client: add support for O_NOFOLLOW in Client::open().

Fixes: #4920
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
This commit is contained in:
Radoslaw Zarzynski 2015-01-26 15:40:14 +01:00
parent 1798803292
commit 911e4c058e
2 changed files with 12 additions and 1 deletions

View File

@ -6378,9 +6378,16 @@ int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit,
filepath path(relpath);
Inode *in;
bool created = false;
int r = path_walk(path, &in);
/* O_CREATE with O_EXCL enforces O_NOFOLLOW. */
bool followsym = !((flags & O_NOFOLLOW) || ((flags & O_CREAT) && (flags & O_EXCL)));
int r = path_walk(path, &in, followsym);
if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL))
return -EEXIST;
if (r == 0 && in->is_symlink() && (flags & O_NOFOLLOW))
return -ELOOP;
if (r == -ENOENT && (flags & O_CREAT)) {
filepath dirpath = path;
string dname = dirpath.last_dentry();

View File

@ -673,6 +673,10 @@ TEST(LibCephFS, Symlinks) {
ASSERT_EQ(ceph_symlink(cmount, test_file, test_symlink), 0);
// test the O_NOFOLLOW case
fd = ceph_open(cmount, test_symlink, O_NOFOLLOW, 0);
ASSERT_EQ(fd, -ELOOP);
// stat the original file
struct stat stbuf_orig;
ASSERT_EQ(ceph_stat(cmount, test_file, &stbuf_orig), 0);