Skip to content

Commit 87ef120

Browse files
committed
Merge tag 'ceph-for-4.17-rc2' of git://github.com/ceph/ceph-client
Pull ceph fixes from Ilya Dryomov: "A couple of follow-up patches for -rc1 changes in rbd, support for a timeout on waiting for the acquisition of exclusive lock and a fix for uninitialized memory access in CephFS, marked for stable" * tag 'ceph-for-4.17-rc2' of git://github.com/ceph/ceph-client: rbd: notrim map option rbd: adjust queue limits for "fancy" striping rbd: avoid Wreturn-type warnings ceph: always update atime/mtime/ctime for new inode rbd: support timeout in rbd_wait_state_locked() rbd: refactor rbd_wait_state_locked()
2 parents a27fc14 + d936054 commit 87ef120

File tree

2 files changed

+76
-35
lines changed

2 files changed

+76
-35
lines changed

drivers/block/rbd.c

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ static struct rbd_client *rbd_client_find(struct ceph_options *ceph_opts)
732732
*/
733733
enum {
734734
Opt_queue_depth,
735+
Opt_lock_timeout,
735736
Opt_last_int,
736737
/* int args above */
737738
Opt_last_string,
@@ -740,11 +741,13 @@ enum {
740741
Opt_read_write,
741742
Opt_lock_on_read,
742743
Opt_exclusive,
744+
Opt_notrim,
743745
Opt_err
744746
};
745747

746748
static match_table_t rbd_opts_tokens = {
747749
{Opt_queue_depth, "queue_depth=%d"},
750+
{Opt_lock_timeout, "lock_timeout=%d"},
748751
/* int args above */
749752
/* string args above */
750753
{Opt_read_only, "read_only"},
@@ -753,20 +756,25 @@ static match_table_t rbd_opts_tokens = {
753756
{Opt_read_write, "rw"}, /* Alternate spelling */
754757
{Opt_lock_on_read, "lock_on_read"},
755758
{Opt_exclusive, "exclusive"},
759+
{Opt_notrim, "notrim"},
756760
{Opt_err, NULL}
757761
};
758762

759763
struct rbd_options {
760764
int queue_depth;
765+
unsigned long lock_timeout;
761766
bool read_only;
762767
bool lock_on_read;
763768
bool exclusive;
769+
bool trim;
764770
};
765771

766772
#define RBD_QUEUE_DEPTH_DEFAULT BLKDEV_MAX_RQ
773+
#define RBD_LOCK_TIMEOUT_DEFAULT 0 /* no timeout */
767774
#define RBD_READ_ONLY_DEFAULT false
768775
#define RBD_LOCK_ON_READ_DEFAULT false
769776
#define RBD_EXCLUSIVE_DEFAULT false
777+
#define RBD_TRIM_DEFAULT true
770778

771779
static int parse_rbd_opts_token(char *c, void *private)
772780
{
@@ -796,6 +804,14 @@ static int parse_rbd_opts_token(char *c, void *private)
796804
}
797805
rbd_opts->queue_depth = intval;
798806
break;
807+
case Opt_lock_timeout:
808+
/* 0 is "wait forever" (i.e. infinite timeout) */
809+
if (intval < 0 || intval > INT_MAX / 1000) {
810+
pr_err("lock_timeout out of range\n");
811+
return -EINVAL;
812+
}
813+
rbd_opts->lock_timeout = msecs_to_jiffies(intval * 1000);
814+
break;
799815
case Opt_read_only:
800816
rbd_opts->read_only = true;
801817
break;
@@ -808,6 +824,9 @@ static int parse_rbd_opts_token(char *c, void *private)
808824
case Opt_exclusive:
809825
rbd_opts->exclusive = true;
810826
break;
827+
case Opt_notrim:
828+
rbd_opts->trim = false;
829+
break;
811830
default:
812831
/* libceph prints "bad option" msg */
813832
return -EINVAL;
@@ -1392,7 +1411,7 @@ static bool rbd_img_is_write(struct rbd_img_request *img_req)
13921411
case OBJ_OP_DISCARD:
13931412
return true;
13941413
default:
1395-
rbd_assert(0);
1414+
BUG();
13961415
}
13971416
}
13981417

@@ -2466,7 +2485,7 @@ static bool rbd_obj_handle_write(struct rbd_obj_request *obj_req)
24662485
}
24672486
return false;
24682487
default:
2469-
rbd_assert(0);
2488+
BUG();
24702489
}
24712490
}
24722491

@@ -2494,7 +2513,7 @@ static bool __rbd_obj_handle_request(struct rbd_obj_request *obj_req)
24942513
}
24952514
return false;
24962515
default:
2497-
rbd_assert(0);
2516+
BUG();
24982517
}
24992518
}
25002519

