#else /* !HAVE_IOP_ATOMIC_OPEN */
static struct lookup_intent *
-ll_convert_intent(struct open_intent *oit, int lookup_flags)
+ll_convert_intent(struct open_intent *oit, int lookup_flags, bool is_readonly)
{
struct lookup_intent *it;
if (lookup_flags & LOOKUP_OPEN) {
it->it_op = IT_OPEN;
- if (lookup_flags & LOOKUP_CREATE)
+ /* Avoid file creation for ro bind mount point(is_readonly) */
+ if ((lookup_flags & LOOKUP_CREATE) && !is_readonly)
it->it_op |= IT_CREAT;
it->it_create_mode = (oit->create_mode & S_IALLUGO) | S_IFREG;
- it->it_flags = ll_namei_to_lookup_intent_flag(oit->flags);
+ it->it_flags = ll_namei_to_lookup_intent_flag(oit->flags &
+ ~(is_readonly ? O_CREAT : 0));
it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
} else {
it->it_op = IT_GETATTR;
MAY_WRITE | MAY_EXEC) == 0))
RETURN(NULL);
- it = ll_convert_intent(&nd->intent.open, nd->flags);
+ it = ll_convert_intent(&nd->intent.open, nd->flags,
+ (nd->path.mnt->mnt_flags & MNT_READONLY) ||
+ (nd->path.mnt->mnt_sb->s_flags & MS_RDONLY));
if (IS_ERR(it))
RETURN((struct dentry *)it);
}
}
run_test 104 "Make sure user defined options are reflected in mount"
+error_and_umount() {
+ umount $TMP/$tdir
+ rmdir $TMP/$tdir
+ error $*
+}
+
+test_105() {
+ cleanup
+ reformat
+ setup
+ mkdir -p $TMP/$tdir
+ mount --bind $DIR $TMP/$tdir || error "mount bind mnt pt failed"
+ rm -f $TMP/$tdir/$tfile
+ rm -f $TMP/$tdir/${tfile}1
+
+ # Files should not be created in ro bind mount point
+ # remounting from rw to ro
+ mount -o remount,ro $TMP/$tdir ||
+ error_and_umount "readonly remount of bind mnt pt failed"
+ touch $TMP/$tdir/$tfile &&
+ error_and_umount "touch succeeds on ro bind mnt pt"
+ [ -e $TMP/$tdir/$tfile ] &&
+ error_and_umount "file created on ro bind mnt pt"
+
+ # Files should be created in rw bind mount point
+ # remounting from ro to rw
+ mount -o remount,rw $TMP/$tdir ||
+ error_and_umount "read-write remount of bind mnt pt failed"
+ touch $TMP/$tdir/${tfile}1 ||
+ error_and_umount "touch fails on rw bind mnt pt"
+ [ -e $TMP/$tdir/${tfile}1 ] ||
+ error_and_umount "file not created on rw bind mnt pt"
+ umount $TMP/$tdir || error "umount of bind mnt pt failed"
+ rmdir $TMP/$tdir
+}
+run_test 105 "check file creation for ro and rw bind mnt pt"
+
if ! combined_mgs_mds ; then
stop mgs
fi