Skip to content

Commit

Permalink
Merge a04f236 into c17f019
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthanup committed Jul 12, 2021
2 parents c17f019 + a04f236 commit d444b25
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 11 deletions.
24 changes: 24 additions & 0 deletions qa/tasks/cephfs/test_layout.py
@@ -0,0 +1,24 @@
import logging

from tasks.cephfs.cephfs_test_case import CephFSTestCase

log = logging.getLogger(__name__)

class TestInheritedLayout(CephFSTestCase):

def test_layout_root(self):
self.mount_a.run_shell(["mkdir", "a"])
layout = self.mount_a.getfattr("a", "ceph.dir.layout")
log.info(layout)

def test_layout(self):
self.mount_a.run_shell(["mkdir", "-p", "a/b"])
self.mount_a.setfattr("a", "ceph.dir.layout.stripe_count", "2")
layout_a = self.mount_a.getfattr("a", "ceph.dir.layout")
log.info(layout_a)
layout_b = self.mount_a.getfattr("b", "ceph.dir.layout")
log.info(layout_b)




9 changes: 8 additions & 1 deletion src/client/Client.cc
Expand Up @@ -12187,7 +12187,8 @@ int Client::_getxattr(Inode *in, const char *name, void *value, size_t size,
if (vxattr->flags & VXATTR_RSTAT) {
flags |= CEPH_STAT_RSTAT;
}
if (vxattr->flags & VXATTR_DIRSTAT) {
if (vxattr->flags & (VXATTR_DIRSTAT ||
vxattr->name.compare(0, 15, "ceph.dir.layout") == 0)) {
flags |= CEPH_CAP_FILE_SHARED;
}
r = _getattr(in, flags | CEPH_STAT_CAP_XATTR, perms, true);
Expand Down Expand Up @@ -12219,7 +12220,11 @@ int Client::_getxattr(Inode *in, const char *name, void *value, size_t size,
goto out;
}

//if (strncmp(name, "layout", 6)) {
//r = _getattr(in, CEPH_STAT_INHERIT_LAYOUT, perms, in->xattr_version == 0);
//} else {
r = _getattr(in, CEPH_STAT_CAP_XATTR, perms, in->xattr_version == 0);
//}
if (r == 0) {
string n(name);
r = -CEPHFS_ENODATA;
Expand Down Expand Up @@ -12647,6 +12652,8 @@ size_t Client::_vxattrcb_layout(Inode *in, char *val, size_t size)
if (in->layout.pool_ns.length())
r += snprintf(val + r, size - r, " pool_namespace=%s",
in->layout.pool_ns.c_str());
if (in->layout.inherit)
r += snprintf(val + r, size -r, "inherited");
return r;
}
size_t Client::_vxattrcb_layout_stripe_unit(Inode *in, char *val, size_t size)
Expand Down
1 change: 1 addition & 0 deletions src/include/ceph_fs.h
Expand Up @@ -805,6 +805,7 @@ int ceph_flags_to_mode(int flags);
#define CEPH_STAT_CAP_INLINE_DATA (CEPH_CAP_FILE_SHARED | \
CEPH_CAP_FILE_RD)
#define CEPH_STAT_RSTAT CEPH_CAP_FILE_WREXTEND
#define CEPH_STAT_INHERIT_LAYOUT CEPH_CAP_GRD

#define CEPH_CAP_ANY_SHARED (CEPH_CAP_AUTH_SHARED | \
CEPH_CAP_LINK_SHARED | \
Expand Down
5 changes: 4 additions & 1 deletion src/include/fs_types.h
Expand Up @@ -137,11 +137,14 @@ struct file_layout_t {
int64_t pool_id; ///< rados pool id
std::string pool_ns; ///< rados pool namespace

bool inherit; ///< is the layout inherited?

file_layout_t(uint32_t su=0, uint32_t sc=0, uint32_t os=0)
: stripe_unit(su),
stripe_count(sc),
object_size(os),
pool_id(-1) {
pool_id(-1),
inherit(false) {
}

static file_layout_t get_default() {
Expand Down
8 changes: 7 additions & 1 deletion src/mds/CInode.cc
Expand Up @@ -3678,7 +3678,8 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
SnapRealm *dir_realm,
snapid_t snapid,
unsigned max_bytes,
int getattr_caps)
int getattr_caps,
file_layout_t inherit_layout)
{
client_t client = session->get_client();
ceph_assert(snapid);
Expand Down Expand Up @@ -3787,6 +3788,11 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
layout = file_i->layout;
}

if (inherit_layout != file_layout_t()) {
layout = inherit_layout;
dout(10) << "Inside if condition" << dendl;
}

// max_size is min of projected, actual
uint64_t max_size =
std::min(oi->get_client_range(client),
Expand Down
4 changes: 2 additions & 2 deletions src/mds/CInode.h
Expand Up @@ -792,8 +792,8 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CIno

// for giving to clients
int encode_inodestat(ceph::buffer::list& bl, Session *session, SnapRealm *realm,
snapid_t snapid=CEPH_NOSNAP, unsigned max_bytes=0,
int getattr_wants=0);
snapid_t snapid=CEPH_NOSNAP, unsigned max_bytes=0,
int getattr_wants=0, file_layout_t inherit_layout=file_layout_t());
void encode_cap_message(const ceph::ref_t<MClientCaps> &m, Capability *cap);

SimpleLock* get_lock(int type) override;
Expand Down
32 changes: 27 additions & 5 deletions src/mds/Server.cc
Expand Up @@ -2310,7 +2310,12 @@ void Server::set_trace_dist(const ref_t<MClientReply> &reply,

// inode
if (in) {
in->encode_inodestat(bl, session, NULL, snapid, 0, mdr->getattr_caps);
if (mdr->client_request->head.args.getattr.mask && CEPH_STAT_INHERIT_LAYOUT) {
in->encode_inodestat(bl, session, NULL, snapid, 0, mdr->getattr_caps, mdr->dir_layout);
} else {
in->encode_inodestat(bl, session, NULL, snapid, 0, mdr->getattr_caps);
}

dout(20) << "set_trace_dist added in " << *in << dendl;
reply->head.is_target = 1;
} else
Expand Down Expand Up @@ -3404,7 +3409,7 @@ class C_MDS_TryFindInode : public ServerContext {
* as appropriate: forwarded on, or the client's been replied to */
CInode* Server::rdlock_path_pin_ref(MDRequestRef& mdr,
bool want_auth,
bool no_want_auth)
bool no_want_auth, bool want_layout)
{
const filepath& refpath = mdr->get_filepath();
dout(10) << "rdlock_path_pin_ref " << *mdr << " " << refpath << dendl;
Expand All @@ -3425,6 +3430,8 @@ CInode* Server::rdlock_path_pin_ref(MDRequestRef& mdr,
}
if (want_auth)
flags |= MDS_TRAVERSE_WANT_AUTH;
if (want_layout)
flags |= MDS_TRAVERSE_WANT_DIRLAYOUT;
int r = mdcache->path_traverse(mdr, cf, refpath, flags, &mdr->dn[0], &mdr->in[0]);
if (r > 0)
return nullptr; // delayed
Expand Down Expand Up @@ -3784,15 +3791,26 @@ void Server::handle_client_getattr(MDRequestRef& mdr, bool is_lookup)
}

bool want_auth = false;
bool want_layout = false;
int mask = req->head.args.getattr.mask;
if (mask & CEPH_STAT_RSTAT)
want_auth = true; // set want_auth for CEPH_STAT_RSTAT mask

if (mask & CEPH_STAT_INHERIT_LAYOUT) {
want_layout = true;
}

if (!mdr->is_batch_head() && mdr->can_batch()) {
CF_MDS_RetryRequestFactory cf(mdcache, mdr, false);
int flags = 0;
if (want_auth) {
flags |= MDS_TRAVERSE_WANT_AUTH;
}
if (want_layout) {
flags |= MDS_TRAVERSE_WANT_DIRLAYOUT;
}
int r = mdcache->path_traverse(mdr, cf, mdr->get_filepath(),
(want_auth ? MDS_TRAVERSE_WANT_AUTH : 0),
&mdr->dn[0], &mdr->in[0]);
flags, &mdr->dn[0], &mdr->in[0]);
if (r > 0)
return; // delayed

Expand Down Expand Up @@ -3823,7 +3841,7 @@ void Server::handle_client_getattr(MDRequestRef& mdr, bool is_lookup)
}
}

CInode *ref = rdlock_path_pin_ref(mdr, want_auth, false);
CInode *ref = rdlock_path_pin_ref(mdr, want_auth, false, want_layout);
if (!ref)
return;

Expand Down Expand Up @@ -3883,6 +3901,10 @@ void Server::handle_client_getattr(MDRequestRef& mdr, bool is_lookup)

mds->balancer->hit_inode(ref, META_POP_IRD, req->get_source().num());

if (want_layout) {
mdr->dir_layout.inherit = true;
}

// reply
dout(10) << "reply to stat on " << *req << dendl;
mdr->tracei = ref;
Expand Down
2 changes: 1 addition & 1 deletion src/mds/Server.h
Expand Up @@ -185,7 +185,7 @@ class Server {
void apply_allocated_inos(MDRequestRef& mdr, Session *session);

CInode* rdlock_path_pin_ref(MDRequestRef& mdr, bool want_auth,
bool no_want_auth=false);
bool no_want_auth=false, bool want_layout=false);
CDentry* rdlock_path_xlock_dentry(MDRequestRef& mdr, bool create,
bool okexist=false, bool want_layout=false);
std::pair<CDentry*, CDentry*>
Expand Down

0 comments on commit d444b25

Please sign in to comment.