@@ -283,24 +283,22 @@ static int mnt_is_readonly(struct vfsmount *mnt)
283283}
284284
285285/*
286- * Most r/o checks on a fs are for operations that take
287- * discrete amounts of time, like a write() or unlink().
288- * We must keep track of when those operations start
289- * (for permission checks) and when they end, so that
290- * we can determine when writes are able to occur to
291- * a filesystem.
286+ * Most r/o & frozen checks on a fs are for operations that take discrete
287+ * amounts of time, like a write() or unlink(). We must keep track of when
288+ * those operations start (for permission checks) and when they end, so that we
289+ * can determine when writes are able to occur to a filesystem.
292290 */
293291/**
294- * mnt_want_write - get write access to a mount
292+ * __mnt_want_write - get write access to a mount without freeze protection
295293 * @m: the mount on which to take a write
296294 *
297- * This tells the low-level filesystem that a write is
298- * about to be performed to it, and makes sure that
299- * writes are allowed before returning success. When
300- * the write operation is finished, mnt_drop_write()
301- * must be called. This is effectively a refcount.
295+ * This tells the low-level filesystem that a write is about to be performed to
296+ * it, and makes sure that writes are allowed (mnt it read-write) before
297+ * returning success. This operation does not protect against filesystem being
298+ * frozen. When the write operation is finished, __mnt_drop_write() must be
299+ * called. This is effectively a refcount.
302300 */
303- int mnt_want_write (struct vfsmount * m )
301+ int __mnt_want_write (struct vfsmount * m )
304302{
305303 struct mount * mnt = real_mount (m );
306304 int ret = 0 ;
@@ -326,6 +324,27 @@ int mnt_want_write(struct vfsmount *m)
326324 ret = - EROFS ;
327325 }
328326 preempt_enable ();
327+
328+ return ret ;
329+ }
330+
331+ /**
332+ * mnt_want_write - get write access to a mount
333+ * @m: the mount on which to take a write
334+ *
335+ * This tells the low-level filesystem that a write is about to be performed to
336+ * it, and makes sure that writes are allowed (mount is read-write, filesystem
337+ * is not frozen) before returning success. When the write operation is
338+ * finished, mnt_drop_write() must be called. This is effectively a refcount.
339+ */
340+ int mnt_want_write (struct vfsmount * m )
341+ {
342+ int ret ;
343+
344+ sb_start_write (m -> mnt_sb );
345+ ret = __mnt_want_write (m );
346+ if (ret )
347+ sb_end_write (m -> mnt_sb );
329348 return ret ;
330349}
331350EXPORT_SYMBOL_GPL (mnt_want_write );
@@ -355,38 +374,76 @@ int mnt_clone_write(struct vfsmount *mnt)
355374EXPORT_SYMBOL_GPL (mnt_clone_write );
356375
357376/**
358- * mnt_want_write_file - get write access to a file's mount
377+ * __mnt_want_write_file - get write access to a file's mount
359378 * @file: the file who's mount on which to take a write
360379 *
361- * This is like mnt_want_write , but it takes a file and can
380+ * This is like __mnt_want_write , but it takes a file and can
362381 * do some optimisations if the file is open for write already
363382 */
364- int mnt_want_write_file (struct file * file )
383+ int __mnt_want_write_file (struct file * file )
365384{
366385 struct inode * inode = file -> f_dentry -> d_inode ;
386+
367387 if (!(file -> f_mode & FMODE_WRITE ) || special_file (inode -> i_mode ))
368- return mnt_want_write (file -> f_path .mnt );
388+ return __mnt_want_write (file -> f_path .mnt );
369389 else
370390 return mnt_clone_write (file -> f_path .mnt );
371391}
392+
393+ /**
394+ * mnt_want_write_file - get write access to a file's mount
395+ * @file: the file who's mount on which to take a write
396+ *
397+ * This is like mnt_want_write, but it takes a file and can
398+ * do some optimisations if the file is open for write already
399+ */
400+ int mnt_want_write_file (struct file * file )
401+ {
402+ int ret ;
403+
404+ sb_start_write (file -> f_path .mnt -> mnt_sb );
405+ ret = __mnt_want_write_file (file );
406+ if (ret )
407+ sb_end_write (file -> f_path .mnt -> mnt_sb );
408+ return ret ;
409+ }
372410EXPORT_SYMBOL_GPL (mnt_want_write_file );
373411
374412/**
375- * mnt_drop_write - give up write access to a mount
413+ * __mnt_drop_write - give up write access to a mount
376414 * @mnt: the mount on which to give up write access
377415 *
378416 * Tells the low-level filesystem that we are done
379417 * performing writes to it. Must be matched with
380- * mnt_want_write () call above.
418+ * __mnt_want_write () call above.
381419 */
382- void mnt_drop_write (struct vfsmount * mnt )
420+ void __mnt_drop_write (struct vfsmount * mnt )
383421{
384422 preempt_disable ();
385423 mnt_dec_writers (real_mount (mnt ));
386424 preempt_enable ();
387425}
426+
427+ /**
428+ * mnt_drop_write - give up write access to a mount
429+ * @mnt: the mount on which to give up write access
430+ *
431+ * Tells the low-level filesystem that we are done performing writes to it and
432+ * also allows filesystem to be frozen again. Must be matched with
433+ * mnt_want_write() call above.
434+ */
435+ void mnt_drop_write (struct vfsmount * mnt )
436+ {
437+ __mnt_drop_write (mnt );
438+ sb_end_write (mnt -> mnt_sb );
439+ }
388440EXPORT_SYMBOL_GPL (mnt_drop_write );
389441
442+ void __mnt_drop_write_file (struct file * file )
443+ {
444+ __mnt_drop_write (file -> f_path .mnt );
445+ }
446+
390447void mnt_drop_write_file (struct file * file )
391448{
392449 mnt_drop_write (file -> f_path .mnt );
0 commit comments