@@ -181,6 +181,7 @@ struct rbd_image_header {
181
181
struct rbd_spec {
182
182
u64 pool_id ;
183
183
const char * pool_name ;
184
+ const char * pool_ns ; /* NULL if default, never "" */
184
185
185
186
const char * image_id ;
186
187
const char * image_name ;
@@ -735,6 +736,7 @@ enum {
735
736
Opt_lock_timeout ,
736
737
Opt_last_int ,
737
738
/* int args above */
739
+ Opt_pool_ns ,
738
740
Opt_last_string ,
739
741
/* string args above */
740
742
Opt_read_only ,
@@ -749,6 +751,7 @@ static match_table_t rbd_opts_tokens = {
749
751
{Opt_queue_depth , "queue_depth=%d" },
750
752
{Opt_lock_timeout , "lock_timeout=%d" },
751
753
/* int args above */
754
+ {Opt_pool_ns , "_pool_ns=%s" },
752
755
/* string args above */
753
756
{Opt_read_only , "read_only" },
754
757
{Opt_read_only , "ro" }, /* Alternate spelling */
@@ -776,17 +779,22 @@ struct rbd_options {
776
779
#define RBD_EXCLUSIVE_DEFAULT false
777
780
#define RBD_TRIM_DEFAULT true
778
781
782
+ struct parse_rbd_opts_ctx {
783
+ struct rbd_spec * spec ;
784
+ struct rbd_options * opts ;
785
+ };
786
+
779
787
static int parse_rbd_opts_token (char * c , void * private )
780
788
{
781
- struct rbd_options * rbd_opts = private ;
789
+ struct parse_rbd_opts_ctx * pctx = private ;
782
790
substring_t argstr [MAX_OPT_ARGS ];
783
791
int token , intval , ret ;
784
792
785
793
token = match_token (c , rbd_opts_tokens , argstr );
786
794
if (token < Opt_last_int ) {
787
795
ret = match_int (& argstr [0 ], & intval );
788
796
if (ret < 0 ) {
789
- pr_err ("bad mount option arg (not int) at '%s'\n" , c );
797
+ pr_err ("bad option arg (not int) at '%s'\n" , c );
790
798
return ret ;
791
799
}
792
800
dout ("got int token %d val %d\n" , token , intval );
@@ -802,30 +810,36 @@ static int parse_rbd_opts_token(char *c, void *private)
802
810
pr_err ("queue_depth out of range\n" );
803
811
return - EINVAL ;
804
812
}
805
- rbd_opts -> queue_depth = intval ;
813
+ pctx -> opts -> queue_depth = intval ;
806
814
break ;
807
815
case Opt_lock_timeout :
808
816
/* 0 is "wait forever" (i.e. infinite timeout) */
809
817
if (intval < 0 || intval > INT_MAX / 1000 ) {
810
818
pr_err ("lock_timeout out of range\n" );
811
819
return - EINVAL ;
812
820
}
813
- rbd_opts -> lock_timeout = msecs_to_jiffies (intval * 1000 );
821
+ pctx -> opts -> lock_timeout = msecs_to_jiffies (intval * 1000 );
822
+ break ;
823
+ case Opt_pool_ns :
824
+ kfree (pctx -> spec -> pool_ns );
825
+ pctx -> spec -> pool_ns = match_strdup (argstr );
826
+ if (!pctx -> spec -> pool_ns )
827
+ return - ENOMEM ;
814
828
break ;
815
829
case Opt_read_only :
816
- rbd_opts -> read_only = true;
830
+ pctx -> opts -> read_only = true;
817
831
break ;
818
832
case Opt_read_write :
819
- rbd_opts -> read_only = false;
833
+ pctx -> opts -> read_only = false;
820
834
break ;
821
835
case Opt_lock_on_read :
822
- rbd_opts -> lock_on_read = true;
836
+ pctx -> opts -> lock_on_read = true;
823
837
break ;
824
838
case Opt_exclusive :
825
- rbd_opts -> exclusive = true;
839
+ pctx -> opts -> exclusive = true;
826
840
break ;
827
841
case Opt_notrim :
828
- rbd_opts -> trim = false;
842
+ pctx -> opts -> trim = false;
829
843
break ;
830
844
default :
831
845
/* libceph prints "bad option" msg */
@@ -1452,7 +1466,7 @@ static void rbd_osd_req_format_write(struct rbd_obj_request *obj_request)
1452
1466
struct ceph_osd_request * osd_req = obj_request -> osd_req ;
1453
1467
1454
1468
osd_req -> r_flags = CEPH_OSD_FLAG_WRITE ;
1455
- ktime_get_real_ts (& osd_req -> r_mtime );
1469
+ ktime_get_real_ts64 (& osd_req -> r_mtime );
1456
1470
osd_req -> r_data_offset = obj_request -> ex .oe_off ;
1457
1471
}
1458
1472
@@ -1475,7 +1489,13 @@ rbd_osd_req_create(struct rbd_obj_request *obj_req, unsigned int num_ops)
1475
1489
req -> r_callback = rbd_osd_req_callback ;
1476
1490
req -> r_priv = obj_req ;
1477
1491
1492
+ /*
1493
+ * Data objects may be stored in a separate pool, but always in
1494
+ * the same namespace in that pool as the header in its pool.
1495
+ */
1496
+ ceph_oloc_copy (& req -> r_base_oloc , & rbd_dev -> header_oloc );
1478
1497
req -> r_base_oloc .pool = rbd_dev -> layout .pool_id ;
1498
+
1479
1499
if (ceph_oid_aprintf (& req -> r_base_oid , GFP_NOIO , name_format ,
1480
1500
rbd_dev -> header .object_prefix , obj_req -> ex .oe_objno ))
1481
1501
goto err_req ;
@@ -4119,6 +4139,14 @@ static ssize_t rbd_pool_id_show(struct device *dev,
4119
4139
(unsigned long long ) rbd_dev -> spec -> pool_id );
4120
4140
}
4121
4141
4142
+ static ssize_t rbd_pool_ns_show (struct device * dev ,
4143
+ struct device_attribute * attr , char * buf )
4144
+ {
4145
+ struct rbd_device * rbd_dev = dev_to_rbd_dev (dev );
4146
+
4147
+ return sprintf (buf , "%s\n" , rbd_dev -> spec -> pool_ns ?: "" );
4148
+ }
4149
+
4122
4150
static ssize_t rbd_name_show (struct device * dev ,
4123
4151
struct device_attribute * attr , char * buf )
4124
4152
{
@@ -4217,6 +4245,7 @@ static DEVICE_ATTR(cluster_fsid, 0444, rbd_cluster_fsid_show, NULL);
4217
4245
static DEVICE_ATTR (config_info , 0400 , rbd_config_info_show , NULL) ;
4218
4246
static DEVICE_ATTR (pool , 0444 , rbd_pool_show , NULL) ;
4219
4247
static DEVICE_ATTR (pool_id , 0444 , rbd_pool_id_show , NULL) ;
4248
+ static DEVICE_ATTR (pool_ns , 0444 , rbd_pool_ns_show , NULL) ;
4220
4249
static DEVICE_ATTR (name , 0444 , rbd_name_show , NULL) ;
4221
4250
static DEVICE_ATTR (image_id , 0444 , rbd_image_id_show , NULL) ;
4222
4251
static DEVICE_ATTR (refresh , 0200 , NULL, rbd_image_refresh ) ;
@@ -4235,6 +4264,7 @@ static struct attribute *rbd_attrs[] = {
4235
4264
& dev_attr_config_info .attr ,
4236
4265
& dev_attr_pool .attr ,
4237
4266
& dev_attr_pool_id .attr ,
4267
+ & dev_attr_pool_ns .attr ,
4238
4268
& dev_attr_name .attr ,
4239
4269
& dev_attr_image_id .attr ,
4240
4270
& dev_attr_current_snap .attr ,
@@ -4295,6 +4325,7 @@ static void rbd_spec_free(struct kref *kref)
4295
4325
struct rbd_spec * spec = container_of (kref , struct rbd_spec , kref );
4296
4326
4297
4327
kfree (spec -> pool_name );
4328
+ kfree (spec -> pool_ns );
4298
4329
kfree (spec -> image_id );
4299
4330
kfree (spec -> image_name );
4300
4331
kfree (spec -> snap_name );
@@ -4353,6 +4384,12 @@ static struct rbd_device *__rbd_dev_create(struct rbd_client *rbdc,
4353
4384
rbd_dev -> header .data_pool_id = CEPH_NOPOOL ;
4354
4385
ceph_oid_init (& rbd_dev -> header_oid );
4355
4386
rbd_dev -> header_oloc .pool = spec -> pool_id ;
4387
+ if (spec -> pool_ns ) {
4388
+ WARN_ON (!* spec -> pool_ns );
4389
+ rbd_dev -> header_oloc .pool_ns =
4390
+ ceph_find_or_create_string (spec -> pool_ns ,
4391
+ strlen (spec -> pool_ns ));
4392
+ }
4356
4393
4357
4394
mutex_init (& rbd_dev -> watch_mutex );
4358
4395
rbd_dev -> watch_state = RBD_WATCH_STATE_UNREGISTERED ;
@@ -4633,6 +4670,17 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
4633
4670
parent_spec -> pool_id = pool_id ;
4634
4671
parent_spec -> image_id = image_id ;
4635
4672
parent_spec -> snap_id = snap_id ;
4673
+
4674
+ /* TODO: support cloning across namespaces */
4675
+ if (rbd_dev -> spec -> pool_ns ) {
4676
+ parent_spec -> pool_ns = kstrdup (rbd_dev -> spec -> pool_ns ,
4677
+ GFP_KERNEL );
4678
+ if (!parent_spec -> pool_ns ) {
4679
+ ret = - ENOMEM ;
4680
+ goto out_err ;
4681
+ }
4682
+ }
4683
+
4636
4684
rbd_dev -> parent_spec = parent_spec ;
4637
4685
parent_spec = NULL ; /* rbd_dev now owns this */
4638
4686
} else {
@@ -5146,8 +5194,7 @@ static int rbd_add_parse_args(const char *buf,
5146
5194
const char * mon_addrs ;
5147
5195
char * snap_name ;
5148
5196
size_t mon_addrs_size ;
5149
- struct rbd_spec * spec = NULL ;
5150
- struct rbd_options * rbd_opts = NULL ;
5197
+ struct parse_rbd_opts_ctx pctx = { 0 };
5151
5198
struct ceph_options * copts ;
5152
5199
int ret ;
5153
5200
@@ -5171,22 +5218,22 @@ static int rbd_add_parse_args(const char *buf,
5171
5218
goto out_err ;
5172
5219
}
5173
5220
5174
- spec = rbd_spec_alloc ();
5175
- if (!spec )
5221
+ pctx . spec = rbd_spec_alloc ();
5222
+ if (!pctx . spec )
5176
5223
goto out_mem ;
5177
5224
5178
- spec -> pool_name = dup_token (& buf , NULL );
5179
- if (!spec -> pool_name )
5225
+ pctx . spec -> pool_name = dup_token (& buf , NULL );
5226
+ if (!pctx . spec -> pool_name )
5180
5227
goto out_mem ;
5181
- if (!* spec -> pool_name ) {
5228
+ if (!* pctx . spec -> pool_name ) {
5182
5229
rbd_warn (NULL , "no pool name provided" );
5183
5230
goto out_err ;
5184
5231
}
5185
5232
5186
- spec -> image_name = dup_token (& buf , NULL );
5187
- if (!spec -> image_name )
5233
+ pctx . spec -> image_name = dup_token (& buf , NULL );
5234
+ if (!pctx . spec -> image_name )
5188
5235
goto out_mem ;
5189
- if (!* spec -> image_name ) {
5236
+ if (!* pctx . spec -> image_name ) {
5190
5237
rbd_warn (NULL , "no image name provided" );
5191
5238
goto out_err ;
5192
5239
}
@@ -5207,40 +5254,40 @@ static int rbd_add_parse_args(const char *buf,
5207
5254
if (!snap_name )
5208
5255
goto out_mem ;
5209
5256
* (snap_name + len ) = '\0' ;
5210
- spec -> snap_name = snap_name ;
5257
+ pctx . spec -> snap_name = snap_name ;
5211
5258
5212
5259
/* Initialize all rbd options to the defaults */
5213
5260
5214
- rbd_opts = kzalloc (sizeof ( * rbd_opts ), GFP_KERNEL );
5215
- if (!rbd_opts )
5261
+ pctx . opts = kzalloc (sizeof ( * pctx . opts ), GFP_KERNEL );
5262
+ if (!pctx . opts )
5216
5263
goto out_mem ;
5217
5264
5218
- rbd_opts -> read_only = RBD_READ_ONLY_DEFAULT ;
5219
- rbd_opts -> queue_depth = RBD_QUEUE_DEPTH_DEFAULT ;
5220
- rbd_opts -> lock_timeout = RBD_LOCK_TIMEOUT_DEFAULT ;
5221
- rbd_opts -> lock_on_read = RBD_LOCK_ON_READ_DEFAULT ;
5222
- rbd_opts -> exclusive = RBD_EXCLUSIVE_DEFAULT ;
5223
- rbd_opts -> trim = RBD_TRIM_DEFAULT ;
5265
+ pctx . opts -> read_only = RBD_READ_ONLY_DEFAULT ;
5266
+ pctx . opts -> queue_depth = RBD_QUEUE_DEPTH_DEFAULT ;
5267
+ pctx . opts -> lock_timeout = RBD_LOCK_TIMEOUT_DEFAULT ;
5268
+ pctx . opts -> lock_on_read = RBD_LOCK_ON_READ_DEFAULT ;
5269
+ pctx . opts -> exclusive = RBD_EXCLUSIVE_DEFAULT ;
5270
+ pctx . opts -> trim = RBD_TRIM_DEFAULT ;
5224
5271
5225
5272
copts = ceph_parse_options (options , mon_addrs ,
5226
- mon_addrs + mon_addrs_size - 1 ,
5227
- parse_rbd_opts_token , rbd_opts );
5273
+ mon_addrs + mon_addrs_size - 1 ,
5274
+ parse_rbd_opts_token , & pctx );
5228
5275
if (IS_ERR (copts )) {
5229
5276
ret = PTR_ERR (copts );
5230
5277
goto out_err ;
5231
5278
}
5232
5279
kfree (options );
5233
5280
5234
5281
* ceph_opts = copts ;
5235
- * opts = rbd_opts ;
5236
- * rbd_spec = spec ;
5282
+ * opts = pctx . opts ;
5283
+ * rbd_spec = pctx . spec ;
5237
5284
5238
5285
return 0 ;
5239
5286
out_mem :
5240
5287
ret = - ENOMEM ;
5241
5288
out_err :
5242
- kfree (rbd_opts );
5243
- rbd_spec_put (spec );
5289
+ kfree (pctx . opts );
5290
+ rbd_spec_put (pctx . spec );
5244
5291
kfree (options );
5245
5292
5246
5293
return ret ;
@@ -5586,8 +5633,10 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
5586
5633
ret = rbd_register_watch (rbd_dev );
5587
5634
if (ret ) {
5588
5635
if (ret == - ENOENT )
5589
- pr_info ("image %s/%s does not exist\n" ,
5636
+ pr_info ("image %s/%s%s%s does not exist\n" ,
5590
5637
rbd_dev -> spec -> pool_name ,
5638
+ rbd_dev -> spec -> pool_ns ?: "" ,
5639
+ rbd_dev -> spec -> pool_ns ? "/" : "" ,
5591
5640
rbd_dev -> spec -> image_name );
5592
5641
goto err_out_format ;
5593
5642
}
@@ -5609,8 +5658,10 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
5609
5658
ret = rbd_spec_fill_names (rbd_dev );
5610
5659
if (ret ) {
5611
5660
if (ret == - ENOENT )
5612
- pr_info ("snap %s/%s@%s does not exist\n" ,
5661
+ pr_info ("snap %s/%s%s%s @%s does not exist\n" ,
5613
5662
rbd_dev -> spec -> pool_name ,
5663
+ rbd_dev -> spec -> pool_ns ?: "" ,
5664
+ rbd_dev -> spec -> pool_ns ? "/" : "" ,
5614
5665
rbd_dev -> spec -> image_name ,
5615
5666
rbd_dev -> spec -> snap_name );
5616
5667
goto err_out_probe ;
0 commit comments