[pnfs] [PATCH 29/37] pnfs: client layout cache: insert_layout infrastructure
Benny Halevy
bhalevy at panasas.com
Tue Jan 1 05:51:40 EST 2008
Signed-off-by: Benny Halevy <bhalevy at panasas.com>
---
fs/nfs/pnfs.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 55ec489..116383d 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -532,6 +532,64 @@ out:
return status;
}
+/*
+ * cmp two layout segments for sorting into layout cache
+ */
+static inline s64
+cmp_layout(struct nfs4_pnfs_layout_segment *l1,
+ struct nfs4_pnfs_layout_segment *l2)
+{
+ s64 d;
+
+ /* lower offset < higher offset */
+ d = l1->offset - l2->offset;
+ if (d)
+ return d;
+
+ /* read < read/write */
+ d = (l1->iomode == IOMODE_RW) - (l2->iomode == IOMODE_RW);
+ if (d)
+ return d;
+
+ /* longer length < shorter length */
+ return l2->length - l1->length;
+}
+
+static void
+pnfs_insert_layout(struct pnfs_layout_type *lo,
+ struct pnfs_layout_segment *lseg)
+{
+ struct pnfs_layout_segment *lp;
+ int found = 0;
+
+ dprintk("%s:Begin\n", __FUNCTION__);
+
+ BUG_ON_UNLOCKED_LO(lo);
+ list_for_each_entry (lp, &lo->segs, fi_list) {
+ if (cmp_layout(&lp->range, &lseg->range) > 0)
+ continue;
+ list_add_tail(&lseg->fi_list, &lp->fi_list);
+ dprintk("%s: inserted lseg %p "
+ "iomode %d offset %llu length %llu before "
+ "lp %p iomode %d offset %llu length %llu\n",
+ __FUNCTION__, lseg, lseg->range.iomode,
+ lseg->range.offset, lseg->range.length,
+ lp, lp->range.iomode, lp->range.offset,
+ lp->range.length);
+ found = 1;
+ break;
+ }
+ if (!found) {
+ list_add_tail(&lseg->fi_list, &lo->segs);
+ dprintk("%s: inserted lseg %p "
+ "iomode %d offset %llu length %llu at tail\n",
+ __FUNCTION__, lseg, lseg->range.iomode,
+ lseg->range.offset, lseg->range.length);
+ }
+
+ dprintk("%s:Return\n", __FUNCTION__);
+}
+
/* DH: Inject layout blob into the I/O module. This must happen before
* the I/O module has its read/write methods called.
*/
--
1.5.3.3
More information about the pNFS
mailing list