file.c (25a912e51af7c0761a6d3424640901ded517e201) file.c (1ad71a27124caf0b68ddd3c92be01aa2b2a72b2a)
1/*
2 * fs/f2fs/file.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

--- 2658 unchanged lines hidden (view full) ---

2667
2668 err = f2fs_ioc_setproject(filp, fa.fsx_projid);
2669 if (err)
2670 return err;
2671
2672 return 0;
2673}
2674
1/*
2 * fs/f2fs/file.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

--- 2658 unchanged lines hidden (view full) ---

2667
2668 err = f2fs_ioc_setproject(filp, fa.fsx_projid);
2669 if (err)
2670 return err;
2671
2672 return 0;
2673}
2674
2675int f2fs_pin_file_control(struct inode *inode, bool inc)
2676{
2677 struct f2fs_inode_info *fi = F2FS_I(inode);
2678 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
2679
2680 /* Use i_gc_failures for normal file as a risk signal. */
2681 if (inc)
2682 f2fs_i_gc_failures_write(inode, fi->i_gc_failures + 1);
2683
2684 if (fi->i_gc_failures > sbi->gc_pin_file_threshold) {
2685 f2fs_msg(sbi->sb, KERN_WARNING,
2686 "%s: Enable GC = ino %lx after %x GC trials\n",
2687 __func__, inode->i_ino, fi->i_gc_failures);
2688 clear_inode_flag(inode, FI_PIN_FILE);
2689 return -EAGAIN;
2690 }
2691 return 0;
2692}
2693
2694static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg)
2695{
2696 struct inode *inode = file_inode(filp);
2697 __u32 pin;
2698 int ret = 0;
2699
2700 if (!inode_owner_or_capable(inode))
2701 return -EACCES;
2702
2703 if (get_user(pin, (__u32 __user *)arg))
2704 return -EFAULT;
2705
2706 if (!S_ISREG(inode->i_mode))
2707 return -EINVAL;
2708
2709 if (f2fs_readonly(F2FS_I_SB(inode)->sb))
2710 return -EROFS;
2711
2712 ret = mnt_want_write_file(filp);
2713 if (ret)
2714 return ret;
2715
2716 inode_lock(inode);
2717
2718 if (!pin) {
2719 clear_inode_flag(inode, FI_PIN_FILE);
2720 F2FS_I(inode)->i_gc_failures = 1;
2721 goto done;
2722 }
2723
2724 if (f2fs_pin_file_control(inode, false)) {
2725 ret = -EAGAIN;
2726 goto out;
2727 }
2728 ret = f2fs_convert_inline_inode(inode);
2729 if (ret)
2730 goto out;
2731
2732 set_inode_flag(inode, FI_PIN_FILE);
2733 ret = F2FS_I(inode)->i_gc_failures;
2734done:
2735 f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
2736out:
2737 inode_unlock(inode);
2738 mnt_drop_write_file(filp);
2739 return ret;
2740}
2741
2742static int f2fs_ioc_get_pin_file(struct file *filp, unsigned long arg)
2743{
2744 struct inode *inode = file_inode(filp);
2745 __u32 pin = 0;
2746
2747 if (is_inode_flag_set(inode, FI_PIN_FILE))
2748 pin = F2FS_I(inode)->i_gc_failures;
2749 return put_user(pin, (u32 __user *)arg);
2750}
2751
2675long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2676{
2677 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
2678 return -EIO;
2679
2680 switch (cmd) {
2681 case F2FS_IOC_GETFLAGS:
2682 return f2fs_ioc_getflags(filp, arg);

--- 34 unchanged lines hidden (view full) ---

2717 case F2FS_IOC_FLUSH_DEVICE:
2718 return f2fs_ioc_flush_device(filp, arg);
2719 case F2FS_IOC_GET_FEATURES:
2720 return f2fs_ioc_get_features(filp, arg);
2721 case F2FS_IOC_FSGETXATTR:
2722 return f2fs_ioc_fsgetxattr(filp, arg);
2723 case F2FS_IOC_FSSETXATTR:
2724 return f2fs_ioc_fssetxattr(filp, arg);
2752long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2753{
2754 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
2755 return -EIO;
2756
2757 switch (cmd) {
2758 case F2FS_IOC_GETFLAGS:
2759 return f2fs_ioc_getflags(filp, arg);

--- 34 unchanged lines hidden (view full) ---

2794 case F2FS_IOC_FLUSH_DEVICE:
2795 return f2fs_ioc_flush_device(filp, arg);
2796 case F2FS_IOC_GET_FEATURES:
2797 return f2fs_ioc_get_features(filp, arg);
2798 case F2FS_IOC_FSGETXATTR:
2799 return f2fs_ioc_fsgetxattr(filp, arg);
2800 case F2FS_IOC_FSSETXATTR:
2801 return f2fs_ioc_fssetxattr(filp, arg);
2802 case F2FS_IOC_GET_PIN_FILE:
2803 return f2fs_ioc_get_pin_file(filp, arg);
2804 case F2FS_IOC_SET_PIN_FILE:
2805 return f2fs_ioc_set_pin_file(filp, arg);
2725 default:
2726 return -ENOTTY;
2727 }
2728}
2729
2730static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
2731{
2732 struct file *file = iocb->ki_filp;

--- 59 unchanged lines hidden (view full) ---

2792 case F2FS_IOC_GARBAGE_COLLECT_RANGE:
2793 case F2FS_IOC_WRITE_CHECKPOINT:
2794 case F2FS_IOC_DEFRAGMENT:
2795 case F2FS_IOC_MOVE_RANGE:
2796 case F2FS_IOC_FLUSH_DEVICE:
2797 case F2FS_IOC_GET_FEATURES:
2798 case F2FS_IOC_FSGETXATTR:
2799 case F2FS_IOC_FSSETXATTR:
2806 default:
2807 return -ENOTTY;
2808 }
2809}
2810
2811static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
2812{
2813 struct file *file = iocb->ki_filp;

--- 59 unchanged lines hidden (view full) ---

2873 case F2FS_IOC_GARBAGE_COLLECT_RANGE:
2874 case F2FS_IOC_WRITE_CHECKPOINT:
2875 case F2FS_IOC_DEFRAGMENT:
2876 case F2FS_IOC_MOVE_RANGE:
2877 case F2FS_IOC_FLUSH_DEVICE:
2878 case F2FS_IOC_GET_FEATURES:
2879 case F2FS_IOC_FSGETXATTR:
2880 case F2FS_IOC_FSSETXATTR:
2881 case F2FS_IOC_GET_PIN_FILE:
2882 case F2FS_IOC_SET_PIN_FILE:
2800 break;
2801 default:
2802 return -ENOIOCTLCMD;
2803 }
2804 return f2fs_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
2805}
2806#endif
2807

--- 17 unchanged lines hidden ---
2883 break;
2884 default:
2885 return -ENOIOCTLCMD;
2886 }
2887 return f2fs_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
2888}
2889#endif
2890

--- 17 unchanged lines hidden ---