/* Swab any part of val you need to here */
if (KEY_IS(KEY_READ_ONLY)) {
+ /* If client wants rw, make sure nodemap does not enforce ro. */
+ if (!*(__u32 *)val) {
+ struct lu_nodemap *nm = NULL;
+ bool readonly = false;
+
+ if (req->rq_export)
+ nm = nodemap_get_from_exp(req->rq_export);
+
+ if (!IS_ERR_OR_NULL(nm)) {
+ readonly = nm->nmf_readonly_mount;
+ nodemap_putref(nm);
+ }
+
+ if (unlikely(readonly))
+ RETURN(-EROFS);
+ }
spin_lock(&req->rq_export->exp_lock);
if (*(__u32 *)val)
*exp_connect_flags_ptr(req->rq_export) |=
do_facet mgs $LCTL nodemap_modify --name c0 \
--property readonly_mount --value 1
wait_nm_sync c0 readonly_mount
+
+ # mount without option should turn into ro
zconf_mount_clients $HOSTNAME $MOUNT ${MOUNT_OPTS} ||
- error "mount failed"
+ error "mount failed (1)"
findmnt $MOUNT --output=options -n -f | grep -q "ro," ||
error "mount should have been turned into ro"
cat $testfile || error "read $testfile failed (1)"
echo b > $testfile && error "write $testfile should fail (1)"
umount_client $MOUNT || error "umount $MOUNT failed (3)"
+
+ # mount rw should turn into ro
zconf_mount_clients $HOSTNAME $MOUNT ${MOUNT_OPTS},rw ||
error "mount '-o rw' failed"
findmnt $MOUNT --output=options -n -f | grep -q "ro," ||
cat $testfile || error "read $testfile failed (2)"
echo b > $testfile && error "write $testfile should fail (2)"
umount_client $MOUNT || error "umount $MOUNT failed (4)"
+
+ # mount ro should work as expected
zconf_mount_clients $HOSTNAME $MOUNT ${MOUNT_OPTS},ro ||
error "mount '-o ro' failed"
wait_ssk
cat $testfile || error "read $testfile failed (3)"
echo b > $testfile && error "write $testfile should fail (3)"
umount_client $MOUNT || error "umount $MOUNT failed (5)"
+
+ # remount rw should not work
+ zconf_mount_clients $HOSTNAME $MOUNT ${MOUNT_OPTS} ||
+ error "mount failed (2)"
+ mount_client $MOUNT remount,rw || error "remount failed"
+ findmnt $MOUNT --output=options -n -f | grep -q "ro," ||
+ error "remount rw should have been turned into ro"
+ cat $testfile || error "read $testfile failed (4)"
+ echo b > $testfile && error "write $testfile should fail (4)"
+ umount_client $MOUNT || error "umount $MOUNT failed (6)"
}
run_test 61 "Nodemap enforces read-only mount"