diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2014-04-19 14:24:18 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2014-08-07 14:40:08 -0400 |
commit | 54a4d58a6459a93fc6ee898354b3d2ffb80dd03a (patch) | |
tree | c47084891155b17c7fadad5a6a4a4900582bfedc /kernel/acct.c | |
parent | b8f00e6be46f4c9a112e05fd692712873c4c4048 (diff) |
acct: simplify check_free_space()
a) file can't be NULL
b) file can't be changed under us
c) all writes are serialized by acct->lock; no need to mess with
spinlock there.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'kernel/acct.c')
-rw-r--r-- | kernel/acct.c | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/kernel/acct.c b/kernel/acct.c index f9ef9db55c0e..019f012a3c6f 100644 --- a/kernel/acct.c +++ b/kernel/acct.c | |||
@@ -93,64 +93,36 @@ static LIST_HEAD(acct_list); | |||
93 | /* | 93 | /* |
94 | * Check the amount of free space and suspend/resume accordingly. | 94 | * Check the amount of free space and suspend/resume accordingly. |
95 | */ | 95 | */ |
96 | static int check_free_space(struct bsd_acct_struct *acct, struct file *file) | 96 | static int check_free_space(struct bsd_acct_struct *acct) |
97 | { | 97 | { |
98 | struct kstatfs sbuf; | 98 | struct kstatfs sbuf; |
99 | int res; | ||
100 | int act; | ||
101 | u64 resume; | ||
102 | u64 suspend; | ||
103 | 99 | ||
104 | spin_lock(&acct_lock); | 100 | if (time_is_before_jiffies(acct->needcheck)) |
105 | res = acct->active; | ||
106 | if (!file || time_is_before_jiffies(acct->needcheck)) | ||
107 | goto out; | 101 | goto out; |
108 | spin_unlock(&acct_lock); | ||
109 | 102 | ||
110 | /* May block */ | 103 | /* May block */ |
111 | if (vfs_statfs(&file->f_path, &sbuf)) | 104 | if (vfs_statfs(&acct->file->f_path, &sbuf)) |
112 | return res; | ||
113 | suspend = sbuf.f_blocks * SUSPEND; | ||
114 | resume = sbuf.f_blocks * RESUME; | ||
115 | |||
116 | do_div(suspend, 100); | ||
117 | do_div(resume, 100); | ||
118 | |||
119 | if (sbuf.f_bavail <= suspend) | ||
120 | act = -1; | ||
121 | else if (sbuf.f_bavail >= resume) | ||
122 | act = 1; | ||
123 | else | ||
124 | act = 0; | ||
125 | |||
126 | /* | ||
127 | * If some joker switched acct->file under us we'ld better be | ||
128 | * silent and _not_ touch anything. | ||
129 | */ | ||
130 | spin_lock(&acct_lock); | ||
131 | if (file != acct->file) { | ||
132 | if (act) | ||
133 | res = act > 0; | ||
134 | goto out; | 105 | goto out; |
135 | } | ||
136 | 106 | ||
137 | if (acct->active) { | 107 | if (acct->active) { |
138 | if (act < 0) { | 108 | u64 suspend = sbuf.f_blocks * SUSPEND; |
109 | do_div(suspend, 100); | ||
110 | if (sbuf.f_bavail <= suspend) { | ||
139 | acct->active = 0; | 111 | acct->active = 0; |
140 | printk(KERN_INFO "Process accounting paused\n"); | 112 | printk(KERN_INFO "Process accounting paused\n"); |
141 | } | 113 | } |
142 | } else { | 114 | } else { |
143 | if (act > 0) { | 115 | u64 resume = sbuf.f_blocks * RESUME; |
116 | do_div(resume, 100); | ||
117 | if (sbuf.f_bavail >= resume) { | ||
144 | acct->active = 1; | 118 | acct->active = 1; |
145 | printk(KERN_INFO "Process accounting resumed\n"); | 119 | printk(KERN_INFO "Process accounting resumed\n"); |
146 | } | 120 | } |
147 | } | 121 | } |
148 | 122 | ||
149 | acct->needcheck = jiffies + ACCT_TIMEOUT*HZ; | 123 | acct->needcheck = jiffies + ACCT_TIMEOUT*HZ; |
150 | res = acct->active; | ||
151 | out: | 124 | out: |
152 | spin_unlock(&acct_lock); | 125 | return acct->active; |
153 | return res; | ||
154 | } | 126 | } |
155 | 127 | ||
156 | static void acct_put(struct bsd_acct_struct *p) | 128 | static void acct_put(struct bsd_acct_struct *p) |
@@ -550,7 +522,7 @@ static void do_acct_process(struct bsd_acct_struct *acct) | |||
550 | * First check to see if there is enough free_space to continue | 522 | * First check to see if there is enough free_space to continue |
551 | * the process accounting system. | 523 | * the process accounting system. |
552 | */ | 524 | */ |
553 | if (!check_free_space(acct, file)) | 525 | if (!check_free_space(acct)) |
554 | goto out; | 526 | goto out; |
555 | 527 | ||
556 | fill_ac(&ac); | 528 | fill_ac(&ac); |