diff options
Diffstat (limited to 'fs/nfs/flexfilelayout/flexfilelayout.c')
-rw-r--r-- | fs/nfs/flexfilelayout/flexfilelayout.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 4215278c9c76..cd999af504d9 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include "../nfs4trace.h" | 20 | #include "../nfs4trace.h" |
21 | #include "../iostat.h" | 21 | #include "../iostat.h" |
22 | #include "../nfs.h" | 22 | #include "../nfs.h" |
23 | #include "../nfs42.h" | ||
23 | 24 | ||
24 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD | 25 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD |
25 | 26 | ||
@@ -1659,6 +1660,75 @@ out: | |||
1659 | dprintk("%s: Return\n", __func__); | 1660 | dprintk("%s: Return\n", __func__); |
1660 | } | 1661 | } |
1661 | 1662 | ||
1663 | static bool | ||
1664 | ff_layout_mirror_prepare_stats(struct nfs42_layoutstat_args *args, | ||
1665 | struct pnfs_layout_segment *pls, | ||
1666 | int *dev_count, int dev_limit) | ||
1667 | { | ||
1668 | struct nfs4_ff_layout_mirror *mirror; | ||
1669 | struct nfs4_deviceid_node *dev; | ||
1670 | struct nfs42_layoutstat_devinfo *devinfo; | ||
1671 | int i; | ||
1672 | |||
1673 | for (i = 0; i <= FF_LAYOUT_MIRROR_COUNT(pls); i++) { | ||
1674 | if (*dev_count >= dev_limit) | ||
1675 | break; | ||
1676 | mirror = FF_LAYOUT_COMP(pls, i); | ||
1677 | dev = FF_LAYOUT_DEVID_NODE(pls, i); | ||
1678 | devinfo = &args->devinfo[*dev_count]; | ||
1679 | memcpy(&devinfo->dev_id, &dev->deviceid, NFS4_DEVICEID4_SIZE); | ||
1680 | devinfo->offset = pls->pls_range.offset; | ||
1681 | devinfo->length = pls->pls_range.length; | ||
1682 | /* well, we don't really know if IO is continuous or not! */ | ||
1683 | devinfo->read_count = mirror->read_stat.io_stat.bytes_completed; | ||
1684 | devinfo->read_bytes = mirror->read_stat.io_stat.bytes_completed; | ||
1685 | devinfo->write_count = mirror->write_stat.io_stat.bytes_completed; | ||
1686 | devinfo->write_bytes = mirror->write_stat.io_stat.bytes_completed; | ||
1687 | devinfo->layout_type = LAYOUT_FLEX_FILES; | ||
1688 | devinfo->layoutstats_encode = NULL; | ||
1689 | devinfo->layout_private = NULL; | ||
1690 | |||
1691 | ++(*dev_count); | ||
1692 | } | ||
1693 | |||
1694 | return *dev_count < dev_limit; | ||
1695 | } | ||
1696 | |||
1697 | static int | ||
1698 | ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args) | ||
1699 | { | ||
1700 | struct pnfs_layout_segment *pls; | ||
1701 | int dev_count = 0; | ||
1702 | |||
1703 | spin_lock(&args->inode->i_lock); | ||
1704 | list_for_each_entry(pls, &NFS_I(args->inode)->layout->plh_segs, pls_list) { | ||
1705 | dev_count += FF_LAYOUT_MIRROR_COUNT(pls); | ||
1706 | } | ||
1707 | spin_unlock(&args->inode->i_lock); | ||
1708 | /* For now, send at most PNFS_LAYOUTSTATS_MAXDEV statistics */ | ||
1709 | if (dev_count > PNFS_LAYOUTSTATS_MAXDEV) { | ||
1710 | dprintk("%s: truncating devinfo to limit (%d:%d)\n", | ||
1711 | __func__, dev_count, PNFS_LAYOUTSTATS_MAXDEV); | ||
1712 | dev_count = PNFS_LAYOUTSTATS_MAXDEV; | ||
1713 | } | ||
1714 | args->devinfo = kmalloc(dev_count * sizeof(*args->devinfo), GFP_KERNEL); | ||
1715 | if (!args->devinfo) | ||
1716 | return -ENOMEM; | ||
1717 | |||
1718 | dev_count = 0; | ||
1719 | spin_lock(&args->inode->i_lock); | ||
1720 | list_for_each_entry(pls, &NFS_I(args->inode)->layout->plh_segs, pls_list) { | ||
1721 | if (!ff_layout_mirror_prepare_stats(args, pls, &dev_count, | ||
1722 | PNFS_LAYOUTSTATS_MAXDEV)) { | ||
1723 | break; | ||
1724 | } | ||
1725 | } | ||
1726 | spin_unlock(&args->inode->i_lock); | ||
1727 | args->num_dev = dev_count; | ||
1728 | |||
1729 | return 0; | ||
1730 | } | ||
1731 | |||
1662 | static struct pnfs_layoutdriver_type flexfilelayout_type = { | 1732 | static struct pnfs_layoutdriver_type flexfilelayout_type = { |
1663 | .id = LAYOUT_FLEX_FILES, | 1733 | .id = LAYOUT_FLEX_FILES, |
1664 | .name = "LAYOUT_FLEX_FILES", | 1734 | .name = "LAYOUT_FLEX_FILES", |
@@ -1681,6 +1751,7 @@ static struct pnfs_layoutdriver_type flexfilelayout_type = { | |||
1681 | .alloc_deviceid_node = ff_layout_alloc_deviceid_node, | 1751 | .alloc_deviceid_node = ff_layout_alloc_deviceid_node, |
1682 | .encode_layoutreturn = ff_layout_encode_layoutreturn, | 1752 | .encode_layoutreturn = ff_layout_encode_layoutreturn, |
1683 | .sync = pnfs_nfs_generic_sync, | 1753 | .sync = pnfs_nfs_generic_sync, |
1754 | .prepare_layoutstats = ff_layout_prepare_layoutstats, | ||
1684 | }; | 1755 | }; |
1685 | 1756 | ||
1686 | static int __init nfs4flexfilelayout_init(void) | 1757 | static int __init nfs4flexfilelayout_init(void) |