dm-log-userspace-base.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /*
  2. * Copyright (C) 2006-2009 Red Hat, Inc.
  3. *
  4. * This file is released under the LGPL.
  5. */
  6. #include <linux/bio.h>
  7. #include <linux/slab.h>
  8. #include <linux/dm-dirty-log.h>
  9. #include <linux/device-mapper.h>
  10. #include <linux/dm-log-userspace.h>
  11. #include "dm-log-userspace-transfer.h"
  12. #define DM_LOG_USERSPACE_VSN "1.1.0"
  13. struct flush_entry {
  14. int type;
  15. region_t region;
  16. struct list_head list;
  17. };
  18. /*
  19. * This limit on the number of mark and clear request is, to a degree,
  20. * arbitrary. However, there is some basis for the choice in the limits
  21. * imposed on the size of data payload by dm-log-userspace-transfer.c:
  22. * dm_consult_userspace().
  23. */
  24. #define MAX_FLUSH_GROUP_COUNT 32
  25. struct log_c {
  26. struct dm_target *ti;
  27. uint32_t region_size;
  28. region_t region_count;
  29. uint64_t luid;
  30. char uuid[DM_UUID_LEN];
  31. char *usr_argv_str;
  32. uint32_t usr_argc;
  33. /*
  34. * in_sync_hint gets set when doing is_remote_recovering. It
  35. * represents the first region that needs recovery. IOW, the
  36. * first zero bit of sync_bits. This can be useful for to limit
  37. * traffic for calls like is_remote_recovering and get_resync_work,
  38. * but be take care in its use for anything else.
  39. */
  40. uint64_t in_sync_hint;
  41. /*
  42. * Mark and clear requests are held until a flush is issued
  43. * so that we can group, and thereby limit, the amount of
  44. * network traffic between kernel and userspace. The 'flush_lock'
  45. * is used to protect these lists.
  46. */
  47. spinlock_t flush_lock;
  48. struct list_head mark_list;
  49. struct list_head clear_list;
  50. };
  51. static mempool_t *flush_entry_pool;
  52. static void *flush_entry_alloc(gfp_t gfp_mask, void *pool_data)
  53. {
  54. return kmalloc(sizeof(struct flush_entry), gfp_mask);
  55. }
  56. static void flush_entry_free(void *element, void *pool_data)
  57. {
  58. kfree(element);
  59. }
  60. static int userspace_do_request(struct log_c *lc, const char *uuid,
  61. int request_type, char *data, size_t data_size,
  62. char *rdata, size_t *rdata_size)
  63. {
  64. int r;
  65. /*
  66. * If the server isn't there, -ESRCH is returned,
  67. * and we must keep trying until the server is
  68. * restored.
  69. */
  70. retry:
  71. r = dm_consult_userspace(uuid, lc->luid, request_type, data,
  72. data_size, rdata, rdata_size);
  73. if (r != -ESRCH)
  74. return r;
  75. DMERR(" Userspace log server not found.");
  76. while (1) {
  77. set_current_state(TASK_INTERRUPTIBLE);
  78. schedule_timeout(2*HZ);
  79. DMWARN("Attempting to contact userspace log server...");
  80. r = dm_consult_userspace(uuid, lc->luid, DM_ULOG_CTR,
  81. lc->usr_argv_str,
  82. strlen(lc->usr_argv_str) + 1,
  83. NULL, NULL);
  84. if (!r)
  85. break;
  86. }
  87. DMINFO("Reconnected to userspace log server... DM_ULOG_CTR complete");
  88. r = dm_consult_userspace(uuid, lc->luid, DM_ULOG_RESUME, NULL,
  89. 0, NULL, NULL);
  90. if (!r)
  91. goto retry;
  92. DMERR("Error trying to resume userspace log: %d", r);
  93. return -ESRCH;
  94. }
  95. static int build_constructor_string(struct dm_target *ti,
  96. unsigned argc, char **argv,
  97. char **ctr_str)
  98. {
  99. int i, str_size;
  100. char *str = NULL;
  101. *ctr_str = NULL;
  102. for (i = 0, str_size = 0; i < argc; i++)
  103. str_size += strlen(argv[i]) + 1; /* +1 for space between args */
  104. str_size += 20; /* Max number of chars in a printed u64 number */
  105. str = kzalloc(str_size, GFP_KERNEL);
  106. if (!str) {
  107. DMWARN("Unable to allocate memory for constructor string");
  108. return -ENOMEM;
  109. }
  110. str_size = sprintf(str, "%llu", (unsigned long long)ti->len);
  111. for (i = 0; i < argc; i++)
  112. str_size += sprintf(str + str_size, " %s", argv[i]);
  113. *ctr_str = str;
  114. return str_size;
  115. }
  116. /*
  117. * userspace_ctr
  118. *
  119. * argv contains:
  120. * <UUID> <other args>
  121. * Where 'other args' is the userspace implementation specific log
  122. * arguments. An example might be:
  123. * <UUID> clustered_disk <arg count> <log dev> <region_size> [[no]sync]
  124. *
  125. * So, this module will strip off the <UUID> for identification purposes
  126. * when communicating with userspace about a log; but will pass on everything
  127. * else.
  128. */
  129. static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti,
  130. unsigned argc, char **argv)
  131. {
  132. int r = 0;
  133. int str_size;
  134. char *ctr_str = NULL;
  135. struct log_c *lc = NULL;
  136. uint64_t rdata;
  137. size_t rdata_size = sizeof(rdata);
  138. if (argc < 3) {
  139. DMWARN("Too few arguments to userspace dirty log");
  140. return -EINVAL;
  141. }
  142. lc = kmalloc(sizeof(*lc), GFP_KERNEL);
  143. if (!lc) {
  144. DMWARN("Unable to allocate userspace log context.");
  145. return -ENOMEM;
  146. }
  147. /* The ptr value is sufficient for local unique id */
  148. lc->luid = (unsigned long)lc;
  149. lc->ti = ti;
  150. if (strlen(argv[0]) > (DM_UUID_LEN - 1)) {
  151. DMWARN("UUID argument too long.");
  152. kfree(lc);
  153. return -EINVAL;
  154. }
  155. strncpy(lc->uuid, argv[0], DM_UUID_LEN);
  156. spin_lock_init(&lc->flush_lock);
  157. INIT_LIST_HEAD(&lc->mark_list);
  158. INIT_LIST_HEAD(&lc->clear_list);
  159. str_size = build_constructor_string(ti, argc - 1, argv + 1, &ctr_str);
  160. if (str_size < 0) {
  161. kfree(lc);
  162. return str_size;
  163. }
  164. /* Send table string */
  165. r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_CTR,
  166. ctr_str, str_size, NULL, NULL);
  167. if (r < 0) {
  168. if (r == -ESRCH)
  169. DMERR("Userspace log server not found");
  170. else
  171. DMERR("Userspace log server failed to create log");
  172. goto out;
  173. }
  174. /* Since the region size does not change, get it now */
  175. rdata_size = sizeof(rdata);
  176. r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_GET_REGION_SIZE,
  177. NULL, 0, (char *)&rdata, &rdata_size);
  178. if (r) {
  179. DMERR("Failed to get region size of dirty log");
  180. goto out;
  181. }
  182. lc->region_size = (uint32_t)rdata;
  183. lc->region_count = dm_sector_div_up(ti->len, lc->region_size);
  184. out:
  185. if (r) {
  186. kfree(lc);
  187. kfree(ctr_str);
  188. } else {
  189. lc->usr_argv_str = ctr_str;
  190. lc->usr_argc = argc;
  191. log->context = lc;
  192. }
  193. return r;
  194. }
  195. static void userspace_dtr(struct dm_dirty_log *log)
  196. {
  197. struct log_c *lc = log->context;
  198. (void) dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_DTR,
  199. NULL, 0,
  200. NULL, NULL);
  201. kfree(lc->usr_argv_str);
  202. kfree(lc);
  203. return;
  204. }
  205. static int userspace_presuspend(struct dm_dirty_log *log)
  206. {
  207. int r;
  208. struct log_c *lc = log->context;
  209. r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_PRESUSPEND,
  210. NULL, 0,
  211. NULL, NULL);
  212. return r;
  213. }
  214. static int userspace_postsuspend(struct dm_dirty_log *log)
  215. {
  216. int r;
  217. struct log_c *lc = log->context;
  218. r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_POSTSUSPEND,
  219. NULL, 0,
  220. NULL, NULL);
  221. return r;
  222. }
  223. static int userspace_resume(struct dm_dirty_log *log)
  224. {
  225. int r;
  226. struct log_c *lc = log->context;
  227. lc->in_sync_hint = 0;
  228. r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_RESUME,
  229. NULL, 0,
  230. NULL, NULL);
  231. return r;
  232. }
  233. static uint32_t userspace_get_region_size(struct dm_dirty_log *log)
  234. {
  235. struct log_c *lc = log->context;
  236. return lc->region_size;
  237. }
  238. /*
  239. * userspace_is_clean
  240. *
  241. * Check whether a region is clean. If there is any sort of
  242. * failure when consulting the server, we return not clean.
  243. *
  244. * Returns: 1 if clean, 0 otherwise
  245. */
  246. static int userspace_is_clean(struct dm_dirty_log *log, region_t region)
  247. {
  248. int r;
  249. uint64_t region64 = (uint64_t)region;
  250. int64_t is_clean;
  251. size_t rdata_size;
  252. struct log_c *lc = log->context;
  253. rdata_size = sizeof(is_clean);
  254. r = userspace_do_request(lc, lc->uuid, DM_ULOG_IS_CLEAN,
  255. (char *)&region64, sizeof(region64),
  256. (char *)&is_clean, &rdata_size);
  257. return (r) ? 0 : (int)is_clean;
  258. }
  259. /*
  260. * userspace_in_sync
  261. *
  262. * Check if the region is in-sync. If there is any sort
  263. * of failure when consulting the server, we assume that
  264. * the region is not in sync.
  265. *
  266. * If 'can_block' is set, return immediately
  267. *
  268. * Returns: 1 if in-sync, 0 if not-in-sync, -EWOULDBLOCK
  269. */
  270. static int userspace_in_sync(struct dm_dirty_log *log, region_t region,
  271. int can_block)
  272. {
  273. int r;
  274. uint64_t region64 = region;
  275. int64_t in_sync;
  276. size_t rdata_size;
  277. struct log_c *lc = log->context;
  278. /*
  279. * We can never respond directly - even if in_sync_hint is
  280. * set. This is because another machine could see a device
  281. * failure and mark the region out-of-sync. If we don't go
  282. * to userspace to ask, we might think the region is in-sync
  283. * and allow a read to pick up data that is stale. (This is
  284. * very unlikely if a device actually fails; but it is very
  285. * likely if a connection to one device from one machine fails.)
  286. *
  287. * There still might be a problem if the mirror caches the region
  288. * state as in-sync... but then this call would not be made. So,
  289. * that is a mirror problem.
  290. */
  291. if (!can_block)
  292. return -EWOULDBLOCK;
  293. rdata_size = sizeof(in_sync);
  294. r = userspace_do_request(lc, lc->uuid, DM_ULOG_IN_SYNC,
  295. (char *)&region64, sizeof(region64),
  296. (char *)&in_sync, &rdata_size);
  297. return (r) ? 0 : (int)in_sync;
  298. }
  299. static int flush_one_by_one(struct log_c *lc, struct list_head *flush_list)
  300. {
  301. int r = 0;
  302. struct flush_entry *fe;
  303. list_for_each_entry(fe, flush_list, list) {
  304. r = userspace_do_request(lc, lc->uuid, fe->type,
  305. (char *)&fe->region,
  306. sizeof(fe->region),
  307. NULL, NULL);
  308. if (r)
  309. break;
  310. }
  311. return r;
  312. }
  313. static int flush_by_group(struct log_c *lc, struct list_head *flush_list)
  314. {
  315. int r = 0;
  316. int count;
  317. uint32_t type = 0;
  318. struct flush_entry *fe, *tmp_fe;
  319. LIST_HEAD(tmp_list);
  320. uint64_t group[MAX_FLUSH_GROUP_COUNT];
  321. /*
  322. * Group process the requests
  323. */
  324. while (!list_empty(flush_list)) {
  325. count = 0;
  326. list_for_each_entry_safe(fe, tmp_fe, flush_list, list) {
  327. group[count] = fe->region;
  328. count++;
  329. list_del(&fe->list);
  330. list_add(&fe->list, &tmp_list);
  331. type = fe->type;
  332. if (count >= MAX_FLUSH_GROUP_COUNT)
  333. break;
  334. }
  335. r = userspace_do_request(lc, lc->uuid, type,
  336. (char *)(group),
  337. count * sizeof(uint64_t),
  338. NULL, NULL);
  339. if (r) {
  340. /* Group send failed. Attempt one-by-one. */
  341. list_splice_init(&tmp_list, flush_list);
  342. r = flush_one_by_one(lc, flush_list);
  343. break;
  344. }
  345. }
  346. /*
  347. * Must collect flush_entrys that were successfully processed
  348. * as a group so that they will be free'd by the caller.
  349. */
  350. list_splice_init(&tmp_list, flush_list);
  351. return r;
  352. }
  353. /*
  354. * userspace_flush
  355. *
  356. * This function is ok to block.
  357. * The flush happens in two stages. First, it sends all
  358. * clear/mark requests that are on the list. Then it
  359. * tells the server to commit them. This gives the
  360. * server a chance to optimise the commit, instead of
  361. * doing it for every request.
  362. *
  363. * Additionally, we could implement another thread that
  364. * sends the requests up to the server - reducing the
  365. * load on flush. Then the flush would have less in
  366. * the list and be responsible for the finishing commit.
  367. *
  368. * Returns: 0 on success, < 0 on failure
  369. */
  370. static int userspace_flush(struct dm_dirty_log *log)
  371. {
  372. int r = 0;
  373. unsigned long flags;
  374. struct log_c *lc = log->context;
  375. LIST_HEAD(mark_list);
  376. LIST_HEAD(clear_list);
  377. struct flush_entry *fe, *tmp_fe;
  378. spin_lock_irqsave(&lc->flush_lock, flags);
  379. list_splice_init(&lc->mark_list, &mark_list);
  380. list_splice_init(&lc->clear_list, &clear_list);
  381. spin_unlock_irqrestore(&lc->flush_lock, flags);
  382. if (list_empty(&mark_list) && list_empty(&clear_list))
  383. return 0;
  384. r = flush_by_group(lc, &mark_list);
  385. if (r)
  386. goto fail;
  387. r = flush_by_group(lc, &clear_list);
  388. if (r)
  389. goto fail;
  390. r = userspace_do_request(lc, lc->uuid, DM_ULOG_FLUSH,
  391. NULL, 0, NULL, NULL);
  392. fail:
  393. /*
  394. * We can safely remove these entries, even if failure.
  395. * Calling code will receive an error and will know that
  396. * the log facility has failed.
  397. */
  398. list_for_each_entry_safe(fe, tmp_fe, &mark_list, list) {
  399. list_del(&fe->list);
  400. mempool_free(fe, flush_entry_pool);
  401. }
  402. list_for_each_entry_safe(fe, tmp_fe, &clear_list, list) {
  403. list_del(&fe->list);
  404. mempool_free(fe, flush_entry_pool);
  405. }
  406. if (r)
  407. dm_table_event(lc->ti->table);
  408. return r;
  409. }
  410. /*
  411. * userspace_mark_region
  412. *
  413. * This function should avoid blocking unless absolutely required.
  414. * (Memory allocation is valid for blocking.)
  415. */
  416. static void userspace_mark_region(struct dm_dirty_log *log, region_t region)
  417. {
  418. unsigned long flags;
  419. struct log_c *lc = log->context;
  420. struct flush_entry *fe;
  421. /* Wait for an allocation, but _never_ fail */
  422. fe = mempool_alloc(flush_entry_pool, GFP_NOIO);
  423. BUG_ON(!fe);
  424. spin_lock_irqsave(&lc->flush_lock, flags);
  425. fe->type = DM_ULOG_MARK_REGION;
  426. fe->region = region;
  427. list_add(&fe->list, &lc->mark_list);
  428. spin_unlock_irqrestore(&lc->flush_lock, flags);
  429. return;
  430. }
  431. /*
  432. * userspace_clear_region
  433. *
  434. * This function must not block.
  435. * So, the alloc can't block. In the worst case, it is ok to
  436. * fail. It would simply mean we can't clear the region.
  437. * Does nothing to current sync context, but does mean
  438. * the region will be re-sync'ed on a reload of the mirror
  439. * even though it is in-sync.
  440. */
  441. static void userspace_clear_region(struct dm_dirty_log *log, region_t region)
  442. {
  443. unsigned long flags;
  444. struct log_c *lc = log->context;
  445. struct flush_entry *fe;
  446. /*
  447. * If we fail to allocate, we skip the clearing of
  448. * the region. This doesn't hurt us in any way, except
  449. * to cause the region to be resync'ed when the
  450. * device is activated next time.
  451. */
  452. fe = mempool_alloc(flush_entry_pool, GFP_ATOMIC);
  453. if (!fe) {
  454. DMERR("Failed to allocate memory to clear region.");
  455. return;
  456. }
  457. spin_lock_irqsave(&lc->flush_lock, flags);
  458. fe->type = DM_ULOG_CLEAR_REGION;
  459. fe->region = region;
  460. list_add(&fe->list, &lc->clear_list);
  461. spin_unlock_irqrestore(&lc->flush_lock, flags);
  462. return;
  463. }
  464. /*
  465. * userspace_get_resync_work
  466. *
  467. * Get a region that needs recovery. It is valid to return
  468. * an error for this function.
  469. *
  470. * Returns: 1 if region filled, 0 if no work, <0 on error
  471. */
  472. static int userspace_get_resync_work(struct dm_dirty_log *log, region_t *region)
  473. {
  474. int r;
  475. size_t rdata_size;
  476. struct log_c *lc = log->context;
  477. struct {
  478. int64_t i; /* 64-bit for mix arch compatibility */
  479. region_t r;
  480. } pkg;
  481. if (lc->in_sync_hint >= lc->region_count)
  482. return 0;
  483. rdata_size = sizeof(pkg);
  484. r = userspace_do_request(lc, lc->uuid, DM_ULOG_GET_RESYNC_WORK,
  485. NULL, 0,
  486. (char *)&pkg, &rdata_size);
  487. *region = pkg.r;
  488. return (r) ? r : (int)pkg.i;
  489. }
  490. /*
  491. * userspace_set_region_sync
  492. *
  493. * Set the sync status of a given region. This function
  494. * must not fail.
  495. */
  496. static void userspace_set_region_sync(struct dm_dirty_log *log,
  497. region_t region, int in_sync)
  498. {
  499. int r;
  500. struct log_c *lc = log->context;
  501. struct {
  502. region_t r;
  503. int64_t i;
  504. } pkg;
  505. pkg.r = region;
  506. pkg.i = (int64_t)in_sync;
  507. r = userspace_do_request(lc, lc->uuid, DM_ULOG_SET_REGION_SYNC,
  508. (char *)&pkg, sizeof(pkg),
  509. NULL, NULL);
  510. /*
  511. * It would be nice to be able to report failures.
  512. * However, it is easy emough to detect and resolve.
  513. */
  514. return;
  515. }
  516. /*
  517. * userspace_get_sync_count
  518. *
  519. * If there is any sort of failure when consulting the server,
  520. * we assume that the sync count is zero.
  521. *
  522. * Returns: sync count on success, 0 on failure
  523. */
  524. static region_t userspace_get_sync_count(struct dm_dirty_log *log)
  525. {
  526. int r;
  527. size_t rdata_size;
  528. uint64_t sync_count;
  529. struct log_c *lc = log->context;
  530. rdata_size = sizeof(sync_count);
  531. r = userspace_do_request(lc, lc->uuid, DM_ULOG_GET_SYNC_COUNT,
  532. NULL, 0,
  533. (char *)&sync_count, &rdata_size);
  534. if (r)
  535. return 0;
  536. if (sync_count >= lc->region_count)
  537. lc->in_sync_hint = lc->region_count;
  538. return (region_t)sync_count;
  539. }
  540. /*
  541. * userspace_status
  542. *
  543. * Returns: amount of space consumed
  544. */
  545. static int userspace_status(struct dm_dirty_log *log, status_type_t status_type,
  546. char *result, unsigned maxlen)
  547. {
  548. int r = 0;
  549. char *table_args;
  550. size_t sz = (size_t)maxlen;
  551. struct log_c *lc = log->context;
  552. switch (status_type) {
  553. case STATUSTYPE_INFO:
  554. r = userspace_do_request(lc, lc->uuid, DM_ULOG_STATUS_INFO,
  555. NULL, 0,
  556. result, &sz);
  557. if (r) {
  558. sz = 0;
  559. DMEMIT("%s 1 COM_FAILURE", log->type->name);
  560. }
  561. break;
  562. case STATUSTYPE_TABLE:
  563. sz = 0;
  564. table_args = strchr(lc->usr_argv_str, ' ');
  565. BUG_ON(!table_args); /* There will always be a ' ' */
  566. table_args++;
  567. DMEMIT("%s %u %s %s ", log->type->name, lc->usr_argc,
  568. lc->uuid, table_args);
  569. break;
  570. }
  571. return (r) ? 0 : (int)sz;
  572. }
  573. /*
  574. * userspace_is_remote_recovering
  575. *
  576. * Returns: 1 if region recovering, 0 otherwise
  577. */
  578. static int userspace_is_remote_recovering(struct dm_dirty_log *log,
  579. region_t region)
  580. {
  581. int r;
  582. uint64_t region64 = region;
  583. struct log_c *lc = log->context;
  584. static unsigned long long limit;
  585. struct {
  586. int64_t is_recovering;
  587. uint64_t in_sync_hint;
  588. } pkg;
  589. size_t rdata_size = sizeof(pkg);
  590. /*
  591. * Once the mirror has been reported to be in-sync,
  592. * it will never again ask for recovery work. So,
  593. * we can safely say there is not a remote machine
  594. * recovering if the device is in-sync. (in_sync_hint
  595. * must be reset at resume time.)
  596. */
  597. if (region < lc->in_sync_hint)
  598. return 0;
  599. else if (jiffies < limit)
  600. return 1;
  601. limit = jiffies + (HZ / 4);
  602. r = userspace_do_request(lc, lc->uuid, DM_ULOG_IS_REMOTE_RECOVERING,
  603. (char *)&region64, sizeof(region64),
  604. (char *)&pkg, &rdata_size);
  605. if (r)
  606. return 1;
  607. lc->in_sync_hint = pkg.in_sync_hint;
  608. return (int)pkg.is_recovering;
  609. }
  610. static struct dm_dirty_log_type _userspace_type = {
  611. .name = "userspace",
  612. .module = THIS_MODULE,
  613. .ctr = userspace_ctr,
  614. .dtr = userspace_dtr,
  615. .presuspend = userspace_presuspend,
  616. .postsuspend = userspace_postsuspend,
  617. .resume = userspace_resume,
  618. .get_region_size = userspace_get_region_size,
  619. .is_clean = userspace_is_clean,
  620. .in_sync = userspace_in_sync,
  621. .flush = userspace_flush,
  622. .mark_region = userspace_mark_region,
  623. .clear_region = userspace_clear_region,
  624. .get_resync_work = userspace_get_resync_work,
  625. .set_region_sync = userspace_set_region_sync,
  626. .get_sync_count = userspace_get_sync_count,
  627. .status = userspace_status,
  628. .is_remote_recovering = userspace_is_remote_recovering,
  629. };
  630. static int __init userspace_dirty_log_init(void)
  631. {
  632. int r = 0;
  633. flush_entry_pool = mempool_create(100, flush_entry_alloc,
  634. flush_entry_free, NULL);
  635. if (!flush_entry_pool) {
  636. DMWARN("Unable to create flush_entry_pool: No memory.");
  637. return -ENOMEM;
  638. }
  639. r = dm_ulog_tfr_init();
  640. if (r) {
  641. DMWARN("Unable to initialize userspace log communications");
  642. mempool_destroy(flush_entry_pool);
  643. return r;
  644. }
  645. r = dm_dirty_log_type_register(&_userspace_type);
  646. if (r) {
  647. DMWARN("Couldn't register userspace dirty log type");
  648. dm_ulog_tfr_exit();
  649. mempool_destroy(flush_entry_pool);
  650. return r;
  651. }
  652. DMINFO("version " DM_LOG_USERSPACE_VSN " loaded");
  653. return 0;
  654. }
  655. static void __exit userspace_dirty_log_exit(void)
  656. {
  657. dm_dirty_log_type_unregister(&_userspace_type);
  658. dm_ulog_tfr_exit();
  659. mempool_destroy(flush_entry_pool);
  660. DMINFO("version " DM_LOG_USERSPACE_VSN " unloaded");
  661. return;
  662. }
  663. module_init(userspace_dirty_log_init);
  664. module_exit(userspace_dirty_log_exit);
  665. MODULE_DESCRIPTION(DM_NAME " userspace dirty log link");
  666. MODULE_AUTHOR("Jonathan Brassow <dm-devel@redhat.com>");
  667. MODULE_LICENSE("GPL");