config.c 18 KB

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