]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
added "--rbduser" option in "lxc-create -B rbd"
authorRahik-Sikder <sikder.rahik@gmail.com>
Tue, 9 Dec 2025 22:12:25 +0000 (16:12 -0600)
committerRahik-Sikder <sikder.rahik@gmail.com>
Wed, 10 Dec 2025 02:23:44 +0000 (20:23 -0600)
Co-developed-by: Rahik Sikder <sikder.rahik@gmail.com>
Co-developed-by: Jake Chacko <chackoj1204@gmail.com>
Signed-off-by: Rahik-Sikder <sikder.rahik@gmail.com>
src/lxc/initutils.c
src/lxc/initutils.h
src/lxc/lxccontainer.h
src/lxc/storage/rbd.c
src/lxc/tools/arguments.h
src/lxc/tools/lxc_create.c

index 2081692475ce5be9622b140c6b8a87f64e9c4814..181f5841c2304c427b0cc984b51db2b460242b60 100644 (file)
@@ -49,6 +49,7 @@ const char *lxc_global_config_value(const char *option_name)
                { "lxc.bdev.lvm.thin_pool", DEFAULT_THIN_POOL },
                { "lxc.bdev.zfs.root",      DEFAULT_ZFSROOT },
                { "lxc.bdev.rbd.rbdpool",   DEFAULT_RBDPOOL },
+               { "lxc.bdev.rbd.rbduser",       DEFAULT_RBDUSER },
                { "lxc.lxcpath",            NULL            },
                { "lxc.default_config",     NULL            },
                { "lxc.cgroup.pattern",     NULL            },
index 2e749063f00acc0d75c5876724a071a979714de3..6ae0997ace5c152f9fae3e12343d23d2bf5b459d 100644 (file)
@@ -25,6 +25,7 @@
 #define DEFAULT_THIN_POOL "lxc"
 #define DEFAULT_ZFSROOT "lxc"
 #define DEFAULT_RBDPOOL "lxc"
+#define DEFAULT_RBDUSER NULL
 
 #ifndef PR_SET_MM
 #define PR_SET_MM 35
index 2d90fe8d8e3605753413f54a48cb78b04e7c0f95..ee94840bfeee6abc34f754f5a19c7af7364a308f 100644 (file)
@@ -936,6 +936,7 @@ struct bdev_specs {
        struct {
                char *rbdname; /*!< RBD image name */
                char *rbdpool; /*!< Ceph pool name */
+               char *rbduser; /*!< Ceph user name*/
        } rbd;
 };
 
index c6d8204658a45575aefb922f26d300a8948de632..50227f48faa1ed4d25b4ae7c86647f8fd855dce8 100644 (file)
@@ -22,6 +22,7 @@ lxc_log_define(rbd, lxc);
 
 struct rbd_args {
        const char *osd_pool_name;
+       const char *rbd_user;
        const char *rbd_name;
        const char *size;
 };
