diff options
author | Oleg Nesterov <oleg@tv-sign.ru> | 2005-06-23 03:10:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-23 12:45:29 -0400 |
commit | dfb388bf8a328f206bba33933dd97230f412238b (patch) | |
tree | 656cf4d7aba441667c4d25135ee70672738126e9 /fs/buffer.c | |
parent | 01890a4c120f68366441bf5e193d1b9dd543d4d0 (diff) |
[PATCH] factor out common code in sys_fsync/sys_fdatasync
This patch consolidates sys_fsync and sys_fdatasync.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/buffer.c')
-rw-r--r-- | fs/buffer.c | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/fs/buffer.c b/fs/buffer.c index 0befa724ab98..12bdb2791127 100644 --- a/fs/buffer.c +++ b/fs/buffer.c | |||
@@ -331,7 +331,7 @@ int file_fsync(struct file *filp, struct dentry *dentry, int datasync) | |||
331 | return ret; | 331 | return ret; |
332 | } | 332 | } |
333 | 333 | ||
334 | asmlinkage long sys_fsync(unsigned int fd) | 334 | static long do_fsync(unsigned int fd, int datasync) |
335 | { | 335 | { |
336 | struct file * file; | 336 | struct file * file; |
337 | struct address_space *mapping; | 337 | struct address_space *mapping; |
@@ -342,14 +342,14 @@ asmlinkage long sys_fsync(unsigned int fd) | |||
342 | if (!file) | 342 | if (!file) |
343 | goto out; | 343 | goto out; |
344 | 344 | ||
345 | mapping = file->f_mapping; | ||
346 | |||
347 | ret = -EINVAL; | 345 | ret = -EINVAL; |
348 | if (!file->f_op || !file->f_op->fsync) { | 346 | if (!file->f_op || !file->f_op->fsync) { |
349 | /* Why? We can still call filemap_fdatawrite */ | 347 | /* Why? We can still call filemap_fdatawrite */ |
350 | goto out_putf; | 348 | goto out_putf; |
351 | } | 349 | } |
352 | 350 | ||
351 | mapping = file->f_mapping; | ||
352 | |||
353 | current->flags |= PF_SYNCWRITE; | 353 | current->flags |= PF_SYNCWRITE; |
354 | ret = filemap_fdatawrite(mapping); | 354 | ret = filemap_fdatawrite(mapping); |
355 | 355 | ||
@@ -358,7 +358,7 @@ asmlinkage long sys_fsync(unsigned int fd) | |||
358 | * which could cause livelocks in fsync_buffers_list | 358 | * which could cause livelocks in fsync_buffers_list |
359 | */ | 359 | */ |
360 | down(&mapping->host->i_sem); | 360 | down(&mapping->host->i_sem); |
361 | err = file->f_op->fsync(file, file->f_dentry, 0); | 361 | err = file->f_op->fsync(file, file->f_dentry, datasync); |
362 | if (!ret) | 362 | if (!ret) |
363 | ret = err; | 363 | ret = err; |
364 | up(&mapping->host->i_sem); | 364 | up(&mapping->host->i_sem); |
@@ -373,39 +373,14 @@ out: | |||
373 | return ret; | 373 | return ret; |
374 | } | 374 | } |
375 | 375 | ||
376 | asmlinkage long sys_fdatasync(unsigned int fd) | 376 | asmlinkage long sys_fsync(unsigned int fd) |
377 | { | 377 | { |
378 | struct file * file; | 378 | return do_fsync(fd, 0); |
379 | struct address_space *mapping; | 379 | } |
380 | int ret, err; | ||
381 | |||
382 | ret = -EBADF; | ||
383 | file = fget(fd); | ||
384 | if (!file) | ||
385 | goto out; | ||
386 | |||
387 | ret = -EINVAL; | ||
388 | if (!file->f_op || !file->f_op->fsync) | ||
389 | goto out_putf; | ||
390 | |||
391 | mapping = file->f_mapping; | ||
392 | |||
393 | current->flags |= PF_SYNCWRITE; | ||
394 | ret = filemap_fdatawrite(mapping); | ||
395 | down(&mapping->host->i_sem); | ||
396 | err = file->f_op->fsync(file, file->f_dentry, 1); | ||
397 | if (!ret) | ||
398 | ret = err; | ||
399 | up(&mapping->host->i_sem); | ||
400 | err = filemap_fdatawait(mapping); | ||
401 | if (!ret) | ||
402 | ret = err; | ||
403 | current->flags &= ~PF_SYNCWRITE; | ||
404 | 380 | ||
405 | out_putf: | 381 | asmlinkage long sys_fdatasync(unsigned int fd) |
406 | fput(file); | 382 | { |
407 | out: | 383 | return do_fsync(fd, 1); |
408 | return ret; | ||
409 | } | 384 | } |
410 | 385 | ||
411 | /* | 386 | /* |