]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
storage: make detect method return bool
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 25 Jul 2017 11:02:30 +0000 (13:02 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 31 Jul 2017 21:34:17 +0000 (23:34 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
19 files changed:
src/lxc/bdev/bdev.h
src/lxc/bdev/lxcaufs.c
src/lxc/bdev/lxcaufs.h
src/lxc/bdev/lxcbtrfs.c
src/lxc/bdev/lxcbtrfs.h
src/lxc/bdev/lxcdir.c
src/lxc/bdev/lxcdir.h
src/lxc/bdev/lxcloop.c
src/lxc/bdev/lxcloop.h
src/lxc/bdev/lxclvm.c
src/lxc/bdev/lxclvm.h
src/lxc/bdev/lxcnbd.c
src/lxc/bdev/lxcnbd.h
src/lxc/bdev/lxcoverlay.c
src/lxc/bdev/lxcoverlay.h
src/lxc/bdev/lxcrbd.c
src/lxc/bdev/lxcrbd.h
src/lxc/bdev/lxczfs.c
src/lxc/bdev/lxczfs.h

index 15d46502f087d4d29a12238e8d7cfc613d1be980..591ddb8091949f7713ab55f5f646043ef2e97510 100644 (file)
@@ -61,7 +61,7 @@ struct bdev;
 
 struct bdev_ops {
        /* detect whether path is of this bdev type */
-       int (*detect)(const char *path);
+       bool (*detect)(const char *path);
        // mount requires src and dest to be set.
        int (*mount)(struct bdev *bdev);
        int (*umount)(struct bdev *bdev);
index 481b62ffe0a4f97e59e96091c3eb03c47867ca63..a2122f236dc72d1440d8fa1ee4d97cc191e3a6fd 100644 (file)
@@ -227,12 +227,12 @@ int aufs_destroy(struct bdev *orig)
        return lxc_rmdir_onedev(upper, NULL);
 }
 
-int aufs_detect(const char *path)
+bool aufs_detect(const char *path)
 {
        if (!strncmp(path, "aufs:", 5))
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
 
 int aufs_mount(struct bdev *bdev)
index fa623f712a7176faf6432bc9cd0b3620667bf134..a0dcac3eb08dff81eeaf19f8dac2e390927895c7 100644 (file)
@@ -25,6 +25,7 @@
 #define __LXC_AUFS_H
 
 #define _GNU_SOURCE
+#include <stdbool.h>
 #include <stdint.h>
 
 #if IS_BIONIC
@@ -54,7 +55,7 @@ int aufs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
 int aufs_create(struct bdev *bdev, const char *dest, const char *n,
                struct bdev_specs *specs);
 int aufs_destroy(struct bdev *orig);
-int aufs_detect(const char *path);
+bool aufs_detect(const char *path);
 int aufs_mount(struct bdev *bdev);
 int aufs_umount(struct bdev *bdev);
 
index dbb5ce672db21df23674c074be6f94b055ae645e..0a34042796a6d8070970d7d729671ef83db079da 100644 (file)
@@ -166,26 +166,26 @@ int is_btrfs_subvol(const char *path)
        return stfs.f_type == BTRFS_SUPER_MAGIC;
 }
 
-int btrfs_detect(const char *path)
+bool btrfs_detect(const char *path)
 {
        struct stat st;
        int ret;
 
        if (!strncmp(path, "btrfs:", 6))
-               return 1;
+               return true;
 
        if (!is_btrfs_fs(path))
-               return 0;
+               return false;
 
        /* make sure it's a subvolume */
        ret = stat(path, &st);
        if (ret < 0)
-               return 0;
+               return false;
 
        if (st.st_ino == 256 && S_ISDIR(st.st_mode))
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
 
 int btrfs_mount(struct bdev *bdev)
index 0069245e8e0d848bb29975a8317c8cf56e6308ce..d88e1be2ca21efa358cb6e34e7b1f824f1ed197e 100644 (file)
@@ -397,7 +397,7 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
 int btrfs_create(struct bdev *bdev, const char *dest, const char *n,
                 struct bdev_specs *specs);
 int btrfs_destroy(struct bdev *orig);
-int btrfs_detect(const char *path);
+bool btrfs_detect(const char *path);
 int btrfs_mount(struct bdev *bdev);
 int btrfs_umount(struct bdev *bdev);
 
index 610425aed0fafd12c54158c4ff0071251c4c78ab..5b73df6587bbf5c8288b90392d1b949ba772bbc0 100644 (file)
@@ -134,15 +134,15 @@ int dir_destroy(struct bdev *orig)
        return 0;
 }
 
-int dir_detect(const char *path)
+bool dir_detect(const char *path)
 {
        if (!strncmp(path, "dir:", 4))
-               return 1;
+               return true;
 
        if (is_dir(path))
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
 
 int dir_mount(struct bdev *bdev)
index f5cca9ada0e6c9627d5344a0eac8bcb53d47a860..d63c6690094ea20694f60ff8dc3eacd96c8ae61b 100644 (file)
@@ -25,6 +25,7 @@
 #define __LXC_DIR_H
 
 #define _GNU_SOURCE
+#include <stdbool.h>
 #include <stdint.h>
 
 /* defined in bdev.h */
@@ -45,7 +46,7 @@ int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
 int dir_create(struct bdev *bdev, const char *dest, const char *n,
                struct bdev_specs *specs);
 int dir_destroy(struct bdev *orig);
-int dir_detect(const char *path);
+bool dir_detect(const char *path);
 int dir_mount(struct bdev *bdev);
 int dir_umount(struct bdev *bdev);
 
index 0da3e81871e2623196478eac5d577b85c1b5f76d..7508cb62ed8ccee6689f830effe7540d4cdf3b95 100644 (file)
@@ -206,22 +206,22 @@ int loop_destroy(struct bdev *orig) {
        return unlink(orig->src + 5);
 }
 
-int loop_detect(const char *path)
+bool loop_detect(const char *path)
 {
        int ret;
        struct stat s;
 
        if (!strncmp(path, "loop:", 5))
-               return 1;
+               return true;
 
        ret = stat(path, &s);
        if (ret < 0)
-               return 0;
+               return false;
 
        if (__S_ISTYPE(s.st_mode, S_IFREG))
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
 
 int loop_mount(struct bdev *bdev)
index 5d33182a31bea19d214e5d3a4639e64e00a1f685..9c7baa2a7cfb5cd9ad4c2037b6d274d01036f171 100644 (file)
@@ -25,6 +25,7 @@
 #define __LXC_LOOP_H
 
 #define _GNU_SOURCE
+#include <stdbool.h>
 #include <stdint.h>
 
 /* defined in bdev.h */
@@ -45,7 +46,7 @@ int loop_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
 int loop_create(struct bdev *bdev, const char *dest, const char *n,
                struct bdev_specs *specs);
 int loop_destroy(struct bdev *orig);
-int loop_detect(const char *path);
+bool loop_detect(const char *path);
 int loop_mount(struct bdev *bdev);
 int loop_umount(struct bdev *bdev);
 
index aea605d048d16647831593e02c9384303a12b065..0ed2446eb525fa72cf1f8b0af504dd447098a1a5 100644 (file)
@@ -193,7 +193,7 @@ static int do_lvm_create(const char *path, uint64_t size, const char *thinpool)
 /* Look at "/sys/dev/block/maj:min/dm/uuid". If it contains the hardcoded LVM
  * prefix "LVM-" then this is an lvm2 LV.
  */
-int lvm_detect(const char *path)
+bool lvm_detect(const char *path)
 {
        int fd;
        ssize_t ret;
@@ -201,35 +201,35 @@ int lvm_detect(const char *path)
        char devp[MAXPATHLEN], buf[4];
 
        if (!strncmp(path, "lvm:", 4))
-               return 1;
+               return true;
 
        ret = stat(path, &statbuf);
        if (ret < 0)
-               return 0;
+               return false;
 
        if (!S_ISBLK(statbuf.st_mode))
-               return 0;
+               return false;
 
        ret = snprintf(devp, MAXPATHLEN, "/sys/dev/block/%d:%d/dm/uuid",
                       major(statbuf.st_rdev), minor(statbuf.st_rdev));
        if (ret < 0 || ret >= MAXPATHLEN) {
                ERROR("Failed to create string");
-               return 0;
+               return false;
        }
 
        fd = open(devp, O_RDONLY);
        if (fd < 0)
-               return 0;
+               return false;
 
        ret = read(fd, buf, sizeof(buf));
        close(fd);
        if (ret != sizeof(buf))
-               return 0;
+               return false;
 
        if (strncmp(buf, "LVM-", 4))
-               return 0;
+               return false;
 
-       return 1;
+       return true;
 }
 
 int lvm_mount(struct bdev *bdev)
index 07824fced6a21cf499bf76791c5abc103af5a40c..a89ca669308af02f31fb0d5e131117a128736eb8 100644 (file)
@@ -40,7 +40,7 @@ struct lxc_conf;
 /*
  * Functions associated with an lvm bdev struct.
  */
-int lvm_detect(const char *path);
+bool lvm_detect(const char *path);
 int lvm_mount(struct bdev *bdev);
 int lvm_umount(struct bdev *bdev);
 int lvm_compare_lv_attr(const char *path, int pos, const char expected);
index e6ce59038ec92d00ccfcaa9897c6d3a92d60b3d2..2c419527c32b53d789e6782c0d614591eb4952b8 100644 (file)
@@ -106,12 +106,12 @@ int nbd_destroy(struct bdev *orig)
        return -ENOSYS;
 }
 
-int nbd_detect(const char *path)
+bool nbd_detect(const char *path)
 {
        if (!strncmp(path, "nbd:", 4))
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
 
 int nbd_mount(struct bdev *bdev)
index 1404d5a3b34eaf5e2867519f16ddb72dbca6b4bf..52ce8cb05ffc96090252dfc2d5a2f8902e26ba05 100644 (file)
@@ -46,7 +46,7 @@ int nbd_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
 int nbd_create(struct bdev *bdev, const char *dest, const char *n,
                struct bdev_specs *specs);
 int nbd_destroy(struct bdev *orig);
-int nbd_detect(const char *path);
+bool nbd_detect(const char *path);
 int nbd_mount(struct bdev *bdev);
 int nbd_umount(struct bdev *bdev);
 
index 85f4650a2f072103d7e33fcf6010d9a5588c1fa1..5e4fde5e76b7063a099fceb109ebb0380e6e4278 100644 (file)
@@ -332,15 +332,15 @@ int ovl_destroy(struct bdev *orig)
        return lxc_rmdir_onedev(upper, NULL);
 }
 
-int ovl_detect(const char *path)
+bool ovl_detect(const char *path)
 {
        if (!strncmp(path, "overlayfs:", 10))
-               return 1;
+               return true;
 
        if (!strncmp(path, "overlay:", 8))
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
 
 int ovl_mount(struct bdev *bdev)
index fe70d3dbc2530275cce7c599c205dd810ede6695..bc1edc792314c26389b99c00459b4639b8498737 100644 (file)
@@ -25,6 +25,7 @@
 #define __LXC_OVERLAY_H
 
 #include <grp.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -56,7 +57,7 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
 int ovl_create(struct bdev *bdev, const char *dest, const char *n,
               struct bdev_specs *specs);
 int ovl_destroy(struct bdev *orig);
-int ovl_detect(const char *path);
+bool ovl_detect(const char *path);
 int ovl_mount(struct bdev *bdev);
 int ovl_umount(struct bdev *bdev);
 
index 7af4aaa2453ebae174146647475006a534cef120..3c2904e6e6965344548b07578a02299e4aafb6f4 100644 (file)
@@ -219,15 +219,15 @@ int rbd_destroy(struct bdev *orig)
        return 0;
 }
 
-int rbd_detect(const char *path)
+bool rbd_detect(const char *path)
 {
        if (!strncmp(path, "rbd:", 4))
-               return 1;
+               return true;
 
        if (!strncmp(path, "/dev/rbd/", 9))
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
 
 int rbd_mount(struct bdev *bdev)
index 19fa026b730a4d63e3eaccbdff28e0d516ffe253..731fc0a1b151944c7147f9323b4c21644b0073c8 100644 (file)
@@ -25,6 +25,7 @@
 #define __LXC_RDB_H
 
 #define _GNU_SOURCE
+#include <stdbool.h>
 #include <stdint.h>
 
 /* defined in bdev.h */
@@ -45,7 +46,7 @@ int rbd_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
 int rbd_create(struct bdev *bdev, const char *dest, const char *n,
                struct bdev_specs *specs);
 int rbd_destroy(struct bdev *orig);
-int rbd_detect(const char *path);
+bool rbd_detect(const char *path);
 int rbd_mount(struct bdev *bdev);
 int rbd_umount(struct bdev *bdev);
 
index 8fe74137d9b14180f947a186b52089ecae914b38..253901cb6d9488063b492044fc6d9eddf7942ede 100644 (file)
  */
 
 #define _GNU_SOURCE
-#include <stdio.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/mount.h>
+#include <unistd.h>
 
 #include "bdev.h"
 #include "config.h"
 
 lxc_log_define(lxczfs, lxc);
 
-/*
- * zfs ops:
- * There are two ways we could do this. We could always specify the 'zfs device'
+/* There are two ways we could do this. We could always specify the 'zfs device'
  * (i.e. tank/lxc lxc/container) as rootfs. But instead (at least right now) we
- * have lxc-create specify $lxcpath/$lxcname/rootfs as the mountpoint, so that
+ * have lxc-create specify <lxcpath>/<lxcname>/rootfs as the mountpoint, so that
  * it is always mounted. That means 'mount' is really never needed and could be
  * noop, but for the sake of flexibility let's always bind-mount.
  */
 
-int zfs_list_entry(const char *path, char *output, size_t inlen)
+static bool zfs_list_entry(const char *path, char *output, size_t inlen)
 {
        struct lxc_popen_FILE *f;
-       int found=0;
+       bool found = false;
 
        f = lxc_popen("zfs list 2> /dev/null");
        if (f == NULL) {
                SYSERROR("popen failed");
-               return 0;
+               return false;
        }
 
        while (fgets(output, inlen, f->f)) {
                if (strstr(output, path)) {
-                       found = 1;
+                       found = true;
                        break;
                }
        }
-       (void) lxc_pclose(f);
+       (void)lxc_pclose(f);
 
        return found;
 }
 
-int zfs_detect(const char *path)
+bool zfs_detect(const char *path)
 {
        if (!strncmp(path, "zfs:", 4))
-               return 1;
+               return true;
 
        char *output = malloc(LXC_LOG_BUFFER_SIZE);
 
        if (!output) {
                ERROR("out of memory");
-               return 0;
+               return false;
        }
 
-       int found = zfs_list_entry(path, output, LXC_LOG_BUFFER_SIZE);
+       bool found = zfs_list_entry(path, output, LXC_LOG_BUFFER_SIZE);
        free(output);
 
        return found;
@@ -104,7 +102,8 @@ int zfs_mount(struct bdev *bdev)
        }
 
        src = lxc_storage_get_path(bdev->src, bdev->type);
-       ret = mount(src, bdev->dest, "bind", MS_BIND | MS_REC | mntflags, mntdata);
+       ret = mount(src, bdev->dest, "bind", MS_BIND | MS_REC | mntflags,
+                   mntdata);
        free(mntdata);
 
        return ret;
@@ -122,7 +121,7 @@ int zfs_umount(struct bdev *bdev)
 }
 
 int zfs_clone(const char *opath, const char *npath, const char *oname,
-               const char *nname, const char *lxcpath, int snapshot)
+             const char *nname, const char *lxcpath, int snapshot)
 {
        // use the 'zfs list | grep opath' entry to get the zfsroot
        char output[MAXPATHLEN], option[MAXPATHLEN];
@@ -144,8 +143,9 @@ int zfs_clone(const char *opath, const char *npath, const char *oname,
                zfsroot = lxc_global_config_value("lxc.bdev.zfs.root");
        }
 
-       ret = snprintf(option, MAXPATHLEN, "-omountpoint=%s/%s/rootfs", lxcpath, nname);
-       if (ret < 0  || ret >= MAXPATHLEN)
+       ret = snprintf(option, MAXPATHLEN, "-omountpoint=%s/%s/rootfs", lxcpath,
+                      nname);
+       if (ret < 0 || ret >= MAXPATHLEN)
                return -1;
 
        // zfs create -omountpoint=$lxcpath/$lxcname $zfsroot/$nname
@@ -154,10 +154,12 @@ int zfs_clone(const char *opath, const char *npath, const char *oname,
                        return -1;
                if (!pid) {
                        char dev[MAXPATHLEN];
-                       ret = snprintf(dev, MAXPATHLEN, "%s/%s", zfsroot, nname);
-                       if (ret < 0  || ret >= MAXPATHLEN)
+                       ret =
+                           snprintf(dev, MAXPATHLEN, "%s/%s", zfsroot, nname);
+                       if (ret < 0 || ret >= MAXPATHLEN)
                                exit(EXIT_FAILURE);
-                       execlp("zfs", "zfs", "create", option, dev, (char *)NULL);
+                       execlp("zfs", "zfs", "create", option, dev,
+                              (char *)NULL);
                        exit(EXIT_FAILURE);
                }
                return wait_for_pid(pid);
@@ -167,11 +169,11 @@ int zfs_clone(const char *opath, const char *npath, const char *oname,
                // zfs clone zfsroot/oname@nname zfsroot/nname
                char path1[MAXPATHLEN], path2[MAXPATHLEN];
 
-               ret = snprintf(path1, MAXPATHLEN, "%s/%s@%s", zfsroot,
-                               oname, nname);
+               ret = snprintf(path1, MAXPATHLEN, "%s/%s@%s", zfsroot, oname,
+                              nname);
                if (ret < 0 || ret >= MAXPATHLEN)
                        return -1;
-               (void) snprintf(path2, MAXPATHLEN, "%s/%s", zfsroot, nname);
+               (void)snprintf(path2, MAXPATHLEN, "%s/%s", zfsroot, nname);
 
                // if the snapshot exists, delete it
                if ((pid = fork()) < 0)
@@ -184,7 +186,7 @@ int zfs_clone(const char *opath, const char *npath, const char *oname,
                        exit(EXIT_FAILURE);
                }
                // it probably doesn't exist so destroy probably will fail.
-               (void) wait_for_pid(pid);
+               (void)wait_for_pid(pid);
 
                // run first (snapshot) command
                if ((pid = fork()) < 0)
@@ -200,7 +202,8 @@ int zfs_clone(const char *opath, const char *npath, const char *oname,
                if ((pid = fork()) < 0)
                        return -1;
                if (!pid) {
-                       execlp("zfs", "zfs", "clone", option, path1, path2, (char *)NULL);
+                       execlp("zfs", "zfs", "clone", option, path1, path2,
+                              (char *)NULL);
                        exit(EXIT_FAILURE);
                }
                return wait_for_pid(pid);
@@ -208,8 +211,8 @@ int zfs_clone(const char *opath, const char *npath, const char *oname,
 }
 
 int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
-               const char *cname, const char *oldpath, const char *lxcpath, int snap,
-               uint64_t newsize, struct lxc_conf *conf)
+                  const char *cname, const char *oldpath, const char *lxcpath,
+                  int snap, uint64_t newsize, struct lxc_conf *conf)
 {
        char *origsrc, *newsrc;
        int len, ret;
@@ -218,7 +221,8 @@ int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
                return -1;
 
        if (snap && strcmp(orig->type, "zfs")) {
-               ERROR("zfs snapshot from %s backing store is not supported", orig->type);
+               ERROR("zfs snapshot from %s backing store is not supported",
+                     orig->type);
                return -1;
        }
 
@@ -286,7 +290,7 @@ int zfs_create_exec_wrapper(void *args)
 }
 
 int zfs_create(struct bdev *bdev, const char *dest, const char *n,
-               struct bdev_specs *specs)
+              struct bdev_specs *specs)
 {
        const char *zfsroot;
        char cmd_output[MAXPATHLEN], dev[MAXPATHLEN], option[MAXPATHLEN];
@@ -317,11 +321,11 @@ int zfs_create(struct bdev *bdev, const char *dest, const char *n,
                return -1;
 
        ret = snprintf(option, MAXPATHLEN, "-omountpoint=%s", bdev->dest);
-       if (ret < 0  || ret >= MAXPATHLEN)
+       if (ret < 0 || ret >= MAXPATHLEN)
                return -1;
 
        ret = snprintf(dev, MAXPATHLEN, "%s/%s", zfsroot, n);
-       if (ret < 0  || ret >= MAXPATHLEN)
+       if (ret < 0 || ret >= MAXPATHLEN)
                return -1;
 
        cmd_args.options = option;
@@ -329,6 +333,7 @@ int zfs_create(struct bdev *bdev, const char *dest, const char *n,
        ret = run_command(cmd_output, sizeof(cmd_output),
                          zfs_create_exec_wrapper, (void *)&cmd_args);
        if (ret < 0)
-               ERROR("Failed to create zfs dataset \"%s\": %s", dev, cmd_output);
+               ERROR("Failed to create zfs dataset \"%s\": %s", dev,
+                     cmd_output);
        return ret;
 }
index 048461997f4a66e4f93aae8a2b827c835ae1a797..ea9ae87d7cb0557d12ecfd317547cbb2fbaa2f5c 100644 (file)
@@ -53,8 +53,7 @@ int zfs_create(struct bdev *bdev, const char *dest, const char *n,
  * container busy.
  */
 int zfs_destroy(struct bdev *orig);
-int zfs_detect(const char *path);
-int zfs_list_entry(const char *path, char *output, size_t inlen);
+bool zfs_detect(const char *path);
 int zfs_mount(struct bdev *bdev);
 int zfs_umount(struct bdev *bdev);