]> Pileus Git - ~andy/linux/commitdiff
fs: Fix hang with BSD accounting on frozen filesystem
authorJan Kara <jack@suse.cz>
Fri, 3 May 2013 22:11:23 +0000 (00:11 +0200)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 4 May 2013 18:57:58 +0000 (14:57 -0400)
When BSD process accounting is enabled and logs information to a
filesystem which gets frozen, system easily becomes unusable because
each attempt to account process information blocks. Thus e.g. every task
gets blocked in exit.

It seems better to drop accounting information (which can already happen
when filesystem is running out of space) instead of locking system up.
So we just skip the write if the filesystem is frozen.

Reported-by: Nikola Ciprich <nikola.ciprich@linuxbox.cz>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
include/linux/fs.h
kernel/acct.c

index e8cd6b8396753901227a34659cedca367beb0926..b5a24ba83b6f17c7ae98bce197559a8d7e6ef60e 100644 (file)
@@ -2227,6 +2227,13 @@ static inline void file_start_write(struct file *file)
        __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true);
 }
 
+static inline bool file_start_write_trylock(struct file *file)
+{
+       if (!S_ISREG(file_inode(file)->i_mode))
+               return true;
+       return __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false);
+}
+
 static inline void file_end_write(struct file *file)
 {
        if (!S_ISREG(file_inode(file)->i_mode))
index 85389fe2abd0a95bf99d4abe6b1de63e09351c4c..8d6e145138bb9d2e39e93933177f63536d73d018 100644 (file)
@@ -539,11 +539,16 @@ static void do_acct_process(struct bsd_acct_struct *acct,
        ac.ac_rw = encode_comp_t(ac.ac_io / 1024);
        ac.ac_swaps = encode_comp_t(0);
 
+       /*
+        * Get freeze protection. If the fs is frozen, just skip the write
+        * as we could deadlock the system otherwise.
+        */
+       if (!file_start_write_trylock(file))
+               goto out;
        /*
         * Kernel segment override to datasegment and write it
         * to the accounting file.
         */
-       file_start_write(file);
        fs = get_fs();
        set_fs(KERNEL_DS);
        /*