]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-fuse:image name can not include snap name 7044/head
authorYongqiang He <he.yongqiang@h3c.com>
Thu, 24 Dec 2015 08:56:34 +0000 (03:56 -0500)
committerYongqiang He <he.yongqiang@h3c.com>
Thu, 24 Dec 2015 10:01:36 +0000 (05:01 -0500)
It is legal to create a image name like "foo@s1" by the rbd-fuse method.However the "foo@s1" type image name is not accepted for it may be wrongly treated as the snap name.

Signed-off-by: Yongqiang He <he.yongqiang@h3c.com>
src/rbd_fuse/rbd-fuse.cc

index 32930951928589e351454ad147f29782d5de0853..9e92441b65d007dd7f3ea1ec30a785f799969890 100644 (file)
@@ -523,41 +523,59 @@ rbdfs_destroy(void *unused)
        rados_shutdown(cluster);
 }
 
-// return -errno on error.  fi->fh is not set until open time
-
 int
-rbdfs_create(const char *path, mode_t mode, struct fuse_file_info *fi)
+rbdfs_checkname(const char *checkname)
 {
-       int r;
-       int order = imageorder;
-
-       r = rbd_create2(ioctx, path+1, imagesize, imagefeatures, &order);
-       return r;
-}
-
-int rbdfs_rename(const char *path, const char *destname)
-{
-    const char *srcname = NULL;
     const char *extra[] = {"@", "/"};
-    std::string image_dest_name(destname + 1);
+    std::string strCheckName(checkname);
     
-    // check image dest name
-    if (image_dest_name.empty())
+    if (strCheckName.empty())
         return -EINVAL;
 
     unsigned int sz = sizeof(extra) / sizeof(const char*);
     for (unsigned int i = 0; i < sz; i++)
     {
         std::string ex(extra[i]);
-        if (std::string::npos != image_dest_name.find(ex))
+        if (std::string::npos != strCheckName.find(ex))
             return -EINVAL;
     }
 
+    return 0;
+}
+
+// return -errno on error.  fi->fh is not set until open time
+
+int
+rbdfs_create(const char *path, mode_t mode, struct fuse_file_info *fi)
+{
+         int r;
+         int order = imageorder;
+
+         r = rbdfs_checkname(path+1);
+         if (r != 0)
+         {
+            return r;  
+         }
+
+         r = rbd_create2(ioctx, path+1, imagesize, imagefeatures, &order);
+         return r;
+}
+
+int
+rbdfs_rename(const char *path, const char *destname)
+{
+    int r;
+
+    r = rbdfs_checkname(destname+1);
+    if (r != 0)
+    {
+      return r;
+    }
+
     if (strcmp(path, "/") == 0)
         return -EINVAL;
 
-    srcname = path + 1;
-    return rbd_rename(ioctx, srcname, image_dest_name.c_str());
+    return rbd_rename(ioctx, path+1, destname+1);
 }
 
 int