]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - fs/xfs/xfs_file.c
Merge tag 'compiler-attributes-for-linus-v5.4' of git://github.com/ojeda/linux
[linux.git] / fs / xfs / xfs_file.c
index 28101bbc0b78fb814da4c1d5d345912db505a466..d952d5962e937a31ab13f2a9419350e15106d9f9 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/falloc.h>
 #include <linux/backing-dev.h>
 #include <linux/mman.h>
+#include <linux/fadvise.h>
 
 static const struct vm_operations_struct xfs_file_vm_ops;
 
@@ -933,6 +934,30 @@ xfs_file_fallocate(
        return error;
 }
 
+STATIC int
+xfs_file_fadvise(
+       struct file     *file,
+       loff_t          start,
+       loff_t          end,
+       int             advice)
+{
+       struct xfs_inode *ip = XFS_I(file_inode(file));
+       int ret;
+       int lockflags = 0;
+
+       /*
+        * Operations creating pages in page cache need protection from hole
+        * punching and similar ops
+        */
+       if (advice == POSIX_FADV_WILLNEED) {
+               lockflags = XFS_IOLOCK_SHARED;
+               xfs_ilock(ip, lockflags);
+       }
+       ret = generic_fadvise(file, start, end, advice);
+       if (lockflags)
+               xfs_iunlock(ip, lockflags);
+       return ret;
+}
 
 STATIC loff_t
 xfs_file_remap_range(
@@ -1232,6 +1257,7 @@ const struct file_operations xfs_file_operations = {
        .fsync          = xfs_file_fsync,
        .get_unmapped_area = thp_get_unmapped_area,
        .fallocate      = xfs_file_fallocate,
+       .fadvise        = xfs_file_fadvise,
        .remap_file_range = xfs_file_remap_range,
 };