hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/ocfs2/cluster/heartbeat.c
....@@ -1,22 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* -*- mode: c; c-basic-offset: 8; -*-
23 * vim: noexpandtab sw=8 ts=8 sts=0:
34 *
45 * 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
9
- * version 2 of the License, or (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public
17
- * License along with this program; if not, write to the
18
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
- * Boston, MA 021110-1307, USA.
206 */
217
228 #include <linux/kernel.h>
....@@ -106,10 +92,6 @@
10692 #define O2HB_DEBUG_REGION_PINNED "pinned"
10793
10894 static struct dentry *o2hb_debug_dir;
109
-static struct dentry *o2hb_debug_livenodes;
110
-static struct dentry *o2hb_debug_liveregions;
111
-static struct dentry *o2hb_debug_quorumregions;
112
-static struct dentry *o2hb_debug_failedregions;
11395
11496 static LIST_HEAD(o2hb_all_regions);
11597
....@@ -118,8 +100,6 @@
118100 } o2hb_callbacks[O2HB_NUM_CB];
119101
120102 static struct o2hb_callback *hbcall_from_type(enum o2hb_callback_type type);
121
-
122
-#define O2HB_DEFAULT_BLOCK_BITS 9
123103
124104 enum o2hb_heartbeat_modes {
125105 O2HB_HEARTBEAT_LOCAL = 0,
....@@ -243,10 +223,6 @@
243223 unsigned int hr_region_num;
244224
245225 struct dentry *hr_debug_dir;
246
- struct dentry *hr_debug_livenodes;
247
- struct dentry *hr_debug_regnum;
248
- struct dentry *hr_debug_elapsed_time;
249
- struct dentry *hr_debug_pinned;
250226 struct o2hb_debug_buf *hr_db_livenodes;
251227 struct o2hb_debug_buf *hr_db_regnum;
252228 struct o2hb_debug_buf *hr_db_elapsed_time;
....@@ -582,9 +558,10 @@
582558 }
583559
584560 static int o2hb_read_slots(struct o2hb_region *reg,
561
+ unsigned int begin_slot,
585562 unsigned int max_slots)
586563 {
587
- unsigned int current_slot=0;
564
+ unsigned int current_slot = begin_slot;
588565 int status;
589566 struct o2hb_bio_wait_ctxt wc;
590567 struct bio *bio;
....@@ -1093,9 +1070,14 @@
10931070 return find_last_bit(nodes, numbits);
10941071 }
10951072
1073
+static int o2hb_lowest_node(unsigned long *nodes, int numbits)
1074
+{
1075
+ return find_first_bit(nodes, numbits);
1076
+}
1077
+
10961078 static int o2hb_do_disk_heartbeat(struct o2hb_region *reg)
10971079 {
1098
- int i, ret, highest_node;
1080
+ int i, ret, highest_node, lowest_node;
10991081 int membership_change = 0, own_slot_ok = 0;
11001082 unsigned long configured_nodes[BITS_TO_LONGS(O2NM_MAX_NODES)];
11011083 unsigned long live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
....@@ -1120,7 +1102,8 @@
11201102 }
11211103
11221104 highest_node = o2hb_highest_node(configured_nodes, O2NM_MAX_NODES);
1123
- if (highest_node >= O2NM_MAX_NODES) {
1105
+ lowest_node = o2hb_lowest_node(configured_nodes, O2NM_MAX_NODES);
1106
+ if (highest_node >= O2NM_MAX_NODES || lowest_node >= O2NM_MAX_NODES) {
11241107 mlog(ML_NOTICE, "o2hb: No configured nodes found!\n");
11251108 ret = -EINVAL;
11261109 goto bail;
....@@ -1130,7 +1113,7 @@
11301113 * yet. Of course, if the node definitions have holes in them
11311114 * then we're reading an empty slot anyway... Consider this
11321115 * best-effort. */
1133
- ret = o2hb_read_slots(reg, highest_node + 1);
1116
+ ret = o2hb_read_slots(reg, lowest_node, highest_node + 1);
11341117 if (ret < 0) {
11351118 mlog_errno(ret);
11361119 goto bail;
....@@ -1191,7 +1174,7 @@
11911174 if (atomic_read(&reg->hr_steady_iterations) != 0) {
11921175 if (atomic_dec_and_test(&reg->hr_unsteady_iterations)) {
11931176 printk(KERN_NOTICE "o2hb: Unable to stabilize "
1194
- "heartbeart on region %s (%s)\n",
1177
+ "heartbeat on region %s (%s)\n",
11951178 config_item_name(&reg->hr_item),
11961179 reg->hr_dev_name);
11971180 atomic_set(&reg->hr_steady_iterations, 0);
....@@ -1324,7 +1307,7 @@
13241307
13251308 case O2HB_DB_TYPE_REGION_NUMBER:
13261309 reg = (struct o2hb_region *)db->db_data;
1327
- out += snprintf(buf + out, PAGE_SIZE - out, "%d\n",
1310
+ out += scnprintf(buf + out, PAGE_SIZE - out, "%d\n",
13281311 reg->hr_region_num);
13291312 goto done;
13301313
....@@ -1334,12 +1317,12 @@
13341317 /* If 0, it has never been set before */
13351318 if (lts)
13361319 lts = jiffies_to_msecs(jiffies - lts);
1337
- out += snprintf(buf + out, PAGE_SIZE - out, "%lu\n", lts);
1320
+ out += scnprintf(buf + out, PAGE_SIZE - out, "%lu\n", lts);
13381321 goto done;
13391322
13401323 case O2HB_DB_TYPE_REGION_PINNED:
13411324 reg = (struct o2hb_region *)db->db_data;
1342
- out += snprintf(buf + out, PAGE_SIZE - out, "%u\n",
1325
+ out += scnprintf(buf + out, PAGE_SIZE - out, "%u\n",
13431326 !!reg->hr_item_pinned);
13441327 goto done;
13451328
....@@ -1348,8 +1331,8 @@
13481331 }
13491332
13501333 while ((i = find_next_bit(map, db->db_len, i + 1)) < db->db_len)
1351
- out += snprintf(buf + out, PAGE_SIZE - out, "%d ", i);
1352
- out += snprintf(buf + out, PAGE_SIZE - out, "\n");
1334
+ out += scnprintf(buf + out, PAGE_SIZE - out, "%d ", i);
1335
+ out += scnprintf(buf + out, PAGE_SIZE - out, "\n");
13531336
13541337 done:
13551338 i_size_write(inode, out);
....@@ -1398,107 +1381,60 @@
13981381
13991382 void o2hb_exit(void)
14001383 {
1401
- debugfs_remove(o2hb_debug_failedregions);
1402
- debugfs_remove(o2hb_debug_quorumregions);
1403
- debugfs_remove(o2hb_debug_liveregions);
1404
- debugfs_remove(o2hb_debug_livenodes);
1405
- debugfs_remove(o2hb_debug_dir);
1384
+ debugfs_remove_recursive(o2hb_debug_dir);
14061385 kfree(o2hb_db_livenodes);
14071386 kfree(o2hb_db_liveregions);
14081387 kfree(o2hb_db_quorumregions);
14091388 kfree(o2hb_db_failedregions);
14101389 }
14111390
1412
-static struct dentry *o2hb_debug_create(const char *name, struct dentry *dir,
1413
- struct o2hb_debug_buf **db, int db_len,
1414
- int type, int size, int len, void *data)
1391
+static void o2hb_debug_create(const char *name, struct dentry *dir,
1392
+ struct o2hb_debug_buf **db, int db_len, int type,
1393
+ int size, int len, void *data)
14151394 {
14161395 *db = kmalloc(db_len, GFP_KERNEL);
14171396 if (!*db)
1418
- return NULL;
1397
+ return;
14191398
14201399 (*db)->db_type = type;
14211400 (*db)->db_size = size;
14221401 (*db)->db_len = len;
14231402 (*db)->db_data = data;
14241403
1425
- return debugfs_create_file(name, S_IFREG|S_IRUSR, dir, *db,
1426
- &o2hb_debug_fops);
1404
+ debugfs_create_file(name, S_IFREG|S_IRUSR, dir, *db, &o2hb_debug_fops);
14271405 }
14281406
1429
-static int o2hb_debug_init(void)
1407
+static void o2hb_debug_init(void)
14301408 {
1431
- int ret = -ENOMEM;
1432
-
14331409 o2hb_debug_dir = debugfs_create_dir(O2HB_DEBUG_DIR, NULL);
1434
- if (!o2hb_debug_dir) {
1435
- mlog_errno(ret);
1436
- goto bail;
1437
- }
14381410
1439
- o2hb_debug_livenodes = o2hb_debug_create(O2HB_DEBUG_LIVENODES,
1440
- o2hb_debug_dir,
1441
- &o2hb_db_livenodes,
1442
- sizeof(*o2hb_db_livenodes),
1443
- O2HB_DB_TYPE_LIVENODES,
1444
- sizeof(o2hb_live_node_bitmap),
1445
- O2NM_MAX_NODES,
1446
- o2hb_live_node_bitmap);
1447
- if (!o2hb_debug_livenodes) {
1448
- mlog_errno(ret);
1449
- goto bail;
1450
- }
1411
+ o2hb_debug_create(O2HB_DEBUG_LIVENODES, o2hb_debug_dir,
1412
+ &o2hb_db_livenodes, sizeof(*o2hb_db_livenodes),
1413
+ O2HB_DB_TYPE_LIVENODES, sizeof(o2hb_live_node_bitmap),
1414
+ O2NM_MAX_NODES, o2hb_live_node_bitmap);
14511415
1452
- o2hb_debug_liveregions = o2hb_debug_create(O2HB_DEBUG_LIVEREGIONS,
1453
- o2hb_debug_dir,
1454
- &o2hb_db_liveregions,
1455
- sizeof(*o2hb_db_liveregions),
1456
- O2HB_DB_TYPE_LIVEREGIONS,
1457
- sizeof(o2hb_live_region_bitmap),
1458
- O2NM_MAX_REGIONS,
1459
- o2hb_live_region_bitmap);
1460
- if (!o2hb_debug_liveregions) {
1461
- mlog_errno(ret);
1462
- goto bail;
1463
- }
1416
+ o2hb_debug_create(O2HB_DEBUG_LIVEREGIONS, o2hb_debug_dir,
1417
+ &o2hb_db_liveregions, sizeof(*o2hb_db_liveregions),
1418
+ O2HB_DB_TYPE_LIVEREGIONS,
1419
+ sizeof(o2hb_live_region_bitmap), O2NM_MAX_REGIONS,
1420
+ o2hb_live_region_bitmap);
14641421
1465
- o2hb_debug_quorumregions =
1466
- o2hb_debug_create(O2HB_DEBUG_QUORUMREGIONS,
1467
- o2hb_debug_dir,
1468
- &o2hb_db_quorumregions,
1469
- sizeof(*o2hb_db_quorumregions),
1470
- O2HB_DB_TYPE_QUORUMREGIONS,
1471
- sizeof(o2hb_quorum_region_bitmap),
1472
- O2NM_MAX_REGIONS,
1473
- o2hb_quorum_region_bitmap);
1474
- if (!o2hb_debug_quorumregions) {
1475
- mlog_errno(ret);
1476
- goto bail;
1477
- }
1422
+ o2hb_debug_create(O2HB_DEBUG_QUORUMREGIONS, o2hb_debug_dir,
1423
+ &o2hb_db_quorumregions,
1424
+ sizeof(*o2hb_db_quorumregions),
1425
+ O2HB_DB_TYPE_QUORUMREGIONS,
1426
+ sizeof(o2hb_quorum_region_bitmap), O2NM_MAX_REGIONS,
1427
+ o2hb_quorum_region_bitmap);
14781428
1479
- o2hb_debug_failedregions =
1480
- o2hb_debug_create(O2HB_DEBUG_FAILEDREGIONS,
1481
- o2hb_debug_dir,
1482
- &o2hb_db_failedregions,
1483
- sizeof(*o2hb_db_failedregions),
1484
- O2HB_DB_TYPE_FAILEDREGIONS,
1485
- sizeof(o2hb_failed_region_bitmap),
1486
- O2NM_MAX_REGIONS,
1487
- o2hb_failed_region_bitmap);
1488
- if (!o2hb_debug_failedregions) {
1489
- mlog_errno(ret);
1490
- goto bail;
1491
- }
1492
-
1493
- ret = 0;
1494
-bail:
1495
- if (ret)
1496
- o2hb_exit();
1497
-
1498
- return ret;
1429
+ o2hb_debug_create(O2HB_DEBUG_FAILEDREGIONS, o2hb_debug_dir,
1430
+ &o2hb_db_failedregions,
1431
+ sizeof(*o2hb_db_failedregions),
1432
+ O2HB_DB_TYPE_FAILEDREGIONS,
1433
+ sizeof(o2hb_failed_region_bitmap), O2NM_MAX_REGIONS,
1434
+ o2hb_failed_region_bitmap);
14991435 }
15001436
1501
-int o2hb_init(void)
1437
+void o2hb_init(void)
15021438 {
15031439 int i;
15041440
....@@ -1518,7 +1454,7 @@
15181454
15191455 o2hb_dependent_users = 0;
15201456
1521
- return o2hb_debug_init();
1457
+ o2hb_debug_init();
15221458 }
15231459
15241460 /* if we're already in a callback then we're already serialized by the sem */
....@@ -1582,11 +1518,7 @@
15821518
15831519 kfree(reg->hr_slots);
15841520
1585
- debugfs_remove(reg->hr_debug_livenodes);
1586
- debugfs_remove(reg->hr_debug_regnum);
1587
- debugfs_remove(reg->hr_debug_elapsed_time);
1588
- debugfs_remove(reg->hr_debug_pinned);
1589
- debugfs_remove(reg->hr_debug_dir);
1521
+ debugfs_remove_recursive(reg->hr_debug_dir);
15901522 kfree(reg->hr_db_livenodes);
15911523 kfree(reg->hr_db_regnum);
15921524 kfree(reg->hr_db_elapsed_time);
....@@ -1801,7 +1733,7 @@
18011733 struct o2hb_disk_slot *slot;
18021734 struct o2hb_disk_heartbeat_block *hb_block;
18031735
1804
- ret = o2hb_read_slots(reg, reg->hr_blocks);
1736
+ ret = o2hb_read_slots(reg, 0, reg->hr_blocks);
18051737 if (ret)
18061738 goto out;
18071739
....@@ -1834,7 +1766,6 @@
18341766 int sectsize;
18351767 char *p = (char *)page;
18361768 struct fd f;
1837
- struct inode *inode;
18381769 ssize_t ret = -EINVAL;
18391770 int live_threshold;
18401771
....@@ -1861,20 +1792,16 @@
18611792 reg->hr_block_bytes == 0)
18621793 goto out2;
18631794
1864
- inode = igrab(f.file->f_mapping->host);
1865
- if (inode == NULL)
1795
+ if (!S_ISBLK(f.file->f_mapping->host->i_mode))
18661796 goto out2;
18671797
1868
- if (!S_ISBLK(inode->i_mode))
1869
- goto out3;
1870
-
1871
- reg->hr_bdev = I_BDEV(f.file->f_mapping->host);
1872
- ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ, NULL);
1873
- if (ret) {
1798
+ reg->hr_bdev = blkdev_get_by_dev(f.file->f_mapping->host->i_rdev,
1799
+ FMODE_WRITE | FMODE_READ, NULL);
1800
+ if (IS_ERR(reg->hr_bdev)) {
1801
+ ret = PTR_ERR(reg->hr_bdev);
18741802 reg->hr_bdev = NULL;
1875
- goto out3;
1803
+ goto out2;
18761804 }
1877
- inode = NULL;
18781805
18791806 bdevname(reg->hr_bdev, reg->hr_dev_name);
18801807
....@@ -1977,16 +1904,13 @@
19771904 config_item_name(&reg->hr_item), reg->hr_dev_name);
19781905
19791906 out3:
1980
- iput(inode);
1907
+ if (ret < 0) {
1908
+ blkdev_put(reg->hr_bdev, FMODE_READ | FMODE_WRITE);
1909
+ reg->hr_bdev = NULL;
1910
+ }
19811911 out2:
19821912 fdput(f);
19831913 out:
1984
- if (ret < 0) {
1985
- if (reg->hr_bdev) {
1986
- blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE);
1987
- reg->hr_bdev = NULL;
1988
- }
1989
- }
19901914 return ret;
19911915 }
19921916
....@@ -2045,69 +1969,33 @@
20451969 : NULL;
20461970 }
20471971
2048
-static int o2hb_debug_region_init(struct o2hb_region *reg, struct dentry *dir)
1972
+static void o2hb_debug_region_init(struct o2hb_region *reg,
1973
+ struct dentry *parent)
20491974 {
2050
- int ret = -ENOMEM;
1975
+ struct dentry *dir;
20511976
2052
- reg->hr_debug_dir =
2053
- debugfs_create_dir(config_item_name(&reg->hr_item), dir);
2054
- if (!reg->hr_debug_dir) {
2055
- mlog_errno(ret);
2056
- goto bail;
2057
- }
1977
+ dir = debugfs_create_dir(config_item_name(&reg->hr_item), parent);
1978
+ reg->hr_debug_dir = dir;
20581979
2059
- reg->hr_debug_livenodes =
2060
- o2hb_debug_create(O2HB_DEBUG_LIVENODES,
2061
- reg->hr_debug_dir,
2062
- &(reg->hr_db_livenodes),
2063
- sizeof(*(reg->hr_db_livenodes)),
2064
- O2HB_DB_TYPE_REGION_LIVENODES,
2065
- sizeof(reg->hr_live_node_bitmap),
2066
- O2NM_MAX_NODES, reg);
2067
- if (!reg->hr_debug_livenodes) {
2068
- mlog_errno(ret);
2069
- goto bail;
2070
- }
1980
+ o2hb_debug_create(O2HB_DEBUG_LIVENODES, dir, &(reg->hr_db_livenodes),
1981
+ sizeof(*(reg->hr_db_livenodes)),
1982
+ O2HB_DB_TYPE_REGION_LIVENODES,
1983
+ sizeof(reg->hr_live_node_bitmap), O2NM_MAX_NODES,
1984
+ reg);
20711985
2072
- reg->hr_debug_regnum =
2073
- o2hb_debug_create(O2HB_DEBUG_REGION_NUMBER,
2074
- reg->hr_debug_dir,
2075
- &(reg->hr_db_regnum),
2076
- sizeof(*(reg->hr_db_regnum)),
2077
- O2HB_DB_TYPE_REGION_NUMBER,
2078
- 0, O2NM_MAX_NODES, reg);
2079
- if (!reg->hr_debug_regnum) {
2080
- mlog_errno(ret);
2081
- goto bail;
2082
- }
1986
+ o2hb_debug_create(O2HB_DEBUG_REGION_NUMBER, dir, &(reg->hr_db_regnum),
1987
+ sizeof(*(reg->hr_db_regnum)),
1988
+ O2HB_DB_TYPE_REGION_NUMBER, 0, O2NM_MAX_NODES, reg);
20831989
2084
- reg->hr_debug_elapsed_time =
2085
- o2hb_debug_create(O2HB_DEBUG_REGION_ELAPSED_TIME,
2086
- reg->hr_debug_dir,
2087
- &(reg->hr_db_elapsed_time),
2088
- sizeof(*(reg->hr_db_elapsed_time)),
2089
- O2HB_DB_TYPE_REGION_ELAPSED_TIME,
2090
- 0, 0, reg);
2091
- if (!reg->hr_debug_elapsed_time) {
2092
- mlog_errno(ret);
2093
- goto bail;
2094
- }
1990
+ o2hb_debug_create(O2HB_DEBUG_REGION_ELAPSED_TIME, dir,
1991
+ &(reg->hr_db_elapsed_time),
1992
+ sizeof(*(reg->hr_db_elapsed_time)),
1993
+ O2HB_DB_TYPE_REGION_ELAPSED_TIME, 0, 0, reg);
20951994
2096
- reg->hr_debug_pinned =
2097
- o2hb_debug_create(O2HB_DEBUG_REGION_PINNED,
2098
- reg->hr_debug_dir,
2099
- &(reg->hr_db_pinned),
2100
- sizeof(*(reg->hr_db_pinned)),
2101
- O2HB_DB_TYPE_REGION_PINNED,
2102
- 0, 0, reg);
2103
- if (!reg->hr_debug_pinned) {
2104
- mlog_errno(ret);
2105
- goto bail;
2106
- }
1995
+ o2hb_debug_create(O2HB_DEBUG_REGION_PINNED, dir, &(reg->hr_db_pinned),
1996
+ sizeof(*(reg->hr_db_pinned)),
1997
+ O2HB_DB_TYPE_REGION_PINNED, 0, 0, reg);
21071998
2108
- ret = 0;
2109
-bail:
2110
- return ret;
21111999 }
21122000
21132001 static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *group,
....@@ -2163,11 +2051,7 @@
21632051 if (ret)
21642052 goto unregister_handler;
21652053
2166
- ret = o2hb_debug_region_init(reg, o2hb_debug_dir);
2167
- if (ret) {
2168
- config_item_put(&reg->hr_item);
2169
- goto unregister_handler;
2170
- }
2054
+ o2hb_debug_region_init(reg, o2hb_debug_dir);
21712055
21722056 return &reg->hr_item;
21732057