diff options
author | Rob Landley <rlandley@parallels.com> | 2011-03-09 16:54:13 -0500 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2011-03-11 15:39:28 -0500 |
commit | c12bacec458bef16d843c052f38422862f3da8fe (patch) | |
tree | 6a65f6ecbe0868aba14fb95f033a532b21fa64ba /fs/nfs/super.c | |
parent | 7ec10f26e1fd5fcceb9c96e508c1292a816199f7 (diff) |
cleanup: save 60 lines/100 bytes by combining two mostly duplicate functions.
Eliminate two mostly duplicate functions (nfs_parse_simple_hostname()
and nfs_parse_protected_hostname()) and instead just make the calling
function (nfs_parse_devname()) do everything.
Signed-off-by: Rob Landley <rlandley@parallels.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/super.c')
-rw-r--r-- | fs/nfs/super.c | 129 |
1 files changed, 33 insertions, 96 deletions
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index b68c8607770f..a74e9740190f 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -1665,99 +1665,59 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args, | |||
1665 | return nfs_walk_authlist(args, &request); | 1665 | return nfs_walk_authlist(args, &request); |
1666 | } | 1666 | } |
1667 | 1667 | ||
1668 | static int nfs_parse_simple_hostname(const char *dev_name, | 1668 | /* |
1669 | char **hostname, size_t maxnamlen, | 1669 | * Split "dev_name" into "hostname:export_path". |
1670 | char **export_path, size_t maxpathlen) | 1670 | * |
1671 | * The leftmost colon demarks the split between the server's hostname | ||
1672 | * and the export path. If the hostname starts with a left square | ||
1673 | * bracket, then it may contain colons. | ||
1674 | * | ||
1675 | * Note: caller frees hostname and export path, even on error. | ||
1676 | */ | ||
1677 | static int nfs_parse_devname(const char *dev_name, | ||
1678 | char **hostname, size_t maxnamlen, | ||
1679 | char **export_path, size_t maxpathlen) | ||
1671 | { | 1680 | { |
1672 | size_t len; | 1681 | size_t len; |
1673 | char *colon, *comma; | 1682 | char *end; |
1674 | |||
1675 | colon = strchr(dev_name, ':'); | ||
1676 | if (colon == NULL) | ||
1677 | goto out_bad_devname; | ||
1678 | |||
1679 | len = colon - dev_name; | ||
1680 | if (len > maxnamlen) | ||
1681 | goto out_hostname; | ||
1682 | |||
1683 | /* N.B. caller will free nfs_server.hostname in all cases */ | ||
1684 | *hostname = kstrndup(dev_name, len, GFP_KERNEL); | ||
1685 | if (!*hostname) | ||
1686 | goto out_nomem; | ||
1687 | 1683 | ||
1688 | /* kill possible hostname list: not supported */ | 1684 | /* Is the host name protected with square brakcets? */ |
1689 | comma = strchr(*hostname, ','); | 1685 | if (*dev_name == '[') { |
1690 | if (comma != NULL) { | 1686 | end = strchr(++dev_name, ']'); |
1691 | if (comma == *hostname) | 1687 | if (end == NULL || end[1] != ':') |
1692 | goto out_bad_devname; | 1688 | goto out_bad_devname; |
1693 | *comma = '\0'; | ||
1694 | } | ||
1695 | |||
1696 | colon++; | ||
1697 | len = strlen(colon); | ||
1698 | if (len > maxpathlen) | ||
1699 | goto out_path; | ||
1700 | *export_path = kstrndup(colon, len, GFP_KERNEL); | ||
1701 | if (!*export_path) | ||
1702 | goto out_nomem; | ||
1703 | |||
1704 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path); | ||
1705 | return 0; | ||
1706 | 1689 | ||
1707 | out_bad_devname: | 1690 | len = end - dev_name; |
1708 | dfprintk(MOUNT, "NFS: device name not in host:path format\n"); | 1691 | end++; |
1709 | return -EINVAL; | 1692 | } else { |
1710 | 1693 | char *comma; | |
1711 | out_nomem: | ||
1712 | dfprintk(MOUNT, "NFS: not enough memory to parse device name\n"); | ||
1713 | return -ENOMEM; | ||
1714 | |||
1715 | out_hostname: | ||
1716 | dfprintk(MOUNT, "NFS: server hostname too long\n"); | ||
1717 | return -ENAMETOOLONG; | ||
1718 | |||
1719 | out_path: | ||
1720 | dfprintk(MOUNT, "NFS: export pathname too long\n"); | ||
1721 | return -ENAMETOOLONG; | ||
1722 | } | ||
1723 | |||
1724 | /* | ||
1725 | * Hostname has square brackets around it because it contains one or | ||
1726 | * more colons. We look for the first closing square bracket, and a | ||
1727 | * colon must follow it. | ||
1728 | */ | ||
1729 | static int nfs_parse_protected_hostname(const char *dev_name, | ||
1730 | char **hostname, size_t maxnamlen, | ||
1731 | char **export_path, size_t maxpathlen) | ||
1732 | { | ||
1733 | size_t len; | ||
1734 | char *start, *end; | ||
1735 | 1694 | ||
1736 | start = (char *)(dev_name + 1); | 1695 | end = strchr(dev_name, ':'); |
1696 | if (end == NULL) | ||
1697 | goto out_bad_devname; | ||
1698 | len = end - dev_name; | ||
1737 | 1699 | ||
1738 | end = strchr(start, ']'); | 1700 | /* kill possible hostname list: not supported */ |
1739 | if (end == NULL) | 1701 | comma = strchr(dev_name, ','); |
1740 | goto out_bad_devname; | 1702 | if (comma != NULL && comma < end) |
1741 | if (*(end + 1) != ':') | 1703 | *comma = 0; |
1742 | goto out_bad_devname; | 1704 | } |
1743 | 1705 | ||
1744 | len = end - start; | ||
1745 | if (len > maxnamlen) | 1706 | if (len > maxnamlen) |
1746 | goto out_hostname; | 1707 | goto out_hostname; |
1747 | 1708 | ||
1748 | /* N.B. caller will free nfs_server.hostname in all cases */ | 1709 | /* N.B. caller will free nfs_server.hostname in all cases */ |
1749 | *hostname = kstrndup(start, len, GFP_KERNEL); | 1710 | *hostname = kstrndup(dev_name, len, GFP_KERNEL); |
1750 | if (*hostname == NULL) | 1711 | if (*hostname == NULL) |
1751 | goto out_nomem; | 1712 | goto out_nomem; |
1752 | 1713 | len = strlen(++end); | |
1753 | end += 2; | ||
1754 | len = strlen(end); | ||
1755 | if (len > maxpathlen) | 1714 | if (len > maxpathlen) |
1756 | goto out_path; | 1715 | goto out_path; |
1757 | *export_path = kstrndup(end, len, GFP_KERNEL); | 1716 | *export_path = kstrndup(end, len, GFP_KERNEL); |
1758 | if (!*export_path) | 1717 | if (!*export_path) |
1759 | goto out_nomem; | 1718 | goto out_nomem; |
1760 | 1719 | ||
1720 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path); | ||
1761 | return 0; | 1721 | return 0; |
1762 | 1722 | ||
1763 | out_bad_devname: | 1723 | out_bad_devname: |
@@ -1778,29 +1738,6 @@ out_path: | |||
1778 | } | 1738 | } |
1779 | 1739 | ||
1780 | /* | 1740 | /* |
1781 | * Split "dev_name" into "hostname:export_path". | ||
1782 | * | ||
1783 | * The leftmost colon demarks the split between the server's hostname | ||
1784 | * and the export path. If the hostname starts with a left square | ||
1785 | * bracket, then it may contain colons. | ||
1786 | * | ||
1787 | * Note: caller frees hostname and export path, even on error. | ||
1788 | */ | ||
1789 | static int nfs_parse_devname(const char *dev_name, | ||
1790 | char **hostname, size_t maxnamlen, | ||
1791 | char **export_path, size_t maxpathlen) | ||
1792 | { | ||
1793 | if (*dev_name == '[') | ||
1794 | return nfs_parse_protected_hostname(dev_name, | ||
1795 | hostname, maxnamlen, | ||
1796 | export_path, maxpathlen); | ||
1797 | |||
1798 | return nfs_parse_simple_hostname(dev_name, | ||
1799 | hostname, maxnamlen, | ||
1800 | export_path, maxpathlen); | ||
1801 | } | ||
1802 | |||
1803 | /* | ||
1804 | * Validate the NFS2/NFS3 mount data | 1741 | * Validate the NFS2/NFS3 mount data |
1805 | * - fills in the mount root filehandle | 1742 | * - fills in the mount root filehandle |
1806 | * | 1743 | * |