mirror of
https://github.com/ceph/ceph
synced 2025-01-20 18:21:57 +00:00
client: add support for O_NOFOLLOW in Client::open().
Fixes: #4920 Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
This commit is contained in:
parent
1798803292
commit
911e4c058e
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user