Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd-fuse: implement mv operation #6938

Merged
merged 3 commits into from Dec 21, 2015
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/rbd_fuse/rbd-fuse.cc
Expand Up @@ -18,6 +18,7 @@
#include <unistd.h>
#include <getopt.h>
#include <assert.h>
#include <string>

#if defined(__FreeBSD__)
#include <sys/param.h>
Expand Down Expand Up @@ -534,6 +535,31 @@ rbdfs_create(const char *path, mode_t mode, struct fuse_file_info *fi)
return r;
}

int rbdfs_rename(const char *path, const char *destname)
{
const char *srcname = NULL;
const char *extra[] = {" ", "@", "/"};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any restriction for spaces in the image name -- at least the rbd CLI doesn't restrict it.

std::string image_dest_name(destname + 1);

// check image dest name
if (image_dest_name.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))
return -EINVAL;
}

if (strcmp(path, "/") == 0)
return -EINVAL;

srcname = path + 1;
return rbd_rename(ioctx, srcname, image_dest_name.c_str());
}

int
rbdfs_utime(const char *path, struct utimbuf *utime)
{
Expand Down Expand Up @@ -678,7 +704,7 @@ const static struct fuse_operations rbdfs_oper = {
unlink: rbdfs_unlink,
rmdir: 0,
symlink: 0,
rename: 0,
rename: rbdfs_rename,
link: 0,
chmod: 0,
chown: 0,
Expand Down