Whamcloud - gitweb
LU-4345 osp: store valid bits in setattr record 23/10223/5
authorNiu Yawei <yawei.niu@intel.com>
Tue, 6 May 2014 05:23:12 +0000 (01:23 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 30 May 2014 01:50:33 +0000 (01:50 +0000)
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 <yawei.niu@intel.com>
Change-Id: I17de21071127325ade8dea6f8618b622fec1768d
Reviewed-on: http://review.whamcloud.com/10223
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Mike Pershin <mike.pershin@intel.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
lustre/include/lustre/lustre_idl.h
lustre/obdclass/llog_swab.c
lustre/osp/osp_sync.c
lustre/ptlrpc/wiretest.c
lustre/tests/sanity-quota.sh
lustre/utils/wirecheck.c
lustre/utils/wiretest.c

index 6842e16..b8a910e 100644 (file)
@@ -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));
 
index e5af8a7..150921a 100644 (file)
@@ -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;
         }
index 388c80e..814b4b1 100644 (file)
@@ -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);
index ee48eec..d0149f4 100644 (file)
@@ -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",
index 634d7f9..4de4a04 100644 (file)
@@ -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"
index f27f748..685b4ee 100644 (file)
@@ -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);
 }
 
index 1138185..c9fd44e 100644 (file)
@@ -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",