config.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  5. ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
  6. **
  7. ** This copyrighted material is made available to anyone wishing to use,
  8. ** modify, copy, or redistribute it subject to the terms and conditions
  9. ** of the GNU General Public License v.2.
  10. **
  11. *******************************************************************************
  12. ******************************************************************************/
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/configfs.h>
  16. #include <net/sock.h>
  17. #include "config.h"
  18. #include "lowcomms.h"
  19. /*
  20. * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid
  21. * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight
  22. * /config/dlm/<cluster>/comms/<comm>/nodeid
  23. * /config/dlm/<cluster>/comms/<comm>/local
  24. * /config/dlm/<cluster>/comms/<comm>/addr
  25. * The <cluster> level is useless, but I haven't figured out how to avoid it.
  26. */
  27. static struct config_group *space_list;
  28. static struct config_group *comm_list;
  29. static struct comm *local_comm;
  30. struct clusters;
  31. struct cluster;
  32. struct spaces;
  33. struct space;
  34. struct comms;
  35. struct comm;
  36. struct nodes;
  37. struct node;
  38. static struct config_group *make_cluster(struct config_group *, const char *);
  39. static void drop_cluster(struct config_group *, struct config_item *);
  40. static void release_cluster(struct config_item *);
  41. static struct config_group *make_space(struct config_group *, const char *);
  42. static void drop_space(struct config_group *, struct config_item *);
  43. static void release_space(struct config_item *);
  44. static struct config_item *make_comm(struct config_group *, const char *);
  45. static void drop_comm(struct config_group *, struct config_item *);
  46. static void release_comm(struct config_item *);
  47. static struct config_item *make_node(struct config_group *, const char *);
  48. static void drop_node(struct config_group *, struct config_item *);
  49. static void release_node(struct config_item *);
  50. static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
  51. char *buf);
  52. static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
  53. const char *buf, size_t len);
  54. static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
  55. char *buf);
  56. static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
  57. const char *buf, size_t len);
  58. static ssize_t comm_nodeid_read(struct comm *cm, char *buf);
  59. static ssize_t comm_nodeid_write(struct comm *cm, const char *buf, size_t len);
  60. static ssize_t comm_local_read(struct comm *cm, char *buf);
  61. static ssize_t comm_local_write(struct comm *cm, const char *buf, size_t len);
  62. static ssize_t comm_addr_write(struct comm *cm, const char *buf, size_t len);
  63. static ssize_t node_nodeid_read(struct node *nd, char *buf);
  64. static ssize_t node_nodeid_write(struct node *nd, const char *buf, size_t len);
  65. static ssize_t node_weight_read(struct node *nd, char *buf);
  66. static ssize_t node_weight_write(struct node *nd, const char *buf, size_t len);
  67. enum {
  68. COMM_ATTR_NODEID = 0,
  69. COMM_ATTR_LOCAL,
  70. COMM_ATTR_ADDR,
  71. };
  72. struct comm_attribute {
  73. struct configfs_attribute attr;
  74. ssize_t (*show)(struct comm *, char *);
  75. ssize_t (*store)(struct comm *, const char *, size_t);
  76. };
  77. static struct comm_attribute comm_attr_nodeid = {
  78. .attr = { .ca_owner = THIS_MODULE,
  79. .ca_name = "nodeid",
  80. .ca_mode = S_IRUGO | S_IWUSR },
  81. .show = comm_nodeid_read,
  82. .store = comm_nodeid_write,
  83. };
  84. static struct comm_attribute comm_attr_local = {
  85. .attr = { .ca_owner = THIS_MODULE,
  86. .ca_name = "local",
  87. .ca_mode = S_IRUGO | S_IWUSR },
  88. .show = comm_local_read,
  89. .store = comm_local_write,
  90. };
  91. static struct comm_attribute comm_attr_addr = {
  92. .attr = { .ca_owner = THIS_MODULE,
  93. .ca_name = "addr",
  94. .ca_mode = S_IRUGO | S_IWUSR },
  95. .store = comm_addr_write,
  96. };
  97. static struct configfs_attribute *comm_attrs[] = {
  98. [COMM_ATTR_NODEID] = &comm_attr_nodeid.attr,
  99. [COMM_ATTR_LOCAL] = &comm_attr_local.attr,
  100. [COMM_ATTR_ADDR] = &comm_attr_addr.attr,
  101. NULL,
  102. };
  103. enum {
  104. NODE_ATTR_NODEID = 0,
  105. NODE_ATTR_WEIGHT,
  106. };
  107. struct node_attribute {
  108. struct configfs_attribute attr;
  109. ssize_t (*show)(struct node *, char *);
  110. ssize_t (*store)(struct node *, const char *, size_t);
  111. };
  112. static struct node_attribute node_attr_nodeid = {
  113. .attr = { .ca_owner = THIS_MODULE,
  114. .ca_name = "nodeid",
  115. .ca_mode = S_IRUGO | S_IWUSR },
  116. .show = node_nodeid_read,
  117. .store = node_nodeid_write,
  118. };
  119. static struct node_attribute node_attr_weight = {
  120. .attr = { .ca_owner = THIS_MODULE,
  121. .ca_name = "weight",
  122. .ca_mode = S_IRUGO | S_IWUSR },
  123. .show = node_weight_read,
  124. .store = node_weight_write,
  125. };
  126. static struct configfs_attribute *node_attrs[] = {
  127. [NODE_ATTR_NODEID] = &node_attr_nodeid.attr,
  128. [NODE_ATTR_WEIGHT] = &node_attr_weight.attr,
  129. NULL,
  130. };
  131. struct clusters {
  132. struct configfs_subsystem subsys;
  133. };
  134. struct cluster {
  135. struct config_group group;
  136. };
  137. struct spaces {
  138. struct config_group ss_group;
  139. };
  140. struct space {
  141. struct config_group group;
  142. struct list_head members;
  143. struct mutex members_lock;
  144. int members_count;
  145. };
  146. struct comms {
  147. struct config_group cs_group;
  148. };
  149. struct comm {
  150. struct config_item item;
  151. int nodeid;
  152. int local;
  153. int addr_count;
  154. struct sockaddr_storage *addr[DLM_MAX_ADDR_COUNT];
  155. };
  156. struct nodes {
  157. struct config_group ns_group;
  158. };
  159. struct node {
  160. struct config_item item;
  161. struct list_head list; /* space->members */
  162. int nodeid;
  163. int weight;
  164. };
  165. static struct configfs_group_operations clusters_ops = {
  166. .make_group = make_cluster,
  167. .drop_item = drop_cluster,
  168. };
  169. static struct configfs_item_operations cluster_ops = {
  170. .release = release_cluster,
  171. };
  172. static struct configfs_group_operations spaces_ops = {
  173. .make_group = make_space,
  174. .drop_item = drop_space,
  175. };
  176. static struct configfs_item_operations space_ops = {
  177. .release = release_space,
  178. };
  179. static struct configfs_group_operations comms_ops = {
  180. .make_item = make_comm,
  181. .drop_item = drop_comm,
  182. };
  183. static struct configfs_item_operations comm_ops = {
  184. .release = release_comm,
  185. .show_attribute = show_comm,
  186. .store_attribute = store_comm,
  187. };
  188. static struct configfs_group_operations nodes_ops = {
  189. .make_item = make_node,
  190. .drop_item = drop_node,
  191. };
  192. static struct configfs_item_operations node_ops = {
  193. .release = release_node,
  194. .show_attribute = show_node,
  195. .store_attribute = store_node,
  196. };
  197. static struct config_item_type clusters_type = {
  198. .ct_group_ops = &clusters_ops,
  199. .ct_owner = THIS_MODULE,
  200. };
  201. static struct config_item_type cluster_type = {
  202. .ct_item_ops = &cluster_ops,
  203. .ct_owner = THIS_MODULE,
  204. };
  205. static struct config_item_type spaces_type = {
  206. .ct_group_ops = &spaces_ops,
  207. .ct_owner = THIS_MODULE,
  208. };
  209. static struct config_item_type space_type = {
  210. .ct_item_ops = &space_ops,
  211. .ct_owner = THIS_MODULE,
  212. };
  213. static struct config_item_type comms_type = {
  214. .ct_group_ops = &comms_ops,
  215. .ct_owner = THIS_MODULE,
  216. };
  217. static struct config_item_type comm_type = {
  218. .ct_item_ops = &comm_ops,
  219. .ct_attrs = comm_attrs,
  220. .ct_owner = THIS_MODULE,
  221. };
  222. static struct config_item_type nodes_type = {
  223. .ct_group_ops = &nodes_ops,
  224. .ct_owner = THIS_MODULE,
  225. };
  226. static struct config_item_type node_type = {
  227. .ct_item_ops = &node_ops,
  228. .ct_attrs = node_attrs,
  229. .ct_owner = THIS_MODULE,
  230. };
  231. static struct cluster *to_cluster(struct config_item *i)
  232. {
  233. return i ? container_of(to_config_group(i), struct cluster, group):NULL;
  234. }
  235. static struct space *to_space(struct config_item *i)
  236. {
  237. return i ? container_of(to_config_group(i), struct space, group) : NULL;
  238. }
  239. static struct comm *to_comm(struct config_item *i)
  240. {
  241. return i ? container_of(i, struct comm, item) : NULL;
  242. }
  243. static struct node *to_node(struct config_item *i)
  244. {
  245. return i ? container_of(i, struct node, item) : NULL;
  246. }
  247. static struct config_group *make_cluster(struct config_group *g,
  248. const char *name)
  249. {
  250. struct cluster *cl = NULL;
  251. struct spaces *sps = NULL;
  252. struct comms *cms = NULL;
  253. void *gps = NULL;
  254. cl = kzalloc(sizeof(struct cluster), GFP_KERNEL);
  255. gps = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL);
  256. sps = kzalloc(sizeof(struct spaces), GFP_KERNEL);
  257. cms = kzalloc(sizeof(struct comms), GFP_KERNEL);
  258. if (!cl || !gps || !sps || !cms)
  259. goto fail;
  260. config_group_init_type_name(&cl->group, name, &cluster_type);
  261. config_group_init_type_name(&sps->ss_group, "spaces", &spaces_type);
  262. config_group_init_type_name(&cms->cs_group, "comms", &comms_type);
  263. cl->group.default_groups = gps;
  264. cl->group.default_groups[0] = &sps->ss_group;
  265. cl->group.default_groups[1] = &cms->cs_group;
  266. cl->group.default_groups[2] = NULL;
  267. space_list = &sps->ss_group;
  268. comm_list = &cms->cs_group;
  269. return &cl->group;
  270. fail:
  271. kfree(cl);
  272. kfree(gps);
  273. kfree(sps);
  274. kfree(cms);
  275. return NULL;
  276. }
  277. static void drop_cluster(struct config_group *g, struct config_item *i)
  278. {
  279. struct cluster *cl = to_cluster(i);
  280. struct config_item *tmp;
  281. int j;
  282. for (j = 0; cl->group.default_groups[j]; j++) {
  283. tmp = &cl->group.default_groups[j]->cg_item;
  284. cl->group.default_groups[j] = NULL;
  285. config_item_put(tmp);
  286. }
  287. space_list = NULL;
  288. comm_list = NULL;
  289. config_item_put(i);
  290. }
  291. static void release_cluster(struct config_item *i)
  292. {
  293. struct cluster *cl = to_cluster(i);
  294. kfree(cl->group.default_groups);
  295. kfree(cl);
  296. }
  297. static struct config_group *make_space(struct config_group *g, const char *name)
  298. {
  299. struct space *sp = NULL;
  300. struct nodes *nds = NULL;
  301. void *gps = NULL;
  302. sp = kzalloc(sizeof(struct space), GFP_KERNEL);
  303. gps = kcalloc(2, sizeof(struct config_group *), GFP_KERNEL);
  304. nds = kzalloc(sizeof(struct nodes), GFP_KERNEL);
  305. if (!sp || !gps || !nds)
  306. goto fail;
  307. config_group_init_type_name(&sp->group, name, &space_type);
  308. config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type);
  309. sp->group.default_groups = gps;
  310. sp->group.default_groups[0] = &nds->ns_group;
  311. sp->group.default_groups[1] = NULL;
  312. INIT_LIST_HEAD(&sp->members);
  313. mutex_init(&sp->members_lock);
  314. sp->members_count = 0;
  315. return &sp->group;
  316. fail:
  317. kfree(sp);
  318. kfree(gps);
  319. kfree(nds);
  320. return NULL;
  321. }
  322. static void drop_space(struct config_group *g, struct config_item *i)
  323. {
  324. struct space *sp = to_space(i);
  325. struct config_item *tmp;
  326. int j;
  327. /* assert list_empty(&sp->members) */
  328. for (j = 0; sp->group.default_groups[j]; j++) {
  329. tmp = &sp->group.default_groups[j]->cg_item;
  330. sp->group.default_groups[j] = NULL;
  331. config_item_put(tmp);
  332. }
  333. config_item_put(i);
  334. }
  335. static void release_space(struct config_item *i)
  336. {
  337. struct space *sp = to_space(i);
  338. kfree(sp->group.default_groups);
  339. kfree(sp);
  340. }
  341. static struct config_item *make_comm(struct config_group *g, const char *name)
  342. {
  343. struct comm *cm;
  344. cm = kzalloc(sizeof(struct comm), GFP_KERNEL);
  345. if (!cm)
  346. return NULL;
  347. config_item_init_type_name(&cm->item, name, &comm_type);
  348. cm->nodeid = -1;
  349. cm->local = 0;
  350. cm->addr_count = 0;
  351. return &cm->item;
  352. }
  353. static void drop_comm(struct config_group *g, struct config_item *i)
  354. {
  355. struct comm *cm = to_comm(i);
  356. if (local_comm == cm)
  357. local_comm = NULL;
  358. dlm_lowcomms_close(cm->nodeid);
  359. while (cm->addr_count--)
  360. kfree(cm->addr[cm->addr_count]);
  361. config_item_put(i);
  362. }
  363. static void release_comm(struct config_item *i)
  364. {
  365. struct comm *cm = to_comm(i);
  366. kfree(cm);
  367. }
  368. static struct config_item *make_node(struct config_group *g, const char *name)
  369. {
  370. struct space *sp = to_space(g->cg_item.ci_parent);
  371. struct node *nd;
  372. nd = kzalloc(sizeof(struct node), GFP_KERNEL);
  373. if (!nd)
  374. return NULL;
  375. config_item_init_type_name(&nd->item, name, &node_type);
  376. nd->nodeid = -1;
  377. nd->weight = 1; /* default weight of 1 if none is set */
  378. mutex_lock(&sp->members_lock);
  379. list_add(&nd->list, &sp->members);
  380. sp->members_count++;
  381. mutex_unlock(&sp->members_lock);
  382. return &nd->item;
  383. }
  384. static void drop_node(struct config_group *g, struct config_item *i)
  385. {
  386. struct space *sp = to_space(g->cg_item.ci_parent);
  387. struct node *nd = to_node(i);
  388. mutex_lock(&sp->members_lock);
  389. list_del(&nd->list);
  390. sp->members_count--;
  391. mutex_unlock(&sp->members_lock);
  392. config_item_put(i);
  393. }
  394. static void release_node(struct config_item *i)
  395. {
  396. struct node *nd = to_node(i);
  397. kfree(nd);
  398. }
  399. static struct clusters clusters_root = {
  400. .subsys = {
  401. .su_group = {
  402. .cg_item = {
  403. .ci_namebuf = "dlm",
  404. .ci_type = &clusters_type,
  405. },
  406. },
  407. },
  408. };
  409. int dlm_config_init(void)
  410. {
  411. config_group_init(&clusters_root.subsys.su_group);
  412. init_MUTEX(&clusters_root.subsys.su_sem);
  413. return configfs_register_subsystem(&clusters_root.subsys);
  414. }
  415. void dlm_config_exit(void)
  416. {
  417. configfs_unregister_subsystem(&clusters_root.subsys);
  418. }
  419. /*
  420. * Functions for user space to read/write attributes
  421. */
  422. static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
  423. char *buf)
  424. {
  425. struct comm *cm = to_comm(i);
  426. struct comm_attribute *cma =
  427. container_of(a, struct comm_attribute, attr);
  428. return cma->show ? cma->show(cm, buf) : 0;
  429. }
  430. static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
  431. const char *buf, size_t len)
  432. {
  433. struct comm *cm = to_comm(i);
  434. struct comm_attribute *cma =
  435. container_of(a, struct comm_attribute, attr);
  436. return cma->store ? cma->store(cm, buf, len) : -EINVAL;
  437. }
  438. static ssize_t comm_nodeid_read(struct comm *cm, char *buf)
  439. {
  440. return sprintf(buf, "%d\n", cm->nodeid);
  441. }
  442. static ssize_t comm_nodeid_write(struct comm *cm, const char *buf, size_t len)
  443. {
  444. cm->nodeid = simple_strtol(buf, NULL, 0);
  445. return len;
  446. }
  447. static ssize_t comm_local_read(struct comm *cm, char *buf)
  448. {
  449. return sprintf(buf, "%d\n", cm->local);
  450. }
  451. static ssize_t comm_local_write(struct comm *cm, const char *buf, size_t len)
  452. {
  453. cm->local= simple_strtol(buf, NULL, 0);
  454. if (cm->local && !local_comm)
  455. local_comm = cm;
  456. return len;
  457. }
  458. static ssize_t comm_addr_write(struct comm *cm, const char *buf, size_t len)
  459. {
  460. struct sockaddr_storage *addr;
  461. if (len != sizeof(struct sockaddr_storage))
  462. return -EINVAL;
  463. if (cm->addr_count >= DLM_MAX_ADDR_COUNT)
  464. return -ENOSPC;
  465. addr = kzalloc(sizeof(*addr), GFP_KERNEL);
  466. if (!addr)
  467. return -ENOMEM;
  468. memcpy(addr, buf, len);
  469. cm->addr[cm->addr_count++] = addr;
  470. return len;
  471. }
  472. static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
  473. char *buf)
  474. {
  475. struct node *nd = to_node(i);
  476. struct node_attribute *nda =
  477. container_of(a, struct node_attribute, attr);
  478. return nda->show ? nda->show(nd, buf) : 0;
  479. }
  480. static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
  481. const char *buf, size_t len)
  482. {
  483. struct node *nd = to_node(i);
  484. struct node_attribute *nda =
  485. container_of(a, struct node_attribute, attr);
  486. return nda->store ? nda->store(nd, buf, len) : -EINVAL;
  487. }
  488. static ssize_t node_nodeid_read(struct node *nd, char *buf)
  489. {
  490. return sprintf(buf, "%d\n", nd->nodeid);
  491. }
  492. static ssize_t node_nodeid_write(struct node *nd, const char *buf, size_t len)
  493. {
  494. nd->nodeid = simple_strtol(buf, NULL, 0);
  495. return len;
  496. }
  497. static ssize_t node_weight_read(struct node *nd, char *buf)
  498. {
  499. return sprintf(buf, "%d\n", nd->weight);
  500. }
  501. static ssize_t node_weight_write(struct node *nd, const char *buf, size_t len)
  502. {
  503. nd->weight = simple_strtol(buf, NULL, 0);
  504. return len;
  505. }
  506. /*
  507. * Functions for the dlm to get the info that's been configured
  508. */
  509. static struct space *get_space(char *name)
  510. {
  511. if (!space_list)
  512. return NULL;
  513. return to_space(config_group_find_obj(space_list, name));
  514. }
  515. static void put_space(struct space *sp)
  516. {
  517. config_item_put(&sp->group.cg_item);
  518. }
  519. static struct comm *get_comm(int nodeid, struct sockaddr_storage *addr)
  520. {
  521. struct config_item *i;
  522. struct comm *cm = NULL;
  523. int found = 0;
  524. if (!comm_list)
  525. return NULL;
  526. down(&clusters_root.subsys.su_sem);
  527. list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
  528. cm = to_comm(i);
  529. if (nodeid) {
  530. if (cm->nodeid != nodeid)
  531. continue;
  532. found = 1;
  533. break;
  534. } else {
  535. if (!cm->addr_count ||
  536. memcmp(cm->addr[0], addr, sizeof(*addr)))
  537. continue;
  538. found = 1;
  539. break;
  540. }
  541. }
  542. up(&clusters_root.subsys.su_sem);
  543. if (found)
  544. config_item_get(i);
  545. else
  546. cm = NULL;
  547. return cm;
  548. }
  549. static void put_comm(struct comm *cm)
  550. {
  551. config_item_put(&cm->item);
  552. }
  553. /* caller must free mem */
  554. int dlm_nodeid_list(char *lsname, int **ids_out)
  555. {
  556. struct space *sp;
  557. struct node *nd;
  558. int i = 0, rv = 0;
  559. int *ids;
  560. sp = get_space(lsname);
  561. if (!sp)
  562. return -EEXIST;
  563. mutex_lock(&sp->members_lock);
  564. if (!sp->members_count) {
  565. rv = 0;
  566. goto out;
  567. }
  568. ids = kcalloc(sp->members_count, sizeof(int), GFP_KERNEL);
  569. if (!ids) {
  570. rv = -ENOMEM;
  571. goto out;
  572. }
  573. rv = sp->members_count;
  574. list_for_each_entry(nd, &sp->members, list)
  575. ids[i++] = nd->nodeid;
  576. if (rv != i)
  577. printk("bad nodeid count %d %d\n", rv, i);
  578. *ids_out = ids;
  579. out:
  580. mutex_unlock(&sp->members_lock);
  581. put_space(sp);
  582. return rv;
  583. }
  584. int dlm_node_weight(char *lsname, int nodeid)
  585. {
  586. struct space *sp;
  587. struct node *nd;
  588. int w = -EEXIST;
  589. sp = get_space(lsname);
  590. if (!sp)
  591. goto out;
  592. mutex_lock(&sp->members_lock);
  593. list_for_each_entry(nd, &sp->members, list) {
  594. if (nd->nodeid != nodeid)
  595. continue;
  596. w = nd->weight;
  597. break;
  598. }
  599. mutex_unlock(&sp->members_lock);
  600. put_space(sp);
  601. out:
  602. return w;
  603. }
  604. int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr)
  605. {
  606. struct comm *cm = get_comm(nodeid, NULL);
  607. if (!cm)
  608. return -EEXIST;
  609. if (!cm->addr_count)
  610. return -ENOENT;
  611. memcpy(addr, cm->addr[0], sizeof(*addr));
  612. put_comm(cm);
  613. return 0;
  614. }
  615. int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid)
  616. {
  617. struct comm *cm = get_comm(0, addr);
  618. if (!cm)
  619. return -EEXIST;
  620. *nodeid = cm->nodeid;
  621. put_comm(cm);
  622. return 0;
  623. }
  624. int dlm_our_nodeid(void)
  625. {
  626. return local_comm ? local_comm->nodeid : 0;
  627. }
  628. /* num 0 is first addr, num 1 is second addr */
  629. int dlm_our_addr(struct sockaddr_storage *addr, int num)
  630. {
  631. if (!local_comm)
  632. return -1;
  633. if (num + 1 > local_comm->addr_count)
  634. return -1;
  635. memcpy(addr, local_comm->addr[num], sizeof(*addr));
  636. return 0;
  637. }
  638. /* Config file defaults */
  639. #define DEFAULT_TCP_PORT 21064
  640. #define DEFAULT_BUFFER_SIZE 4096
  641. #define DEFAULT_RSBTBL_SIZE 256
  642. #define DEFAULT_LKBTBL_SIZE 1024
  643. #define DEFAULT_DIRTBL_SIZE 512
  644. #define DEFAULT_RECOVER_TIMER 5
  645. #define DEFAULT_TOSS_SECS 10
  646. #define DEFAULT_SCAN_SECS 5
  647. struct dlm_config_info dlm_config = {
  648. .tcp_port = DEFAULT_TCP_PORT,
  649. .buffer_size = DEFAULT_BUFFER_SIZE,
  650. .rsbtbl_size = DEFAULT_RSBTBL_SIZE,
  651. .lkbtbl_size = DEFAULT_LKBTBL_SIZE,
  652. .dirtbl_size = DEFAULT_DIRTBL_SIZE,
  653. .recover_timer = DEFAULT_RECOVER_TIMER,
  654. .toss_secs = DEFAULT_TOSS_SECS,
  655. .scan_secs = DEFAULT_SCAN_SECS
  656. };