Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: ibmveth: Refactored veth_pool_store for better maintainability

Make veth_pool_store detect requested pool changes, close device if
necessary, update pool, and reopen device.

Signed-off-by: Dave Marquardt <davemarq@linux.ibm.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/20250506160004.328347-1-davemarq@linux.ibm.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Dave Marquardt and committed by
Jakub Kicinski
46431fd5 0a055ec0

+67 -44
+67 -44
drivers/net/ethernet/ibm/ibmveth.c
··· 1871 1871 return 0; 1872 1872 } 1873 1873 1874 + /** 1875 + * veth_pool_store - sysfs store handler for pool attributes 1876 + * @kobj: kobject embedded in pool 1877 + * @attr: attribute being changed 1878 + * @buf: value being stored 1879 + * @count: length of @buf in bytes 1880 + * 1881 + * Stores new value in pool attribute. Verifies the range of the new value for 1882 + * size and buff_size. Verifies that at least one pool remains available to 1883 + * receive MTU-sized packets. 1884 + * 1885 + * Context: Process context. 1886 + * Takes and releases rtnl_mutex to ensure correct ordering of close 1887 + * and open calls. 1888 + * Return: 1889 + * * %-EPERM - Not allowed to disabled all MTU-sized buffer pools 1890 + * * %-EINVAL - New pool size or buffer size is out of range 1891 + * * count - Return count for success 1892 + * * other - Return value from a failed ibmveth_open call 1893 + */ 1874 1894 static ssize_t veth_pool_store(struct kobject *kobj, struct attribute *attr, 1875 1895 const char *buf, size_t count) 1876 1896 { ··· 1900 1880 struct net_device *netdev = dev_get_drvdata(kobj_to_dev(kobj->parent)); 1901 1881 struct ibmveth_adapter *adapter = netdev_priv(netdev); 1902 1882 long value = simple_strtol(buf, NULL, 10); 1883 + bool change = false; 1884 + u32 newbuff_size; 1885 + u32 oldbuff_size; 1886 + int newactive; 1887 + int oldactive; 1888 + u32 newsize; 1889 + u32 oldsize; 1903 1890 long rc; 1904 1891 1905 1892 rtnl_lock(); 1906 1893 1894 + oldbuff_size = pool->buff_size; 1895 + oldactive = pool->active; 1896 + oldsize = pool->size; 1897 + 1898 + newbuff_size = oldbuff_size; 1899 + newactive = oldactive; 1900 + newsize = oldsize; 1901 + 1907 1902 if (attr == &veth_active_attr) { 1908 - if (value && !pool->active) { 1909 - if (netif_running(netdev)) { 1910 - if (ibmveth_alloc_buffer_pool(pool)) { 1911 - netdev_err(netdev, 1912 - "unable to alloc pool\n"); 1913 - rc = -ENOMEM; 1914 - goto unlock_err; 1915 - } 1916 - pool->active = 1; 1917 - ibmveth_close(netdev); 1918 - rc = ibmveth_open(netdev); 1919 - if (rc) 1920 - goto unlock_err; 1921 - } else { 1922 - pool->active = 1; 1923 - } 1924 - } else if (!value && pool->active) { 1903 + if (value && !oldactive) { 1904 + newactive = 1; 1905 + change = true; 1906 + } else if (!value && oldactive) { 1925 1907 int mtu = netdev->mtu + IBMVETH_BUFF_OH; 1926 1908 int i; 1927 1909 /* Make sure there is a buffer pool with buffers that ··· 1943 1921 goto unlock_err; 1944 1922 } 1945 1923 1946 - if (netif_running(netdev)) { 1947 - ibmveth_close(netdev); 1948 - pool->active = 0; 1949 - rc = ibmveth_open(netdev); 1950 - if (rc) 1951 - goto unlock_err; 1952 - } 1953 - pool->active = 0; 1924 + newactive = 0; 1925 + change = true; 1954 1926 } 1955 1927 } else if (attr == &veth_num_attr) { 1956 1928 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT) { 1957 1929 rc = -EINVAL; 1958 1930 goto unlock_err; 1959 - } else { 1960 - if (netif_running(netdev)) { 1961 - ibmveth_close(netdev); 1962 - pool->size = value; 1963 - rc = ibmveth_open(netdev); 1964 - if (rc) 1965 - goto unlock_err; 1966 - } else { 1967 - pool->size = value; 1968 - } 1931 + } 1932 + if (value != oldsize) { 1933 + newsize = value; 1934 + change = true; 1969 1935 } 1970 1936 } else if (attr == &veth_size_attr) { 1971 1937 if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE) { 1972 1938 rc = -EINVAL; 1973 1939 goto unlock_err; 1974 - } else { 1975 - if (netif_running(netdev)) { 1976 - ibmveth_close(netdev); 1977 - pool->buff_size = value; 1978 - rc = ibmveth_open(netdev); 1979 - if (rc) 1980 - goto unlock_err; 1981 - } else { 1982 - pool->buff_size = value; 1940 + } 1941 + if (value != oldbuff_size) { 1942 + newbuff_size = value; 1943 + change = true; 1944 + } 1945 + } 1946 + 1947 + if (change) { 1948 + if (netif_running(netdev)) 1949 + ibmveth_close(netdev); 1950 + 1951 + pool->active = newactive; 1952 + pool->buff_size = newbuff_size; 1953 + pool->size = newsize; 1954 + 1955 + if (netif_running(netdev)) { 1956 + rc = ibmveth_open(netdev); 1957 + if (rc) { 1958 + pool->active = oldactive; 1959 + pool->buff_size = oldbuff_size; 1960 + pool->size = oldsize; 1961 + goto unlock_err; 1983 1962 } 1984 1963 } 1985 1964 }