]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mount: optionally do not fall-back to old-style mount syntax
authorVenky Shankar <vshankar@redhat.com>
Mon, 8 Nov 2021 09:12:22 +0000 (04:12 -0500)
committerVenky Shankar <vshankar@redhat.com>
Tue, 30 Nov 2021 06:13:34 +0000 (01:13 -0500)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/mount/mount.ceph.c

index 8ff58d5e87987291f0138f0d422e229ba8f951e8..5c8985e4836242f165aaf56291524bf6ad5b146f 100644 (file)
 bool verboseflag = false;
 bool skip_mtab_flag = false;
 bool v2_addrs = false;
+bool no_fallback = false;
 static const char * const EMPTY_STRING = "";
 
 /* TODO duplicates logic from kernel */
 #define CEPH_AUTH_NAME_DEFAULT "guest"
 
+/* path to sysfs for ceph */
+#define CEPH_SYS_FS_PATH "/sys/module/ceph/"
+#define CEPH_SYS_FS_PARAM_PATH CEPH_SYS_FS_PATH"/parameters"
+
+/*
+ * mount support hint from kernel -- we only need to check
+ * v2 support for catching bugs.
+ */
+#define CEPH_V2_MOUNT_SUPPORT_PATH CEPH_SYS_FS_PARAM_PATH"/mount_syntax_v2"
+
 #include "mtab.c"
 
 enum mount_dev_format {
@@ -502,6 +513,8 @@ static int parse_options(const char *data, struct ceph_mount_info *cmi,
                        }
                        data = "mds_namespace";
                        skip = false;
+               } else if (strcmp(data, "nofallback") == 0) {
+                       no_fallback = true;
                } else if (strcmp(data, "secretfile") == 0) {
                        int ret;
 
@@ -626,8 +639,7 @@ static int parse_arguments(int argc, char *const *const argv,
                                return -EINVAL;
                        }
                        *opts = argv[i];
-               }
-               else {
+                } else {
                        fprintf(stderr, "Can't understand option: '%s'\n\n", argv[i]);
                        return -EINVAL;
                }
@@ -746,6 +758,35 @@ static int mount_old_device_format(const char *node, struct ceph_mount_info *cmi
        return r;
 }
 
+/*
+ * check whether to fall-back to using old-style mount syntax (called
+ * when new-style mount syntax fails). this is mostly to catch any
+ * new-style (v2) implementation bugs in the kernel and is primarly
+ * used in teuthology tests.
+ */
+static bool should_fallback()
+{
+       int ret;
+       struct stat stbuf;
+
+       if (!no_fallback)
+               return true;
+
+       ret = stat(CEPH_V2_MOUNT_SUPPORT_PATH, &stbuf);
+       if (ret) {
+               mount_ceph_debug("mount.ceph: v2 mount support check returned %d\n",
+                                errno);
+               if (errno == ENOENT)
+                       mount_ceph_debug("mount.ceph: kernel does not support v2"
+                                        " syntax\n");
+               /* fallback on *all* errors */
+               return true;
+       }
+
+       fprintf(stderr, "mount.ceph: kernel BUG!\n");
+       return false;
+}
+
 static int do_mount(const char *dev, const char *node,
                    struct ceph_mount_info *cmi) {
        int retval= -EINVAL;
@@ -754,7 +795,7 @@ static int do_mount(const char *dev, const char *node,
        if (cmi->format == MOUNT_DEV_FORMAT_NEW) {
                retval = mount_new_device_format(node, cmi);
                if (retval)
-                       fallback = (retval == -EINVAL && cmi->cmi_fsid);
+                       fallback = (should_fallback() && retval == -EINVAL && cmi->cmi_fsid);
        }
        /* pass-through or fallback to old-style mount device */
        if (retval && fallback)