@@ -30,8 +31,14 @@ static int rbd_create_wrapper(void *data)
 {
        struct rbd_args *args = data;
 
-       execlp("rbd", "rbd", "create", "--pool", args->osd_pool_name,
+       if (args->rbd_user){
+               execlp("rbd", "rbd", "create", "--id", args->rbd_user, "--pool", 
+                       args->osd_pool_name, args->rbd_name, "--size", args->size, 
+                       (char *)NULL);
+       } else {
+               execlp("rbd", "rbd", "create", "--pool", args->osd_pool_name,
               args->rbd_name, "--size", args->size, (char *)NULL);
+       }
 
        return -1;
 }
@@ -40,9 +47,13 @@ static int rbd_map_wrapper(void *data)
 {
        struct rbd_args *args = data;
 
-       execlp("rbd", "rbd", "map", "--pool", args->osd_pool_name,
+       if (args->rbd_user){
+               execlp("rbd", "rbd", "map", "--id", args->rbd_user, "--pool", 
+                       args->osd_pool_name, args->rbd_name, (char *)NULL);
+       } else {
+               execlp("rbd", "rbd", "map", "--pool", args->osd_pool_name,
               args->rbd_name, (char *)NULL);
-
+       }
        return -1;
 }
 
@@ -50,7 +61,13 @@ static int rbd_unmap_wrapper(void *data)
 {
        struct rbd_args *args = data;
 
-       execlp("rbd", "rbd", "unmap", args->rbd_name, (char *)NULL);
+       if (args->rbd_user){
+               execlp("rbd", "rbd", "unmap", "--id", args->rbd_user, args->rbd_name, 
+                       (char *)NULL);
+       } else {
+               execlp("rbd", "rbd", "unmap", args->rbd_name, (char *)NULL);
+       }
+
 
        return -1;
 }
@@ -59,7 +76,12 @@ static int rbd_delete_wrapper(void *data)
 {
        struct rbd_args *args = data;
 
-       execlp("rbd", "rbd", "rm", args->rbd_name, (char *)NULL);
+       if (args->rbd_user){
+               execlp("rbd", "rbd", "rm", "--id", args->rbd_user, args->rbd_name, 
+                       (char *)NULL);
+       } else {
+               execlp("rbd", "rbd", "rm", args->rbd_name, (char *)NULL);
+       }
 
        return -1;
 }
@@ -83,6 +105,7 @@ int rbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
        const char *cmd_args[2];
        char cmd_output[PATH_MAX];
        const char *rbdname = n;
+       const char *rbduser;
        struct rbd_args args = {0};
 
        if (!specs)
@@ -94,6 +117,10 @@ int rbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
 
        if (specs->rbd.rbdname)
                rbdname = specs->rbd.rbdname;
+       
+       rbduser = specs->rbd.rbduser;
+       if (!rbduser)
+               rbduser = lxc_global_config_value("lxc.bdev.rbd.rbduser");
 
        /* source device /dev/rbd/lxc/ctn */
        len = strlen(rbdpool) + strlen(rbdname) + 4 + 11;
@@ -123,6 +150,7 @@ int rbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
 
        args.osd_pool_name = rbdpool;
        args.rbd_name = rbdname;
+       args.rbd_user = rbduser;
        args.size = sz;
        ret = run_command(cmd_output, sizeof(cmd_output), rbd_create_wrapper,
                          (void *)&args);
@@ -179,6 +207,8 @@ int rbd_destroy(struct lxc_storage *orig)
        struct rbd_args args = {0};
        size_t len;
 
+       args.rbd_user = lxc_global_config_value("lxc.bdev.rbd.rbduser");
+
        src = lxc_storage_get_path(orig->src, orig->type);
        if (file_exists(src)) {
                args.rbd_name = src;
index 92510ecbca4ceb4337716b602614f9c2324b9256..3c9ae4365bd45c60e8d083333eb2a52430f553dd 100644 (file)
@@ -73,7 +73,7 @@ struct lxc_arguments {
        char *fstype;
        uint64_t fssize;
        char *lvname, *vgname, *thinpool;
-       char *rbdname, *rbdpool;
+       char *rbdname, *rbdpool, *rbduser;
        char *zfsroot, *lowerdir, *dir;
 
        /* lxc-execute and lxc-unshare */
index 41756078c62f1813cff783628e3b336e5a166a50..15d8b10427e38cde3df635524193a472019d482f 100644 (file)
@@ -36,6 +36,7 @@ static const struct option my_longopts[] = {
        {"dir", required_argument, 0, '6'},
        {"rbdname", required_argument, 0, '7'},
        {"rbdpool", required_argument, 0, '8'},
+       {"rbduser", required_argument, 0, '9'},
        LXC_COMMON_OPTIONS
 };
 
@@ -67,6 +68,8 @@ Options :\n\
                                 (Default: container name)\n\
       --rbdpool=POOL            Use Ceph RBD pool name POOL\n\
                                 (Default: lxc)\n\
+      --rbduser=RBDUSER         Use Ceph user RBDUSER for auth\n\
+                                (Default: admin)\n\
 \n\
   BDEV option for ZFS (with -B/--bdev zfs) :\n\
       --zfsroot=PATH            Create zfs under given zfsroot\n\
@@ -128,6 +131,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
        case '8':
                args->rbdpool = arg;
                break;
+       case '9':
+               args->rbduser = arg;
+               break;
        }
        return 0;
 }
@@ -175,7 +181,7 @@ static bool validate_bdev_args(struct lxc_arguments *args)
                        }
 
                if (strncmp(args->bdevtype, "rbd", strlen(args->bdevtype)) != 0)
-                       if (args->rbdname || args->rbdpool) {
+                       if (args->rbdname || args->rbdpool ) {
                                ERROR("--rbdname and --rbdpool are only valid with -B rbd");
                                return false;
                        }
@@ -303,6 +309,9 @@ int lxc_create_main(int argc, char *argv[])
 
                if (my_args.rbdpool)
                        spec.rbd.rbdpool = my_args.rbdpool;
+               
+               if(my_args.rbduser)
+                       spec.rbd.rbduser = my_args.rbduser;
        }
 
        if (my_args.dir)