From: Niu Yawei Date: Tue, 6 May 2014 05:23:12 +0000 (-0400) Subject: LU-4345 osp: store valid bits in setattr record X-Git-Tag: 2.5.60~49 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=80f90fcde73e;hp=8862fd2a3a34ad9bd97e1424252d37a740cbafd8;p=fs%2Flustre-release.git LU-4345 osp: store valid bits in setattr record We'd store LA_UID/LA_GID bit along with the UID/GID in the setattr llog record, otherwise, osp could set a random uid/gid to the OST object. Signed-off-by: Niu Yawei Change-Id: I17de21071127325ade8dea6f8618b622fec1768d Reviewed-on: http://review.whamcloud.com/10223 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Mike Pershin Reviewed-by: Alex Zhuravlev --- diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 6842e16..b8a910e 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -3283,7 +3283,7 @@ struct llog_setattr64_rec { __u32 lsr_uid_h; __u32 lsr_gid; __u32 lsr_gid_h; - __u64 lsr_padding; + __u64 lsr_valid; struct llog_rec_tail lsr_tail; } __attribute__((packed)); diff --git a/lustre/obdclass/llog_swab.c b/lustre/obdclass/llog_swab.c index e5af8a7..150921a 100644 --- a/lustre/obdclass/llog_swab.c +++ b/lustre/obdclass/llog_swab.c @@ -234,6 +234,7 @@ void lustre_swab_llog_rec(struct llog_rec_hdr *rec) __swab32s(&lsr->lsr_uid_h); __swab32s(&lsr->lsr_gid); __swab32s(&lsr->lsr_gid_h); + __swab64s(&lsr->lsr_valid); tail = &lsr->lsr_tail; break; } diff --git a/lustre/osp/osp_sync.c b/lustre/osp/osp_sync.c index 388c80e..814b4b1 100644 --- a/lustre/osp/osp_sync.c +++ b/lustre/osp/osp_sync.c @@ -235,6 +235,7 @@ static int osp_sync_add_rec(const struct lu_env *env, struct osp_device *d, LASSERT(attr); osi->osi_setattr.lsr_uid = attr->la_uid; osi->osi_setattr.lsr_gid = attr->la_gid; + osi->osi_setattr.lsr_valid = attr->la_valid; break; default: LBUG(); @@ -478,6 +479,13 @@ static int osp_sync_new_setattr_job(struct osp_device *d, ENTRY; LASSERT(h->lrh_type == MDS_SETATTR64_REC); + /* lsr_valid can only be 0 or LA_UID/GID set */ + if (!rec->lsr_valid && !(rec->lsr_valid & ~(LA_UID | LA_GID))) { + CERROR("%s: invalid setattr record, lsr_valid:"LPU64"\n", + d->opd_obd->obd_name, rec->lsr_valid); + RETURN(-EINVAL); + } + req = osp_sync_new_job(d, llh, h, OST_SETATTR, &RQF_OST_SETATTR); if (IS_ERR(req)) RETURN(PTR_ERR(req)); @@ -487,8 +495,17 @@ static int osp_sync_new_setattr_job(struct osp_device *d, body->oa.o_oi = rec->lsr_oi; body->oa.o_uid = rec->lsr_uid; body->oa.o_gid = rec->lsr_gid; - body->oa.o_valid = OBD_MD_FLGROUP | OBD_MD_FLID | - OBD_MD_FLUID | OBD_MD_FLGID; + body->oa.o_valid = OBD_MD_FLGROUP | OBD_MD_FLID; + /* old setattr record (prior 2.6.0) doesn't have 'valid' stored, + * we assume that both UID and GID are valid in that case. */ + if (rec->lsr_valid == 0) { + body->oa.o_valid |= (OBD_MD_FLUID | OBD_MD_FLGID); + } else { + if (rec->lsr_valid & LA_UID) + body->oa.o_valid |= OBD_MD_FLUID; + if (rec->lsr_valid & LA_GID) + body->oa.o_valid |= OBD_MD_FLGID; + } osp_sync_send_new_rpc(d, req); RETURN(0); diff --git a/lustre/ptlrpc/wiretest.c b/lustre/ptlrpc/wiretest.c index ee48eec..d0149f4 100644 --- a/lustre/ptlrpc/wiretest.c +++ b/lustre/ptlrpc/wiretest.c @@ -3459,10 +3459,10 @@ void lustre_assert_wire_constants(void) (long long)(int)offsetof(struct llog_setattr64_rec, lsr_gid_h)); LASSERTF((int)sizeof(((struct llog_setattr64_rec *)0)->lsr_gid_h) == 4, "found %lld\n", (long long)(int)sizeof(((struct llog_setattr64_rec *)0)->lsr_gid_h)); - LASSERTF((int)offsetof(struct llog_setattr64_rec, lsr_padding) == 48, "found %lld\n", - (long long)(int)offsetof(struct llog_setattr64_rec, lsr_padding)); - LASSERTF((int)sizeof(((struct llog_setattr64_rec *)0)->lsr_padding) == 8, "found %lld\n", - (long long)(int)sizeof(((struct llog_setattr64_rec *)0)->lsr_padding)); + LASSERTF((int)offsetof(struct llog_setattr64_rec, lsr_valid) == 48, "found %lld\n", + (long long)(int)offsetof(struct llog_setattr64_rec, lsr_valid)); + LASSERTF((int)sizeof(((struct llog_setattr64_rec *)0)->lsr_valid) == 8, "found %lld\n", + (long long)(int)sizeof(((struct llog_setattr64_rec *)0)->lsr_valid)); LASSERTF((int)offsetof(struct llog_setattr64_rec, lsr_tail) == 56, "found %lld\n", (long long)(int)offsetof(struct llog_setattr64_rec, lsr_tail)); LASSERTF((int)sizeof(((struct llog_setattr64_rec *)0)->lsr_tail) == 8, "found %lld\n", diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index 634d7f9..4de4a04 100644 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -2144,6 +2144,9 @@ test_34() { USED=$(getquota -g $TSTID global curspace) [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0." + local USED=$(getquota -u $TSTID2 global curspace) + [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0." + echo "Write file..." $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null || error "write failed" @@ -2180,6 +2183,24 @@ test_34() { [ $USED -eq 1 ] || error "Used inodes for group $TSTID is $USED, expected 1" + # chown won't change the ost object group. LU-4345 */ + echo "chown the file to user $TSTID2" + chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed" + + echo "Wait for setattr on objects finished..." + wait_delete_completed + + echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID" + USED=$(getquota -u $TSTID2 global curspace) + [ $USED -lt $BLK_CNT ] && + error "Used space for user $TSTID2 is $USED, expected $BLK_CNT" + USED=$(getquota -u $TSTID global curspace) + [ $USED -ne 0 ] && + error "Used space for user $TSTID is $USED, expected 0" + USED=$(getquota -g $TSTID global curspace) + [ $USED -lt $BLK_CNT ] && + error "Used space for group $TSTID is $USED, expected $BLK_CNT" + cleanup_quota_test } run_test 34 "Usage transfer for user & group" diff --git a/lustre/utils/wirecheck.c b/lustre/utils/wirecheck.c index f27f748..685b4ee 100644 --- a/lustre/utils/wirecheck.c +++ b/lustre/utils/wirecheck.c @@ -1498,7 +1498,7 @@ check_llog_setattr64_rec(void) CHECK_MEMBER(llog_setattr64_rec, lsr_uid_h); CHECK_MEMBER(llog_setattr64_rec, lsr_gid); CHECK_MEMBER(llog_setattr64_rec, lsr_gid_h); - CHECK_MEMBER(llog_setattr64_rec, lsr_padding); + CHECK_MEMBER(llog_setattr64_rec, lsr_valid); CHECK_MEMBER(llog_setattr64_rec, lsr_tail); } diff --git a/lustre/utils/wiretest.c b/lustre/utils/wiretest.c index 1138185..c9fd44e 100644 --- a/lustre/utils/wiretest.c +++ b/lustre/utils/wiretest.c @@ -3466,10 +3466,10 @@ void lustre_assert_wire_constants(void) (long long)(int)offsetof(struct llog_setattr64_rec, lsr_gid_h)); LASSERTF((int)sizeof(((struct llog_setattr64_rec *)0)->lsr_gid_h) == 4, "found %lld\n", (long long)(int)sizeof(((struct llog_setattr64_rec *)0)->lsr_gid_h)); - LASSERTF((int)offsetof(struct llog_setattr64_rec, lsr_padding) == 48, "found %lld\n", - (long long)(int)offsetof(struct llog_setattr64_rec, lsr_padding)); - LASSERTF((int)sizeof(((struct llog_setattr64_rec *)0)->lsr_padding) == 8, "found %lld\n", - (long long)(int)sizeof(((struct llog_setattr64_rec *)0)->lsr_padding)); + LASSERTF((int)offsetof(struct llog_setattr64_rec, lsr_valid) == 48, "found %lld\n", + (long long)(int)offsetof(struct llog_setattr64_rec, lsr_valid)); + LASSERTF((int)sizeof(((struct llog_setattr64_rec *)0)->lsr_valid) == 8, "found %lld\n", + (long long)(int)sizeof(((struct llog_setattr64_rec *)0)->lsr_valid)); LASSERTF((int)offsetof(struct llog_setattr64_rec, lsr_tail) == 56, "found %lld\n", (long long)(int)offsetof(struct llog_setattr64_rec, lsr_tail)); LASSERTF((int)sizeof(((struct llog_setattr64_rec *)0)->lsr_tail) == 8, "found %lld\n",