Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Oleg Nesterov and committed by
Linus Torvalds
dfb388bf 01890a4c

+10 -35
+10 -35
fs/buffer.c
··· 331 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 336 struct file * file; 337 337 struct address_space *mapping; ··· 342 342 if (!file) 343 343 goto out; 344 344 345 - mapping = file->f_mapping; 346 - 347 345 ret = -EINVAL; 348 346 if (!file->f_op || !file->f_op->fsync) { 349 347 /* Why? We can still call filemap_fdatawrite */ 350 348 goto out_putf; 351 349 } 350 + 351 + mapping = file->f_mapping; 352 352 353 353 current->flags |= PF_SYNCWRITE; 354 354 ret = filemap_fdatawrite(mapping); ··· 358 358 * which could cause livelocks in fsync_buffers_list 359 359 */ 360 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 362 if (!ret) 363 363 ret = err; 364 364 up(&mapping->host->i_sem); ··· 373 373 return ret; 374 374 } 375 375 376 + asmlinkage long sys_fsync(unsigned int fd) 377 + { 378 + return do_fsync(fd, 0); 379 + } 380 + 376 381 asmlinkage long sys_fdatasync(unsigned int fd) 377 382 { 378 - struct file * file; 379 - struct address_space *mapping; 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 - 405 - out_putf: 406 - fput(file); 407 - out: 408 - return ret; 383 + return do_fsync(fd, 1); 409 384 } 410 385 411 386 /*