@@ -732,6 +732,7 @@ static struct rbd_client *rbd_client_find(struct ceph_options *ceph_opts)
732
732
*/
733
733
enum {
734
734
Opt_queue_depth ,
735
+ Opt_lock_timeout ,
735
736
Opt_last_int ,
736
737
/* int args above */
737
738
Opt_last_string ,
@@ -740,11 +741,13 @@ enum {
740
741
Opt_read_write ,
741
742
Opt_lock_on_read ,
742
743
Opt_exclusive ,
744
+ Opt_notrim ,
743
745
Opt_err
744
746
};
745
747
746
748
static match_table_t rbd_opts_tokens = {
747
749
{Opt_queue_depth , "queue_depth=%d" },
750
+ {Opt_lock_timeout , "lock_timeout=%d" },
748
751
/* int args above */
749
752
/* string args above */
750
753
{Opt_read_only , "read_only" },
@@ -753,20 +756,25 @@ static match_table_t rbd_opts_tokens = {
753
756
{Opt_read_write , "rw" }, /* Alternate spelling */
754
757
{Opt_lock_on_read , "lock_on_read" },
755
758
{Opt_exclusive , "exclusive" },
759
+ {Opt_notrim , "notrim" },
756
760
{Opt_err , NULL }
757
761
};
758
762
759
763
struct rbd_options {
760
764
int queue_depth ;
765
+ unsigned long lock_timeout ;
761
766
bool read_only ;
762
767
bool lock_on_read ;
763
768
bool exclusive ;
769
+ bool trim ;
764
770
};
765
771
766
772
#define RBD_QUEUE_DEPTH_DEFAULT BLKDEV_MAX_RQ
773
+ #define RBD_LOCK_TIMEOUT_DEFAULT 0 /* no timeout */
767
774
#define RBD_READ_ONLY_DEFAULT false
768
775
#define RBD_LOCK_ON_READ_DEFAULT false
769
776
#define RBD_EXCLUSIVE_DEFAULT false
777
+ #define RBD_TRIM_DEFAULT true
770
778
771
779
static int parse_rbd_opts_token (char * c , void * private )
772
780
{
@@ -796,6 +804,14 @@ static int parse_rbd_opts_token(char *c, void *private)
796
804
}
797
805
rbd_opts -> queue_depth = intval ;
798
806
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 ;
799
815
case Opt_read_only :
800
816
rbd_opts -> read_only = true;
801
817
break ;
@@ -808,6 +824,9 @@ static int parse_rbd_opts_token(char *c, void *private)
808
824
case Opt_exclusive :
809
825
rbd_opts -> exclusive = true;
810
826
break ;
827
+ case Opt_notrim :
828
+ rbd_opts -> trim = false;
829
+ break ;
811
830
default :
812
831
/* libceph prints "bad option" msg */
813
832
return - EINVAL ;
@@ -1392,7 +1411,7 @@ static bool rbd_img_is_write(struct rbd_img_request *img_req)
1392
1411
case OBJ_OP_DISCARD :
1393
1412
return true;
1394
1413
default :
1395
- rbd_assert ( 0 );
1414
+ BUG ( );
1396
1415
}
1397
1416
}
1398
1417
@@ -2466,7 +2485,7 @@ static bool rbd_obj_handle_write(struct rbd_obj_request *obj_req)
2466
2485
}
2467
2486
return false;
2468
2487
default :
2469
- rbd_assert ( 0 );
2488
+ BUG ( );
2470
2489
}
2471
2490
}
2472
2491
@@ -2494,7 +2513,7 @@ static bool __rbd_obj_handle_request(struct rbd_obj_request *obj_req)
2494
2513
}
2495
2514
return false;
2496
2515
default :
2497
- rbd_assert ( 0 );
2516
+ BUG ( );
2498
2517
}
2499
2518
}
2500
2519
@@ -3533,9 +3552,22 @@ static int rbd_obj_method_sync(struct rbd_device *rbd_dev,
3533
3552
/*
3534
3553
* lock_rwsem must be held for read
3535
3554
*/
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 )
3537
3556
{
3538
3557
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
+ }
3539
3571
3540
3572
do {
3541
3573
/*
@@ -3547,12 +3579,22 @@ static void rbd_wait_state_locked(struct rbd_device *rbd_dev)
3547
3579
prepare_to_wait_exclusive (& rbd_dev -> lock_waitq , & wait ,
3548
3580
TASK_UNINTERRUPTIBLE );
3549
3581
up_read (& rbd_dev -> lock_rwsem );
3550
- schedule ();
3582
+ timeout = schedule_timeout (ceph_timeout_jiffies (
3583
+ rbd_dev -> opts -> lock_timeout ));
3551
3584
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 );
3554
3595
3555
3596
finish_wait (& rbd_dev -> lock_waitq , & wait );
3597
+ return ret ;
3556
3598
}
3557
3599
3558
3600
static void rbd_queue_workfn (struct work_struct * work )
@@ -3638,19 +3680,10 @@ static void rbd_queue_workfn(struct work_struct *work)
3638
3680
(op_type != OBJ_OP_READ || rbd_dev -> opts -> lock_on_read );
3639
3681
if (must_be_locked ) {
3640
3682
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 )
3652
3686
goto err_unlock ;
3653
- }
3654
3687
}
3655
3688
3656
3689
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)
3902
3935
{
3903
3936
struct gendisk * disk ;
3904
3937
struct request_queue * q ;
3905
- u64 segment_size ;
3938
+ unsigned int objset_bytes =
3939
+ rbd_dev -> layout .object_size * rbd_dev -> layout .stripe_count ;
3906
3940
int err ;
3907
3941
3908
3942
/* create gendisk info */
@@ -3942,20 +3976,19 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
3942
3976
blk_queue_flag_set (QUEUE_FLAG_NONROT , q );
3943
3977
/* QUEUE_FLAG_ADD_RANDOM is off by default for blk-mq */
3944
3978
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 );
3948
3980
q -> limits .max_sectors = queue_max_hw_sectors (q );
3949
3981
blk_queue_max_segments (q , USHRT_MAX );
3950
3982
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 );
3953
3985
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
+ }
3959
3992
3960
3993
if (!ceph_test_opt (rbd_dev -> rbd_client -> client , NOCRC ))
3961
3994
q -> backing_dev_info -> capabilities |= BDI_CAP_STABLE_WRITES ;
@@ -5179,8 +5212,10 @@ static int rbd_add_parse_args(const char *buf,
5179
5212
5180
5213
rbd_opts -> read_only = RBD_READ_ONLY_DEFAULT ;
5181
5214
rbd_opts -> queue_depth = RBD_QUEUE_DEPTH_DEFAULT ;
5215
+ rbd_opts -> lock_timeout = RBD_LOCK_TIMEOUT_DEFAULT ;
5182
5216
rbd_opts -> lock_on_read = RBD_LOCK_ON_READ_DEFAULT ;
5183
5217
rbd_opts -> exclusive = RBD_EXCLUSIVE_DEFAULT ;
5218
+ rbd_opts -> trim = RBD_TRIM_DEFAULT ;
5184
5219
5185
5220
copts = ceph_parse_options (options , mon_addrs ,
5186
5221
mon_addrs + mon_addrs_size - 1 ,
@@ -5216,16 +5251,18 @@ static void rbd_dev_image_unlock(struct rbd_device *rbd_dev)
5216
5251
5217
5252
static int rbd_add_acquire_lock (struct rbd_device * rbd_dev )
5218
5253
{
5254
+ int ret ;
5255
+
5219
5256
if (!(rbd_dev -> header .features & RBD_FEATURE_EXCLUSIVE_LOCK )) {
5220
5257
rbd_warn (rbd_dev , "exclusive-lock feature is not enabled" );
5221
5258
return - EINVAL ;
5222
5259
}
5223
5260
5224
5261
/* FIXME: "rbd map --exclusive" should be in interruptible */
5225
5262
down_read (& rbd_dev -> lock_rwsem );
5226
- rbd_wait_state_locked (rbd_dev );
5263
+ ret = rbd_wait_state_locked (rbd_dev , true );
5227
5264
up_read (& rbd_dev -> lock_rwsem );
5228
- if (test_bit ( RBD_DEV_FLAG_BLACKLISTED , & rbd_dev -> flags ) ) {
5265
+ if (ret ) {
5229
5266
rbd_warn (rbd_dev , "failed to acquire exclusive lock" );
5230
5267
return - EROFS ;
5231
5268
}
0 commit comments