Skip to content

Commit

Permalink
mds: disallow 'open truncate' non-regular inode
Browse files Browse the repository at this point in the history
Signed-off-by: Yan, Zheng <zyan@redhat.com>
(cherry picked from commit 0e4b6f2)

Conflicts:
	src/mds/Server.cc (hammer has cur->inode.inline_version - in master
	this has been changed to cur->inode.inline_data.version)
  • Loading branch information
ukernel authored and smithfarm committed Jul 8, 2016
1 parent 3f0fb20 commit 2633ec3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/mds/Server.cc
Expand Up @@ -2732,9 +2732,13 @@ void Server::handle_client_open(MDRequestRef& mdr)
return;
}

// can only open non-regular inode with mode FILE_MODE_PIN, at least for now.
if (!cur->inode.is_file())
if (!cur->inode.is_file()) {
// can only open non-regular inode with mode FILE_MODE_PIN, at least for now.
cmode = CEPH_FILE_MODE_PIN;
// the inode is symlink and client wants to follow it, ignore the O_TRUNC flag.
if (cur->inode.is_symlink() && !(flags & O_NOFOLLOW))
flags &= ~O_TRUNC;
}

dout(10) << "open flags = " << flags
<< ", filemode = " << cmode
Expand All @@ -2753,6 +2757,13 @@ void Server::handle_client_open(MDRequestRef& mdr)
return;
}

if ((flags & O_TRUNC) && !cur->inode.is_file()) {
dout(7) << "specified O_TRUNC on !(file|symlink) " << *cur << dendl;
// we should return -EISDIR for directory, return -EINVAL for other non-regular
respond_to_request(mdr, cur->inode.is_dir() ? EISDIR : -EINVAL);
return;
}

if (cur->inode.inline_version != CEPH_INLINE_NONE &&
!mdr->session->connection->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)) {
dout(7) << "old client cannot open inline data file " << *cur << dendl;
Expand Down

0 comments on commit 2633ec3

Please sign in to comment.