@@ -3533,9 +3552,22 @@ static int rbd_obj_method_sync(struct rbd_device *rbd_dev,
35333552
/*
35343553
* lock_rwsem must be held for read
35353554
*/
3536-
static void rbd_wait_state_locked(struct rbd_device *rbd_dev)
3555+
static int rbd_wait_state_locked(struct rbd_device *rbd_dev, bool may_acquire)
35373556
{
35383557
DEFINE_WAIT(wait);
3558+
unsigned long timeout;
3559+
int ret = 0;
3560+
3561+
if (test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags))
3562+
return -EBLACKLISTED;
3563+
3564+
if (rbd_dev->lock_state == RBD_LOCK_STATE_LOCKED)
3565+
return 0;
3566+
3567+
if (!may_acquire) {
3568+
rbd_warn(rbd_dev, "exclusive lock required");
3569+
return -EROFS;
3570+
}
35393571

35403572
do {
35413573
/*
@@ -3547,12 +3579,22 @@ static void rbd_wait_state_locked(struct rbd_device *rbd_dev)
35473579
prepare_to_wait_exclusive(&rbd_dev->lock_waitq, &wait,
35483580
TASK_UNINTERRUPTIBLE);
35493581
up_read(&rbd_dev->lock_rwsem);
3550-
schedule();
3582+
timeout = schedule_timeout(ceph_timeout_jiffies(
3583+
rbd_dev->opts->lock_timeout));
35513584
down_read(&rbd_dev->lock_rwsem);
3552-
} while (rbd_dev->lock_state != RBD_LOCK_STATE_LOCKED &&
3553-
!test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags));
3585+
if (test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags)) {
3586+
ret = -EBLACKLISTED;
3587+
break;
3588+
}
3589+
if (!timeout) {
3590+
rbd_warn(rbd_dev, "timed out waiting for lock");
3591+
ret = -ETIMEDOUT;
3592+
break;
3593+
}
3594+
} while (rbd_dev->lock_state != RBD_LOCK_STATE_LOCKED);
35543595

35553596
finish_wait(&rbd_dev->lock_waitq, &wait);
3597+
return ret;
35563598
}
35573599

35583600
static void rbd_queue_workfn(struct work_struct *work)
@@ -3638,19 +3680,10 @@ static void rbd_queue_workfn(struct work_struct *work)
36383680
(op_type != OBJ_OP_READ || rbd_dev->opts->lock_on_read);
36393681
if (must_be_locked) {
36403682
down_read(&rbd_dev->lock_rwsem);
3641-
if (rbd_dev->lock_state != RBD_LOCK_STATE_LOCKED &&
3642-
!test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags)) {
3643-
if (rbd_dev->opts->exclusive) {
3644-
rbd_warn(rbd_dev, "exclusive lock required");
3645-
result = -EROFS;
3646-
goto err_unlock;
3647-
}
3648-
rbd_wait_state_locked(rbd_dev);
3649-
}
3650-
if (test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags)) {
3651-
result = -EBLACKLISTED;
3683+
result = rbd_wait_state_locked(rbd_dev,
3684+
!rbd_dev->opts->exclusive);
3685+
if (result)
36523686
goto err_unlock;
3653-
}
36543687
}
36553688

36563689
img_request = rbd_img_request_create(rbd_dev, op_type, snapc);
@@ -3902,7 +3935,8 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
39023935
{
39033936
struct gendisk *disk;
39043937
struct request_queue *q;
3905-
u64 segment_size;
3938+
unsigned int objset_bytes =
3939+
rbd_dev->layout.object_size * rbd_dev->layout.stripe_count;
39063940
int err;
39073941

39083942
/* create gendisk info */
@@ -3942,20 +3976,19 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
39423976
blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
39433977
/* QUEUE_FLAG_ADD_RANDOM is off by default for blk-mq */
39443978

3945-
/* set io sizes to object size */
3946-
segment_size = rbd_obj_bytes(&rbd_dev->header);
3947-
blk_queue_max_hw_sectors(q, segment_size / SECTOR_SIZE);
3979+
blk_queue_max_hw_sectors(q, objset_bytes >> SECTOR_SHIFT);
39483980
q->limits.max_sectors = queue_max_hw_sectors(q);
39493981
blk_queue_max_segments(q, USHRT_MAX);
39503982
blk_queue_max_segment_size(q, UINT_MAX);
3951-
blk_queue_io_min(q, segment_size);
3952-
blk_queue_io_opt(q, segment_size);
3983+
blk_queue_io_min(q, objset_bytes);
3984+
blk_queue_io_opt(q, objset_bytes);
39533985

3954-
/* enable the discard support */
3955-
blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
3956-
q->limits.discard_granularity = segment_size;
3957-
blk_queue_max_discard_sectors(q, segment_size / SECTOR_SIZE);
3958-
blk_queue_max_write_zeroes_sectors(q, segment_size / SECTOR_SIZE);
3986+
if (rbd_dev->opts->trim) {
3987+
blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
3988+
q->limits.discard_granularity = objset_bytes;
3989+
blk_queue_max_discard_sectors(q, objset_bytes >> SECTOR_SHIFT);
3990+
blk_queue_max_write_zeroes_sectors(q, objset_bytes >> SECTOR_SHIFT);
3991+
}
39593992

39603993
if (!ceph_test_opt(rbd_dev->rbd_client->client, NOCRC))
39613994
q->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES;
@@ -5179,8 +5212,10 @@ static int rbd_add_parse_args(const char *buf,
51795212

51805213
rbd_opts->read_only = RBD_READ_ONLY_DEFAULT;
51815214
rbd_opts->queue_depth = RBD_QUEUE_DEPTH_DEFAULT;
5215+
rbd_opts->lock_timeout = RBD_LOCK_TIMEOUT_DEFAULT;
51825216
rbd_opts->lock_on_read = RBD_LOCK_ON_READ_DEFAULT;
51835217
rbd_opts->exclusive = RBD_EXCLUSIVE_DEFAULT;
5218+
rbd_opts->trim = RBD_TRIM_DEFAULT;
51845219

51855220
copts = ceph_parse_options(options, mon_addrs,
51865221
mon_addrs + mon_addrs_size - 1,
@@ -5216,16 +5251,18 @@ static void rbd_dev_image_unlock(struct rbd_device *rbd_dev)
52165251

52175252
static int rbd_add_acquire_lock(struct rbd_device *rbd_dev)
52185253
{
5254+
int ret;
5255+
52195256
if (!(rbd_dev->header.features & RBD_FEATURE_EXCLUSIVE_LOCK)) {
52205257
rbd_warn(rbd_dev, "exclusive-lock feature is not enabled");
52215258
return -EINVAL;
52225259
}
52235260

52245261
/* FIXME: "rbd map --exclusive" should be in interruptible */
52255262
down_read(&rbd_dev->lock_rwsem);
5226-
rbd_wait_state_locked(rbd_dev);
5263+
ret = rbd_wait_state_locked(rbd_dev, true);
52275264
up_read(&rbd_dev->lock_rwsem);
5228-
if (test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags)) {
5265+
if (ret) {
52295266
rbd_warn(rbd_dev, "failed to acquire exclusive lock");
52305267
return -EROFS;
52315268
}

fs/ceph/inode.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,15 @@ void ceph_fill_file_time(struct inode *inode, int issued,
669669
CEPH_CAP_FILE_BUFFER|
670670
CEPH_CAP_AUTH_EXCL|
671671
CEPH_CAP_XATTR_EXCL)) {
672-
if (timespec_compare(ctime, &inode->i_ctime) > 0) {
672+
if (ci->i_version == 0 ||
673+
timespec_compare(ctime, &inode->i_ctime) > 0) {
673674
dout("ctime %ld.%09ld -> %ld.%09ld inc w/ cap\n",
674675
inode->i_ctime.tv_sec, inode->i_ctime.tv_nsec,
675676
ctime->tv_sec, ctime->tv_nsec);
676677
inode->i_ctime = *ctime;
677678
}
678-
if (ceph_seq_cmp(time_warp_seq, ci->i_time_warp_seq) > 0) {
679+
if (ci->i_version == 0 ||
680+
ceph_seq_cmp(time_warp_seq, ci->i_time_warp_seq) > 0) {
679681
/* the MDS did a utimes() */
680682
dout("mtime %ld.%09ld -> %ld.%09ld "
681683
"tw %d -> %d\n",
@@ -795,7 +797,6 @@ static int fill_inode(struct inode *inode, struct page *locked_page,
795797
new_issued = ~issued & le32_to_cpu(info->cap.caps);
796798

797799
/* update inode */
798-
ci->i_version = le64_to_cpu(info->version);
799800
inode->i_rdev = le32_to_cpu(info->rdev);
800801
inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
801802

@@ -868,6 +869,9 @@ static int fill_inode(struct inode *inode, struct page *locked_page,
868869
xattr_blob = NULL;
869870
}
870871

872+
/* finally update i_version */
873+
ci->i_version = le64_to_cpu(info->version);
874+
871875
inode->i_mapping->a_ops = &ceph_aops;
872876

873877
switch (inode->i_mode & S_IFMT) {

0 commit comments

Comments
 (0)