heartbeat.c (985f2c87a7109a42cac93f56ea595353d53a1746) | heartbeat.c (45b997737a8025be2825e464e9e9dd5d07160dc3) |
---|---|
1/* -*- mode: c; c-basic-offset: 8; -*- 2 * vim: noexpandtab sw=8 ts=8 sts=0: 3 * 4 * Copyright (C) 2004, 2005 Oracle. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public 8 * License as published by the Free Software Foundation; either --- 1459 unchanged lines hidden (view full) --- 1468 if (ret_bytes) 1469 *ret_bytes = bytes; 1470 if (ret_bits) 1471 *ret_bits = ffs(bytes) - 1; 1472 1473 return 0; 1474} 1475 | 1/* -*- mode: c; c-basic-offset: 8; -*- 2 * vim: noexpandtab sw=8 ts=8 sts=0: 3 * 4 * Copyright (C) 2004, 2005 Oracle. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public 8 * License as published by the Free Software Foundation; either --- 1459 unchanged lines hidden (view full) --- 1468 if (ret_bytes) 1469 *ret_bytes = bytes; 1470 if (ret_bits) 1471 *ret_bits = ffs(bytes) - 1; 1472 1473 return 0; 1474} 1475 |
1476static ssize_t o2hb_region_block_bytes_read(struct o2hb_region *reg, | 1476static ssize_t o2hb_region_block_bytes_show(struct config_item *item, |
1477 char *page) 1478{ | 1477 char *page) 1478{ |
1479 return sprintf(page, "%u\n", reg->hr_block_bytes); | 1479 return sprintf(page, "%u\n", to_o2hb_region(item)->hr_block_bytes); |
1480} 1481 | 1480} 1481 |
1482static ssize_t o2hb_region_block_bytes_write(struct o2hb_region *reg, | 1482static ssize_t o2hb_region_block_bytes_store(struct config_item *item, |
1483 const char *page, 1484 size_t count) 1485{ | 1483 const char *page, 1484 size_t count) 1485{ |
1486 struct o2hb_region *reg = to_o2hb_region(item); |
|
1486 int status; 1487 unsigned long block_bytes; 1488 unsigned int block_bits; 1489 1490 if (reg->hr_bdev) 1491 return -EINVAL; 1492 1493 status = o2hb_read_block_input(reg, page, count, 1494 &block_bytes, &block_bits); 1495 if (status) 1496 return status; 1497 1498 reg->hr_block_bytes = (unsigned int)block_bytes; 1499 reg->hr_block_bits = block_bits; 1500 1501 return count; 1502} 1503 | 1487 int status; 1488 unsigned long block_bytes; 1489 unsigned int block_bits; 1490 1491 if (reg->hr_bdev) 1492 return -EINVAL; 1493 1494 status = o2hb_read_block_input(reg, page, count, 1495 &block_bytes, &block_bits); 1496 if (status) 1497 return status; 1498 1499 reg->hr_block_bytes = (unsigned int)block_bytes; 1500 reg->hr_block_bits = block_bits; 1501 1502 return count; 1503} 1504 |
1504static ssize_t o2hb_region_start_block_read(struct o2hb_region *reg, | 1505static ssize_t o2hb_region_start_block_show(struct config_item *item, |
1505 char *page) 1506{ | 1506 char *page) 1507{ |
1507 return sprintf(page, "%llu\n", reg->hr_start_block); | 1508 return sprintf(page, "%llu\n", to_o2hb_region(item)->hr_start_block); |
1508} 1509 | 1509} 1510 |
1510static ssize_t o2hb_region_start_block_write(struct o2hb_region *reg, | 1511static ssize_t o2hb_region_start_block_store(struct config_item *item, |
1511 const char *page, 1512 size_t count) 1513{ | 1512 const char *page, 1513 size_t count) 1514{ |
1515 struct o2hb_region *reg = to_o2hb_region(item); |
|
1514 unsigned long long tmp; 1515 char *p = (char *)page; 1516 1517 if (reg->hr_bdev) 1518 return -EINVAL; 1519 1520 tmp = simple_strtoull(p, &p, 0); 1521 if (!p || (*p && (*p != '\n'))) 1522 return -EINVAL; 1523 1524 reg->hr_start_block = tmp; 1525 1526 return count; 1527} 1528 | 1516 unsigned long long tmp; 1517 char *p = (char *)page; 1518 1519 if (reg->hr_bdev) 1520 return -EINVAL; 1521 1522 tmp = simple_strtoull(p, &p, 0); 1523 if (!p || (*p && (*p != '\n'))) 1524 return -EINVAL; 1525 1526 reg->hr_start_block = tmp; 1527 1528 return count; 1529} 1530 |
1529static ssize_t o2hb_region_blocks_read(struct o2hb_region *reg, 1530 char *page) | 1531static ssize_t o2hb_region_blocks_show(struct config_item *item, char *page) |
1531{ | 1532{ |
1532 return sprintf(page, "%d\n", reg->hr_blocks); | 1533 return sprintf(page, "%d\n", to_o2hb_region(item)->hr_blocks); |
1533} 1534 | 1534} 1535 |
1535static ssize_t o2hb_region_blocks_write(struct o2hb_region *reg, | 1536static ssize_t o2hb_region_blocks_store(struct config_item *item, |
1536 const char *page, 1537 size_t count) 1538{ | 1537 const char *page, 1538 size_t count) 1539{ |
1540 struct o2hb_region *reg = to_o2hb_region(item); |
|
1539 unsigned long tmp; 1540 char *p = (char *)page; 1541 1542 if (reg->hr_bdev) 1543 return -EINVAL; 1544 1545 tmp = simple_strtoul(p, &p, 0); 1546 if (!p || (*p && (*p != '\n'))) 1547 return -EINVAL; 1548 1549 if (tmp > O2NM_MAX_NODES || tmp == 0) 1550 return -ERANGE; 1551 1552 reg->hr_blocks = (unsigned int)tmp; 1553 1554 return count; 1555} 1556 | 1541 unsigned long tmp; 1542 char *p = (char *)page; 1543 1544 if (reg->hr_bdev) 1545 return -EINVAL; 1546 1547 tmp = simple_strtoul(p, &p, 0); 1548 if (!p || (*p && (*p != '\n'))) 1549 return -EINVAL; 1550 1551 if (tmp > O2NM_MAX_NODES || tmp == 0) 1552 return -ERANGE; 1553 1554 reg->hr_blocks = (unsigned int)tmp; 1555 1556 return count; 1557} 1558 |
1557static ssize_t o2hb_region_dev_read(struct o2hb_region *reg, 1558 char *page) | 1559static ssize_t o2hb_region_dev_show(struct config_item *item, char *page) |
1559{ 1560 unsigned int ret = 0; 1561 | 1560{ 1561 unsigned int ret = 0; 1562 |
1562 if (reg->hr_bdev) 1563 ret = sprintf(page, "%s\n", reg->hr_dev_name); | 1563 if (to_o2hb_region(item)->hr_bdev) 1564 ret = sprintf(page, "%s\n", to_o2hb_region(item)->hr_dev_name); |
1564 1565 return ret; 1566} 1567 1568static void o2hb_init_region_params(struct o2hb_region *reg) 1569{ 1570 reg->hr_slots_per_page = PAGE_CACHE_SIZE >> reg->hr_block_bits; 1571 reg->hr_timeout_ms = O2HB_REGION_TIMEOUT_MS; --- 93 unchanged lines hidden (view full) --- 1665 slot->ds_last_generation = le64_to_cpu(hb_block->hb_generation); 1666 } 1667 1668out: 1669 return ret; 1670} 1671 1672/* this is acting as commit; we set up all of hr_bdev and hr_task or nothing */ | 1565 1566 return ret; 1567} 1568 1569static void o2hb_init_region_params(struct o2hb_region *reg) 1570{ 1571 reg->hr_slots_per_page = PAGE_CACHE_SIZE >> reg->hr_block_bits; 1572 reg->hr_timeout_ms = O2HB_REGION_TIMEOUT_MS; --- 93 unchanged lines hidden (view full) --- 1666 slot->ds_last_generation = le64_to_cpu(hb_block->hb_generation); 1667 } 1668 1669out: 1670 return ret; 1671} 1672 1673/* this is acting as commit; we set up all of hr_bdev and hr_task or nothing */ |
1673static ssize_t o2hb_region_dev_write(struct o2hb_region *reg, | 1674static ssize_t o2hb_region_dev_store(struct config_item *item, |
1674 const char *page, 1675 size_t count) 1676{ | 1675 const char *page, 1676 size_t count) 1677{ |
1678 struct o2hb_region *reg = to_o2hb_region(item); |
|
1677 struct task_struct *hb_task; 1678 long fd; 1679 int sectsize; 1680 char *p = (char *)page; 1681 struct fd f; 1682 struct inode *inode; 1683 ssize_t ret = -EINVAL; 1684 int live_threshold; --- 138 unchanged lines hidden (view full) --- 1823 if (reg->hr_bdev) { 1824 blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE); 1825 reg->hr_bdev = NULL; 1826 } 1827 } 1828 return ret; 1829} 1830 | 1679 struct task_struct *hb_task; 1680 long fd; 1681 int sectsize; 1682 char *p = (char *)page; 1683 struct fd f; 1684 struct inode *inode; 1685 ssize_t ret = -EINVAL; 1686 int live_threshold; --- 138 unchanged lines hidden (view full) --- 1825 if (reg->hr_bdev) { 1826 blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE); 1827 reg->hr_bdev = NULL; 1828 } 1829 } 1830 return ret; 1831} 1832 |
1831static ssize_t o2hb_region_pid_read(struct o2hb_region *reg, 1832 char *page) | 1833static ssize_t o2hb_region_pid_show(struct config_item *item, char *page) |
1833{ | 1834{ |
1835 struct o2hb_region *reg = to_o2hb_region(item); |
|
1834 pid_t pid = 0; 1835 1836 spin_lock(&o2hb_live_lock); 1837 if (reg->hr_task) 1838 pid = task_pid_nr(reg->hr_task); 1839 spin_unlock(&o2hb_live_lock); 1840 1841 if (!pid) 1842 return 0; 1843 1844 return sprintf(page, "%u\n", pid); 1845} 1846 | 1836 pid_t pid = 0; 1837 1838 spin_lock(&o2hb_live_lock); 1839 if (reg->hr_task) 1840 pid = task_pid_nr(reg->hr_task); 1841 spin_unlock(&o2hb_live_lock); 1842 1843 if (!pid) 1844 return 0; 1845 1846 return sprintf(page, "%u\n", pid); 1847} 1848 |
1847struct o2hb_region_attribute { 1848 struct configfs_attribute attr; 1849 ssize_t (*show)(struct o2hb_region *, char *); 1850 ssize_t (*store)(struct o2hb_region *, const char *, size_t); 1851}; | 1849CONFIGFS_ATTR(o2hb_region_, block_bytes); 1850CONFIGFS_ATTR(o2hb_region_, start_block); 1851CONFIGFS_ATTR(o2hb_region_, blocks); 1852CONFIGFS_ATTR(o2hb_region_, dev); 1853CONFIGFS_ATTR_RO(o2hb_region_, pid); |
1852 | 1854 |
1853static struct o2hb_region_attribute o2hb_region_attr_block_bytes = { 1854 .attr = { .ca_owner = THIS_MODULE, 1855 .ca_name = "block_bytes", 1856 .ca_mode = S_IRUGO | S_IWUSR }, 1857 .show = o2hb_region_block_bytes_read, 1858 .store = o2hb_region_block_bytes_write, 1859}; 1860 1861static struct o2hb_region_attribute o2hb_region_attr_start_block = { 1862 .attr = { .ca_owner = THIS_MODULE, 1863 .ca_name = "start_block", 1864 .ca_mode = S_IRUGO | S_IWUSR }, 1865 .show = o2hb_region_start_block_read, 1866 .store = o2hb_region_start_block_write, 1867}; 1868 1869static struct o2hb_region_attribute o2hb_region_attr_blocks = { 1870 .attr = { .ca_owner = THIS_MODULE, 1871 .ca_name = "blocks", 1872 .ca_mode = S_IRUGO | S_IWUSR }, 1873 .show = o2hb_region_blocks_read, 1874 .store = o2hb_region_blocks_write, 1875}; 1876 1877static struct o2hb_region_attribute o2hb_region_attr_dev = { 1878 .attr = { .ca_owner = THIS_MODULE, 1879 .ca_name = "dev", 1880 .ca_mode = S_IRUGO | S_IWUSR }, 1881 .show = o2hb_region_dev_read, 1882 .store = o2hb_region_dev_write, 1883}; 1884 1885static struct o2hb_region_attribute o2hb_region_attr_pid = { 1886 .attr = { .ca_owner = THIS_MODULE, 1887 .ca_name = "pid", 1888 .ca_mode = S_IRUGO | S_IRUSR }, 1889 .show = o2hb_region_pid_read, 1890}; 1891 | |
1892static struct configfs_attribute *o2hb_region_attrs[] = { | 1855static struct configfs_attribute *o2hb_region_attrs[] = { |
1893 &o2hb_region_attr_block_bytes.attr, 1894 &o2hb_region_attr_start_block.attr, 1895 &o2hb_region_attr_blocks.attr, 1896 &o2hb_region_attr_dev.attr, 1897 &o2hb_region_attr_pid.attr, | 1856 &o2hb_region_attr_block_bytes, 1857 &o2hb_region_attr_start_block, 1858 &o2hb_region_attr_blocks, 1859 &o2hb_region_attr_dev, 1860 &o2hb_region_attr_pid, |
1898 NULL, 1899}; 1900 | 1861 NULL, 1862}; 1863 |
1901static ssize_t o2hb_region_show(struct config_item *item, 1902 struct configfs_attribute *attr, 1903 char *page) 1904{ 1905 struct o2hb_region *reg = to_o2hb_region(item); 1906 struct o2hb_region_attribute *o2hb_region_attr = 1907 container_of(attr, struct o2hb_region_attribute, attr); 1908 ssize_t ret = 0; 1909 1910 if (o2hb_region_attr->show) 1911 ret = o2hb_region_attr->show(reg, page); 1912 return ret; 1913} 1914 1915static ssize_t o2hb_region_store(struct config_item *item, 1916 struct configfs_attribute *attr, 1917 const char *page, size_t count) 1918{ 1919 struct o2hb_region *reg = to_o2hb_region(item); 1920 struct o2hb_region_attribute *o2hb_region_attr = 1921 container_of(attr, struct o2hb_region_attribute, attr); 1922 ssize_t ret = -EINVAL; 1923 1924 if (o2hb_region_attr->store) 1925 ret = o2hb_region_attr->store(reg, page, count); 1926 return ret; 1927} 1928 | |
1929static struct configfs_item_operations o2hb_region_item_ops = { 1930 .release = o2hb_region_release, | 1864static struct configfs_item_operations o2hb_region_item_ops = { 1865 .release = o2hb_region_release, |
1931 .show_attribute = o2hb_region_show, 1932 .store_attribute = o2hb_region_store, | |
1933}; 1934 1935static struct config_item_type o2hb_region_type = { 1936 .ct_item_ops = &o2hb_region_item_ops, 1937 .ct_attrs = o2hb_region_attrs, 1938 .ct_owner = THIS_MODULE, 1939}; 1940 --- 178 unchanged lines hidden (view full) --- 2119 if (bitmap_weight(o2hb_quorum_region_bitmap, 2120 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF) 2121 o2hb_region_pin(NULL); 2122 2123unlock: 2124 spin_unlock(&o2hb_live_lock); 2125} 2126 | 1866}; 1867 1868static struct config_item_type o2hb_region_type = { 1869 .ct_item_ops = &o2hb_region_item_ops, 1870 .ct_attrs = o2hb_region_attrs, 1871 .ct_owner = THIS_MODULE, 1872}; 1873 --- 178 unchanged lines hidden (view full) --- 2052 if (bitmap_weight(o2hb_quorum_region_bitmap, 2053 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF) 2054 o2hb_region_pin(NULL); 2055 2056unlock: 2057 spin_unlock(&o2hb_live_lock); 2058} 2059 |
2127struct o2hb_heartbeat_group_attribute { 2128 struct configfs_attribute attr; 2129 ssize_t (*show)(struct o2hb_heartbeat_group *, char *); 2130 ssize_t (*store)(struct o2hb_heartbeat_group *, const char *, size_t); 2131}; 2132 2133static ssize_t o2hb_heartbeat_group_show(struct config_item *item, 2134 struct configfs_attribute *attr, 2135 char *page) | 2060static ssize_t o2hb_heartbeat_group_threshold_show(struct config_item *item, 2061 char *page) |
2136{ | 2062{ |
2137 struct o2hb_heartbeat_group *reg = to_o2hb_heartbeat_group(to_config_group(item)); 2138 struct o2hb_heartbeat_group_attribute *o2hb_heartbeat_group_attr = 2139 container_of(attr, struct o2hb_heartbeat_group_attribute, attr); 2140 ssize_t ret = 0; 2141 2142 if (o2hb_heartbeat_group_attr->show) 2143 ret = o2hb_heartbeat_group_attr->show(reg, page); 2144 return ret; 2145} 2146 2147static ssize_t o2hb_heartbeat_group_store(struct config_item *item, 2148 struct configfs_attribute *attr, 2149 const char *page, size_t count) 2150{ 2151 struct o2hb_heartbeat_group *reg = to_o2hb_heartbeat_group(to_config_group(item)); 2152 struct o2hb_heartbeat_group_attribute *o2hb_heartbeat_group_attr = 2153 container_of(attr, struct o2hb_heartbeat_group_attribute, attr); 2154 ssize_t ret = -EINVAL; 2155 2156 if (o2hb_heartbeat_group_attr->store) 2157 ret = o2hb_heartbeat_group_attr->store(reg, page, count); 2158 return ret; 2159} 2160 2161static ssize_t o2hb_heartbeat_group_threshold_show(struct o2hb_heartbeat_group *group, 2162 char *page) 2163{ | |
2164 return sprintf(page, "%u\n", o2hb_dead_threshold); 2165} 2166 | 2063 return sprintf(page, "%u\n", o2hb_dead_threshold); 2064} 2065 |
2167static ssize_t o2hb_heartbeat_group_threshold_store(struct o2hb_heartbeat_group *group, 2168 const char *page, 2169 size_t count) | 2066static ssize_t o2hb_heartbeat_group_threshold_store(struct config_item *item, 2067 const char *page, size_t count) |
2170{ 2171 unsigned long tmp; 2172 char *p = (char *)page; 2173 2174 tmp = simple_strtoul(p, &p, 10); 2175 if (!p || (*p && (*p != '\n'))) 2176 return -EINVAL; 2177 2178 /* this will validate ranges for us. */ 2179 o2hb_dead_threshold_set((unsigned int) tmp); 2180 2181 return count; 2182} 2183 | 2068{ 2069 unsigned long tmp; 2070 char *p = (char *)page; 2071 2072 tmp = simple_strtoul(p, &p, 10); 2073 if (!p || (*p && (*p != '\n'))) 2074 return -EINVAL; 2075 2076 /* this will validate ranges for us. */ 2077 o2hb_dead_threshold_set((unsigned int) tmp); 2078 2079 return count; 2080} 2081 |
2184static 2185ssize_t o2hb_heartbeat_group_mode_show(struct o2hb_heartbeat_group *group, 2186 char *page) | 2082static ssize_t o2hb_heartbeat_group_mode_show(struct config_item *item, 2083 char *page) |
2187{ 2188 return sprintf(page, "%s\n", 2189 o2hb_heartbeat_mode_desc[o2hb_heartbeat_mode]); 2190} 2191 | 2084{ 2085 return sprintf(page, "%s\n", 2086 o2hb_heartbeat_mode_desc[o2hb_heartbeat_mode]); 2087} 2088 |
2192static 2193ssize_t o2hb_heartbeat_group_mode_store(struct o2hb_heartbeat_group *group, 2194 const char *page, size_t count) | 2089static ssize_t o2hb_heartbeat_group_mode_store(struct config_item *item, 2090 const char *page, size_t count) |
2195{ 2196 unsigned int i; 2197 int ret; 2198 size_t len; 2199 2200 len = (page[count - 1] == '\n') ? count - 1 : count; 2201 if (!len) 2202 return -EINVAL; --- 8 unchanged lines hidden (view full) --- 2211 o2hb_heartbeat_mode_desc[i]); 2212 return count; 2213 } 2214 2215 return -EINVAL; 2216 2217} 2218 | 2091{ 2092 unsigned int i; 2093 int ret; 2094 size_t len; 2095 2096 len = (page[count - 1] == '\n') ? count - 1 : count; 2097 if (!len) 2098 return -EINVAL; --- 8 unchanged lines hidden (view full) --- 2107 o2hb_heartbeat_mode_desc[i]); 2108 return count; 2109 } 2110 2111 return -EINVAL; 2112 2113} 2114 |
2219static struct o2hb_heartbeat_group_attribute o2hb_heartbeat_group_attr_threshold = { 2220 .attr = { .ca_owner = THIS_MODULE, 2221 .ca_name = "dead_threshold", 2222 .ca_mode = S_IRUGO | S_IWUSR }, 2223 .show = o2hb_heartbeat_group_threshold_show, 2224 .store = o2hb_heartbeat_group_threshold_store, 2225}; | 2115CONFIGFS_ATTR(o2hb_heartbeat_group_, threshold); 2116CONFIGFS_ATTR(o2hb_heartbeat_group_, mode); |
2226 | 2117 |
2227static struct o2hb_heartbeat_group_attribute o2hb_heartbeat_group_attr_mode = { 2228 .attr = { .ca_owner = THIS_MODULE, 2229 .ca_name = "mode", 2230 .ca_mode = S_IRUGO | S_IWUSR }, 2231 .show = o2hb_heartbeat_group_mode_show, 2232 .store = o2hb_heartbeat_group_mode_store, 2233}; 2234 | |
2235static struct configfs_attribute *o2hb_heartbeat_group_attrs[] = { | 2118static struct configfs_attribute *o2hb_heartbeat_group_attrs[] = { |
2236 &o2hb_heartbeat_group_attr_threshold.attr, 2237 &o2hb_heartbeat_group_attr_mode.attr, | 2119 &o2hb_heartbeat_group_attr_threshold, 2120 &o2hb_heartbeat_group_attr_mode, |
2238 NULL, 2239}; 2240 | 2121 NULL, 2122}; 2123 |
2241static struct configfs_item_operations o2hb_heartbeat_group_item_ops = { 2242 .show_attribute = o2hb_heartbeat_group_show, 2243 .store_attribute = o2hb_heartbeat_group_store, 2244}; 2245 | |
2246static struct configfs_group_operations o2hb_heartbeat_group_group_ops = { 2247 .make_item = o2hb_heartbeat_group_make_item, 2248 .drop_item = o2hb_heartbeat_group_drop_item, 2249}; 2250 2251static struct config_item_type o2hb_heartbeat_group_type = { 2252 .ct_group_ops = &o2hb_heartbeat_group_group_ops, | 2124static struct configfs_group_operations o2hb_heartbeat_group_group_ops = { 2125 .make_item = o2hb_heartbeat_group_make_item, 2126 .drop_item = o2hb_heartbeat_group_drop_item, 2127}; 2128 2129static struct config_item_type o2hb_heartbeat_group_type = { 2130 .ct_group_ops = &o2hb_heartbeat_group_group_ops, |
2253 .ct_item_ops = &o2hb_heartbeat_group_item_ops, | |
2254 .ct_attrs = o2hb_heartbeat_group_attrs, 2255 .ct_owner = THIS_MODULE, 2256}; 2257 2258/* this is just here to avoid touching group in heartbeat.h which the 2259 * entire damn world #includes */ 2260struct config_group *o2hb_alloc_hb_set(void) 2261{ --- 375 unchanged lines hidden --- | 2131 .ct_attrs = o2hb_heartbeat_group_attrs, 2132 .ct_owner = THIS_MODULE, 2133}; 2134 2135/* this is just here to avoid touching group in heartbeat.h which the 2136 * entire damn world #includes */ 2137struct config_group *o2hb_alloc_hb_set(void) 2138{ --- 375 unchanged lines hidden --- |