if (cmd == OBD_BRW_WRITE) {
struct lu_nodemap *nodemap;
+ __u32 mapped_uid, mapped_gid;
+
+ nodemap = nodemap_get_from_exp(exp);
+ mapped_uid = nodemap_map_id(nodemap, NODEMAP_UID,
+ NODEMAP_FS_TO_CLIENT,
+ oa->o_uid);
+ mapped_gid = nodemap_map_id(nodemap, NODEMAP_GID,
+ NODEMAP_FS_TO_CLIENT,
+ oa->o_gid);
+
+ if (!IS_ERR_OR_NULL(nodemap)) {
+ /* do not bypass quota enforcement if squashed uid */
+ if (unlikely(mapped_uid == nodemap->nm_squash_uid)) {
+ int idx;
+
+ for (idx = 0; idx < npages; idx++)
+ lnb[idx].lnb_flags &= ~OBD_BRW_NOQUOTA;
+ }
+ nodemap_putref(nodemap);
+ }
valid = OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLPROJID |
OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME;
/* Convert back to client IDs. LU-9671.
* nodemap_get_from_exp() may fail due to nodemap deactivated,
* server ID will be returned back to client in that case. */
- nodemap = nodemap_get_from_exp(exp);
- if (nodemap != NULL && !IS_ERR(nodemap)) {
- oa->o_uid = nodemap_map_id(nodemap, NODEMAP_UID,
- NODEMAP_FS_TO_CLIENT,
- oa->o_uid);
- oa->o_gid = nodemap_map_id(nodemap, NODEMAP_GID,
- NODEMAP_FS_TO_CLIENT,
- oa->o_gid);
- nodemap_putref(nodemap);
- }
+ oa->o_uid = mapped_uid;
+ oa->o_gid = mapped_gid;
} else if (cmd == OBD_BRW_READ) {
rc = ofd_commitrw_read(env, ofd, fid, objcount,
npages, lnb);
cleanup_quota_test
}
+test_75()
+{
+ local limit=10 # MB
+ local testfile="$DIR/$tdir/$tfile-0"
+
+ setup_quota_test || error "setup quota failed with $?"
+ stack_trap cleanup_quota_test_75 EXIT
+
+ # enable ost quota
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ # test for user
+ log "User $TSTUSR quota block hardlimit:$limit MB"
+ $LFS setquota -u $TSTID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
+ error "set user quota failed"
+
+ # make sure the system is clean
+ local used=$(getquota -u $TSTID global curspace)
+ [ $used -ne 0 ] && error "Used space ($used) for user $TSTUSR not 0."
+
+ chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
+
+ do_facet mgs $LCTL nodemap_activate 1
+ wait_nm_sync active
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property admin --value 0
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property trusted --value 0
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property deny_unknown --value 0
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property squash_uid --value $TSTID
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property squash_gid --value $TSTID
+ cancel_lru_locks mdc
+ wait_nm_sync default admin_nodemap
+ wait_nm_sync default trusted_nodemap
+ wait_nm_sync default squash_uid
+
+ log "Write..."
+ $DD of=$testfile bs=1M count=$((limit/2)) ||
+ quota_error u $TSTID \
+ "root write failure, but expect success"
+
+ log "Write out of block quota ..."
+ # possibly a cache write, ignore failure
+ $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
+ # flush cache, ensure noquota flag is set on client
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+ # sync forced cache flush, but did not guarantee that slave
+ # got new edquot through glimpse, so wait to make sure
+ sleep 5
+ $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
+ quota_error u $TSTID \
+ "user write success, but expect EDQUOT"
+ rm -f $testfile
+ wait_delete_completed || error "wait_delete_completed failed"
+ sync_all_data || true
+ used=$(getquota -u $TSTUSR global curspace)
+ [ $used -eq 0 ] || quota_error u $TSTID \
+ "user quota not released after deletion"
+}
+run_test 75 "nodemap squashed root respects quota enforcement"
+
test_76() {
! is_project_quota_supported &&
skip "skip project quota unsupported"