Commit 5b4b299cc7b6adfb9401bf7f826a80f190b971be

Authored by Al Viro
1 parent e7f5909707

nfsd4_list_rec_dir(): don't bother with reopening rec_file

just rewind it to the beginning before vfs_readdir() and be
done with that...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 1 changed file with 21 additions and 31 deletions Side-by-side Diff

fs/nfsd/nfs4recover.c
... ... @@ -191,52 +191,42 @@
191 191 }
192 192  
193 193 static int
194   -nfsd4_list_rec_dir(struct dentry *dir, recdir_func *f)
  194 +nfsd4_list_rec_dir(recdir_func *f)
195 195 {
196 196 const struct cred *original_cred;
197   - struct file *filp;
  197 + struct dentry *dir = rec_file->f_path.dentry;
198 198 LIST_HEAD(names);
199   - struct name_list *entry;
200   - struct dentry *dentry;
201 199 int status;
202 200  
203   - if (!rec_file)
204   - return 0;
205   -
206 201 status = nfs4_save_creds(&original_cred);
207 202 if (status < 0)
208 203 return status;
209 204  
210   - filp = dentry_open(dget(dir), mntget(rec_file->f_path.mnt), O_RDONLY,
211   - current_cred());
212   - status = PTR_ERR(filp);
213   - if (IS_ERR(filp))
214   - goto out;
215   - status = vfs_readdir(filp, nfsd4_build_namelist, &names);
216   - fput(filp);
  205 + status = vfs_llseek(rec_file, 0, SEEK_SET);
  206 + if (status < 0) {
  207 + nfs4_reset_creds(original_cred);
  208 + return status;
  209 + }
  210 +
  211 + status = vfs_readdir(rec_file, nfsd4_build_namelist, &names);
217 212 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
218 213 while (!list_empty(&names)) {
  214 + struct name_list *entry;
219 215 entry = list_entry(names.next, struct name_list, list);
220   -
221   - dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
222   - if (IS_ERR(dentry)) {
223   - status = PTR_ERR(dentry);
224   - break;
  216 + if (!status) {
  217 + struct dentry *dentry;
  218 + dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
  219 + if (IS_ERR(dentry)) {
  220 + status = PTR_ERR(dentry);
  221 + break;
  222 + }
  223 + status = f(dir, dentry);
  224 + dput(dentry);
225 225 }
226   - status = f(dir, dentry);
227   - dput(dentry);
228   - if (status)
229   - break;
230 226 list_del(&entry->list);
231 227 kfree(entry);
232 228 }
233 229 mutex_unlock(&dir->d_inode->i_mutex);
234   -out:
235   - while (!list_empty(&names)) {
236   - entry = list_entry(names.next, struct name_list, list);
237   - list_del(&entry->list);
238   - kfree(entry);
239   - }
240 230 nfs4_reset_creds(original_cred);
241 231 return status;
242 232 }
... ... @@ -322,7 +312,7 @@
322 312 status = mnt_want_write(rec_file->f_path.mnt);
323 313 if (status)
324 314 goto out;
325   - status = nfsd4_list_rec_dir(rec_file->f_path.dentry, purge_old);
  315 + status = nfsd4_list_rec_dir(purge_old);
326 316 if (status == 0)
327 317 vfs_fsync(rec_file, 0);
328 318 mnt_drop_write(rec_file->f_path.mnt);
... ... @@ -352,7 +342,7 @@
352 342 if (!rec_file)
353 343 return 0;
354 344  
355   - status = nfsd4_list_rec_dir(rec_file->f_path.dentry, load_recdir);
  345 + status = nfsd4_list_rec_dir(load_recdir);
356 346 if (status)
357 347 printk("nfsd4: failed loading clients from recovery"
358 348 " directory %s\n", rec_file->f_path.dentry->d_name.name);