@@ -133,12 +133,8 @@ func (d *cephfs) Create() error {
133
133
d .config ["cephfs.path" ] = d .config ["source" ]
134
134
135
135
// Parse the namespace / path.
136
- fields := strings .SplitN (d .config ["cephfs.path" ], "/" , 2 )
137
- fsName := fields [0 ]
138
- fsPath := "/"
139
- if len (fields ) > 1 {
140
- fsPath = fields [1 ]
141
- }
136
+ fsName , fsPath , _ := strings .Cut (d .config ["cephfs.path" ], "/" )
137
+ fsPath = "/" + fsPath
142
138
143
139
// If the filesystem already exists, disallow keys associated to creating the filesystem.
144
140
fsExists , err := d .fsExists (d .config ["cephfs.cluster_name" ], d .config ["cephfs.user.name" ], fsName )
@@ -265,15 +261,35 @@ func (d *cephfs) Create() error {
265
261
return fmt .Errorf ("Failed to create directory '%s': %w" , mountPoint , err )
266
262
}
267
263
268
- // Get the credentials and host.
269
- monAddresses , userSecret , err := d .getConfig (d .config ["cephfs.cluster_name" ], d .config ["cephfs.user.name" ])
264
+ // Collect Ceph information
265
+ clusterName := d .config ["cephfs.cluster_name" ]
266
+ userName := d .config ["cephfs.user.name" ]
267
+
268
+ fsid , err := CephFsid (clusterName )
269
+ if err != nil {
270
+ return err
271
+ }
272
+
273
+ monitors , err := CephMonitors (clusterName )
270
274
if err != nil {
271
275
return err
272
276
}
273
277
278
+ key , err := CephKeyring (clusterName , userName )
279
+ if err != nil {
280
+ return err
281
+ }
282
+
283
+ srcPath , options := CephBuildMount (
284
+ userName ,
285
+ key ,
286
+ fsid ,
287
+ monitors ,
288
+ fsName , "/" ,
289
+ )
290
+
274
291
// Mount the pool.
275
- srcPath := strings .Join (monAddresses , "," ) + ":/"
276
- err = TryMount (srcPath , mountPoint , "ceph" , 0 , fmt .Sprintf ("name=%v,secret=%v,mds_namespace=%v" , d .config ["cephfs.user.name" ], userSecret , fsName ))
292
+ err = TryMount (srcPath , mountPoint , "ceph" , 0 , strings .Join (options , "," ))
277
293
if err != nil {
278
294
return err
279
295
}
@@ -300,12 +316,8 @@ func (d *cephfs) Create() error {
300
316
// Delete clears any local and remote data related to this driver instance.
301
317
func (d * cephfs ) Delete (op * operations.Operation ) error {
302
318
// Parse the namespace / path.
303
- fields := strings .SplitN (d .config ["cephfs.path" ], "/" , 2 )
304
- fsName := fields [0 ]
305
- fsPath := "/"
306
- if len (fields ) > 1 {
307
- fsPath = fields [1 ]
308
- }
319
+ fsName , fsPath , _ := strings .Cut (d .config ["cephfs.path" ], "/" )
320
+ fsPath = "/" + fsPath
309
321
310
322
// Create a temporary mountpoint.
311
323
mountPath , err := os .MkdirTemp ("" , "incus_cephfs_" )
@@ -326,15 +338,35 @@ func (d *cephfs) Delete(op *operations.Operation) error {
326
338
return fmt .Errorf ("Failed to create directory '%s': %w" , mountPoint , err )
327
339
}
328
340
329
- // Get the credentials and host.
330
- monAddresses , userSecret , err := d .getConfig (d .config ["cephfs.cluster_name" ], d .config ["cephfs.user.name" ])
341
+ // Collect Ceph information
342
+ clusterName := d .config ["cephfs.cluster_name" ]
343
+ userName := d .config ["cephfs.user.name" ]
344
+
345
+ fsid , err := CephFsid (clusterName )
331
346
if err != nil {
332
347
return err
333
348
}
334
349
350
+ monitors , err := CephMonitors (clusterName )
351
+ if err != nil {
352
+ return err
353
+ }
354
+
355
+ key , err := CephKeyring (clusterName , userName )
356
+ if err != nil {
357
+ return err
358
+ }
359
+
360
+ srcPath , options := CephBuildMount (
361
+ userName ,
362
+ key ,
363
+ fsid ,
364
+ monitors ,
365
+ fsName , "/" ,
366
+ )
367
+
335
368
// Mount the pool.
336
- srcPath := strings .Join (monAddresses , "," ) + ":/"
337
- err = TryMount (srcPath , mountPoint , "ceph" , 0 , fmt .Sprintf ("name=%v,secret=%v,mds_namespace=%v" , d .config ["cephfs.user.name" ], userSecret , fsName ))
369
+ err = TryMount (srcPath , mountPoint , "ceph" , 0 , strings .Join (options , "," ))
338
370
if err != nil {
339
371
return err
340
372
}
@@ -397,28 +429,39 @@ func (d *cephfs) Mount() (bool, error) {
397
429
}
398
430
399
431
// Parse the namespace / path.
400
- fields := strings .SplitN (d .config ["cephfs.path" ], "/" , 2 )
401
- fsName := fields [0 ]
402
- fsPath := ""
403
- if len (fields ) > 1 {
404
- fsPath = fields [1 ]
432
+ fsName , fsPath , _ := strings .Cut (d .config ["cephfs.path" ], "/" )
433
+ fsPath = "/" + fsPath
434
+
435
+ // Collect Ceph information
436
+ clusterName := d .config ["cephfs.cluster_name" ]
437
+ userName := d .config ["cephfs.user.name" ]
438
+
439
+ fsid , err := CephFsid (clusterName )
440
+ if err != nil {
441
+ return false , err
405
442
}
406
443
407
- // Get the credentials and host.
408
- monAddresses , userSecret , err := d .getConfig (d .config ["cephfs.cluster_name" ], d .config ["cephfs.user.name" ])
444
+ monitors , err := CephMonitors (clusterName )
409
445
if err != nil {
410
446
return false , err
411
447
}
412
448
413
- // Mount options.
414
- options := fmt .Sprintf ("name=%s,secret=%s,mds_namespace=%s" , d .config ["cephfs.user.name" ], userSecret , fsName )
415
- if util .IsTrue (d .config ["cephfs.fscache" ]) {
416
- options += ",fsc"
449
+ key , err := CephKeyring (clusterName , userName )
450
+ if err != nil {
451
+ return false , err
417
452
}
418
453
454
+ srcPath , options := CephBuildMount (
455
+ userName ,
456
+ key ,
457
+ fsid ,
458
+ monitors ,
459
+ fsName ,
460
+ fsPath ,
461
+ )
462
+
419
463
// Mount the pool.
420
- srcPath := strings .Join (monAddresses , "," ) + ":/" + fsPath
421
- err = TryMount (srcPath , GetPoolMountPath (d .name ), "ceph" , 0 , options )
464
+ err = TryMount (srcPath , GetPoolMountPath (d .name ), "ceph" , 0 , strings .Join (options , "," ))
422
465
if err != nil {
423
466
return false , err
424
467
}
0 commit comments