xfs
[Top] [All Lists]

Re: Introduce SEEK_DATA/SEEK_HOLE to XFS V5

To: jeff.liu@xxxxxxxxxx
Subject: Re: Introduce SEEK_DATA/SEEK_HOLE to XFS V5
From: Mark Tinguely <tinguely@xxxxxxx>
Date: Wed, 11 Jan 2012 15:06:09 -0600
Cc: Ben Myers <bpm@xxxxxxx>, Christoph Hellwig <hch@xxxxxxxxxxxxx>, Chris Mason <chris.mason@xxxxxxxxxx>, xfs@xxxxxxxxxxx
In-reply-to: <4F0D21E5.7010908@xxxxxxxxxx>
References: <4F06F71A.2010301@xxxxxxxxxx> <20120110171855.GX6390@xxxxxxx> <4F0D21E5.7010908@xxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.24) Gecko/20111206 Thunderbird/3.1.16

Good work.  I know this is an important addition.

The test in the for loop of the xfs_seek_data() and xfs_seek_hole() routines,
are independent of each other except in order of them being called.

One could add a "continue" statement after computing the offset for the next
iteration of the loop.

This allows the addition of an error condition if no conditions are matched.


Rough patch relative to your patch of the idea.

--- fs/xfs/xfs_file.c.orig      2012-01-11 08:50:50.000000000 -0600
+++ fs/xfs/xfs_file.c   2012-01-11 09:12:47.000000000 -0600
@@ -1265,7 +1265,7 @@ xfs_seek_data(
        ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
        len = XFS_B_TO_FSB(mp, isize);

-       for (;;) {
+       do {
                struct xfs_bmbt_irec    map[2];
                int                     nmap = 2;
                loff_t                  seekoff;
@@ -1323,6 +1323,7 @@ xfs_seek_data(
                        }

                        fsbno = map[1].br_startoff + map[1].br_blockcount;
+                       continue;
                }

                /*
@@ -1366,6 +1367,7 @@ xfs_seek_data(
                        }

                        fsbno = map[1].br_startoff + map[1].br_blockcount;
+                       continue;
                }

                /* Landed in a delay allocated extent or a real data extent */
@@ -1376,11 +1378,14 @@ xfs_seek_data(
                        break;
                }

+               error = ENXIO;
+               goto out_lock;
+       } while (XFS_FSB_TO_B(mp, fsbno) < isize);
+
                /* Return ENXIO if beyond eof */
-               if (XFS_FSB_TO_B(mp, fsbno) > isize) {
-                       error = ENXIO;
-                       goto out_lock;
-               }
+        if (XFS_FSB_TO_B(mp, fsbno) > isize) {
+               error = ENXIO;
+               goto out_lock;
        }

        if (offset < start)
@@ -1424,7 +1429,7 @@ xfs_seek_hole(
        ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
        len = XFS_B_TO_FSB(mp, isize);

-       for (;;) {
+       do {
                struct xfs_bmbt_irec    map[2];
                int                     nmap = 2;
                loff_t                  seekoff;
@@ -1507,6 +1512,7 @@ xfs_seek_hole(
                        }

                        fsbno = map[1].br_startoff + map[1].br_blockcount;
+                       continue;
                }

                /*
@@ -1555,6 +1561,7 @@ xfs_seek_hole(
                        }

                        fsbno = map[1].br_startoff + map[1].br_blockcount;
+                       continue;
                }

                /* Landed in a hole, its fine to return */
@@ -1564,11 +1571,14 @@ xfs_seek_hole(
                        break;
                }

+               error = ENXIO;
+               goto out_lock;
+       } while (XFS_FSB_TO_B(mp, fsbno) < isize);
+
                /* Return ENXIO if beyond eof */
-               if (XFS_FSB_TO_B(mp, fsbno) > isize) {
-                       error = ENXIO;
-                       goto out_lock;
-               }
+       if (XFS_FSB_TO_B(mp, fsbno) > isize) {
+               error = ENXIO;
+               goto out_lock;
        }

        if (offset < start)


--Mark Tinguely

<Prev in Thread] Current Thread [Next in Thread>