dm-log-userspace-base.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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_move(&fe->list, &tmp_list);
  330. type = fe->type;
  331. if (count >= MAX_FLUSH_GROUP_COUNT)
  332. break;
  333. }
  334. r = userspace_do_request(lc, lc->uuid, type,
  335. (char *)(group),
  336. count * sizeof(uint64_t),
  337. NULL, NULL);
  338. if (r) {
  339. /* Group send failed. Attempt one-by-one. */
  340. list_splice_init(&tmp_list, flush_list);
  341. r = flush_one_by_one(lc, flush_list);
  342. break;
  343. }
  344. }
  345. /*
  346. * Must collect flush_entrys that were successfully processed
  347. * as a group so that they will be free'd by the caller.
  348. */
  349. list_splice_init(&tmp_list, flush_list);
  350. return r;
  351. }
  352. /*
  353. * userspace_flush
  354. *
  355. * This function is ok to block.
  356. * The flush happens in two stages. First, it sends all
  357. * clear/mark requests that are on the list. Then it
  358. * tells the server to commit them. This gives the
  359. * server a chance to optimise the commit, instead of
  360. * doing it for every request.
  361. *
  362. * Additionally, we could implement another thread that
  363. * sends the requests up to the server - reducing the
  364. * load on flush. Then the flush would have less in
  365. * the list and be responsible for the finishing commit.
  366. *
  367. * Returns: 0 on success, < 0 on failure
  368. */
  369. static int userspace_flush(struct dm_dirty_log *log)
  370. {
  371. int r = 0;
  372. unsigned long flags;
  373. struct log_c *lc = log->context;
  374. LIST_HEAD(mark_list);
  375. LIST_HEAD(clear_list);
  376. struct flush_entry *fe, *tmp_fe;
  377. spin_lock_irqsave(&lc->flush_lock, flags);
  378. list_splice_init(&lc->mark_list, &mark_list);
  379. list_splice_init(&lc->clear_list, &clear_list);
  380. spin_unlock_irqrestore(&lc->flush_lock, flags);
  381. if (list_empty(&mark_list) && list_empty(&clear_list))
  382. return 0;
  383. r = flush_by_group(lc, &mark_list);
  384. if (r)
  385. goto fail;
  386. r = flush_by_group(lc, &clear_list);
  387. if (r)
  388. goto fail;
  389. r = userspace_do_request(lc, lc->uuid, DM_ULOG_FLUSH,
  390. NULL, 0, NULL, NULL);
  391. fail:
  392. /*
  393. * We can safely remove these entries, even if failure.
  394. * Calling code will receive an error and will know that
  395. * the log facility has failed.
  396. */
  397. list_for_each_entry_safe(fe, tmp_fe, &mark_list, list) {
  398. list_del(&fe->list);
  399. mempool_free(fe, flush_entry_pool);
  400. }
  401. list_for_each_entry_safe(fe, tmp_fe, &clear_list, list) {
  402. list_del(&fe->list);
  403. mempool_free(fe, flush_entry_pool);
  404. }
  405. if (r)
  406. dm_table_event(lc->ti->table);
  407. return r;
  408. }
  409. /*
  410. * userspace_mark_region
  411. *
  412. * This function should avoid blocking unless absolutely required.
  413. * (Memory allocation is valid for blocking.)
  414. */
  415. static void userspace_mark_region(struct dm_dirty_log *log, region_t region)
  416. {
  417. unsigned long flags;
  418. struct log_c *lc = log->context;
  419. struct flush_entry *fe;
  420. /* Wait for an allocation, but _never_ fail */
  421. fe = mempool_alloc(flush_entry_pool, GFP_NOIO);
  422. BUG_ON(!fe);
  423. spin_lock_irqsave(&lc->flush_lock, flags);
  424. fe->type = DM_ULOG_MARK_REGION;
  425. fe->region = region;
  426. list_add(&fe->list, &lc->mark_list);
  427. spin_unlock_irqrestore(&lc->flush_lock, flags);
  428. return;
  429. }
  430. /*
  431. * userspace_clear_region
  432. *
  433. * This function must not block.
  434. * So, the alloc can't block. In the worst case, it is ok to
  435. * fail. It would simply mean we can't clear the region.
  436. * Does nothing to current sync context, but does mean
  437. * the region will be re-sync'ed on a reload of the mirror
  438. * even though it is in-sync.
  439. */
  440. static void userspace_clear_region(struct dm_dirty_log *log, region_t region)
  441. {
  442. unsigned long flags;
  443. struct log_c *lc = log->context;
  444. struct flush_entry *fe;
  445. /*
  446. * If we fail to allocate, we skip the clearing of
  447. * the region. This doesn't hurt us in any way, except
  448. * to cause the region to be resync'ed when the
  449. * device is activated next time.
  450. */
  451. fe = mempool_alloc(flush_entry_pool, GFP_ATOMIC);
  452. if (!fe) {
  453. DMERR("Failed to allocate memory to clear region.");
  454. return;
  455. }
  456. spin_lock_irqsave(&lc->flush_lock, flags);
  457. fe->type = DM_ULOG_CLEAR_REGION;
  458. fe->region = region;
  459. list_add(&fe->list, &lc->clear_list);
  460. spin_unlock_irqrestore(&lc->flush_lock, flags);
  461. return;
  462. }
  463. /*
  464. * userspace_get_resync_work
  465. *
  466. * Get a region that needs recovery. It is valid to return
  467. * an error for this function.
  468. *
  469. * Returns: 1 if region filled, 0 if no work, <0 on error
  470. */
  471. static int userspace_get_resync_work(struct dm_dirty_log *log, region_t *region)
  472. {
  473. int r;
  474. size_t rdata_size;
  475. struct log_c *lc = log->context;
  476. struct {
  477. int64_t i; /* 64-bit for mix arch compatibility */
  478. region_t r;
  479. } pkg;
  480. if (lc->in_sync_hint >= lc->region_count)
  481. return 0;
  482. rdata_size = sizeof(pkg);
  483. r = userspace_do_request(lc, lc->uuid, DM_ULOG_GET_RESYNC_WORK,
  484. NULL, 0,
  485. (char *)&pkg, &rdata_size);
  486. *region = pkg.r;
  487. return (r) ? r : (int)pkg.i;
  488. }
  489. /*
  490. * userspace_set_region_sync
  491. *
  492. * Set the sync status of a given region. This function
  493. * must not fail.
  494. */
  495. static void userspace_set_region_sync(struct dm_dirty_log *log,
  496. region_t region, int in_sync)
  497. {
  498. int r;
  499. struct log_c *lc = log->context;
  500. struct {
  501. region_t r;
  502. int64_t i;
  503. } pkg;
  504. pkg.r = region;
  505. pkg.i = (int64_t)in_sync;
  506. r = userspace_do_request(lc, lc->uuid, DM_ULOG_SET_REGION_SYNC,
  507. (char *)&pkg, sizeof(pkg),
  508. NULL, NULL);
  509. /*
  510. * It would be nice to be able to report failures.
  511. * However, it is easy emough to detect and resolve.
  512. */
  513. return;
  514. }
  515. /*
  516. * userspace_get_sync_count
  517. *
  518. * If there is any sort of failure when consulting the server,
  519. * we assume that the sync count is zero.
  520. *
  521. * Returns: sync count on success, 0 on failure
  522. */
  523. static region_t userspace_get_sync_count(struct dm_dirty_log *log)
  524. {
  525. int r;
  526. size_t rdata_size;
  527. uint64_t sync_count;
  528. struct log_c *lc = log->context;
  529. rdata_size = sizeof(sync_count);
  530. r = userspace_do_request(lc, lc->uuid, DM_ULOG_GET_SYNC_COUNT,
  531. NULL, 0,
  532. (char *)&sync_count, &rdata_size);
  533. if (r)
  534. return 0;
  535. if (sync_count >= lc->region_count)
  536. lc->in_sync_hint = lc->region_count;
  537. return (region_t)sync_count;
  538. }
  539. /*
  540. * userspace_status
  541. *
  542. * Returns: amount of space consumed
  543. */
  544. static int userspace_status(struct dm_dirty_log *log, status_type_t status_type,
  545. char *result, unsigned maxlen)
  546. {
  547. int r = 0;
  548. char *table_args;
  549. size_t sz = (size_t)maxlen;
  550. struct log_c *lc = log->context;
  551. switch (status_type) {
  552. case STATUSTYPE_INFO:
  553. r = userspace_do_request(lc, lc->uuid, DM_ULOG_STATUS_INFO,
  554. NULL, 0,
  555. result, &sz);
  556. if (r) {
  557. sz = 0;
  558. DMEMIT("%s 1 COM_FAILURE", log->type->name);
  559. }
  560. break;
  561. case STATUSTYPE_TABLE:
  562. sz = 0;
  563. table_args = strchr(lc->usr_argv_str, ' ');
  564. BUG_ON(!table_args); /* There will always be a ' ' */
  565. table_args++;
  566. DMEMIT("%s %u %s %s ", log->type->name, lc->usr_argc,
  567. lc->uuid, table_args);
  568. break;
  569. }
  570. return (r) ? 0 : (int)sz;
  571. }
  572. /*
  573. * userspace_is_remote_recovering
  574. *
  575. * Returns: 1 if region recovering, 0 otherwise
  576. */
  577. static int userspace_is_remote_recovering(struct dm_dirty_log *log,
  578. region_t region)
  579. {
  580. int r;
  581. uint64_t region64 = region;
  582. struct log_c *lc = log->context;
  583. static unsigned long long limit;
  584. struct {
  585. int64_t is_recovering;
  586. uint64_t in_sync_hint;
  587. } pkg;
  588. size_t rdata_size = sizeof(pkg);
  589. /*
  590. * Once the mirror has been reported to be in-sync,
  591. * it will never again ask for recovery work. So,
  592. * we can safely say there is not a remote machine
  593. * recovering if the device is in-sync. (in_sync_hint
  594. * must be reset at resume time.)
  595. */
  596. if (region < lc->in_sync_hint)
  597. return 0;
  598. else if (jiffies < limit)
  599. return 1;
  600. limit = jiffies + (HZ / 4);
  601. r = userspace_do_request(lc, lc->uuid, DM_ULOG_IS_REMOTE_RECOVERING,
  602. (char *)&region64, sizeof(region64),
  603. (char *)&pkg, &rdata_size);
  604. if (r)
  605. return 1;
  606. lc->in_sync_hint = pkg.in_sync_hint;
  607. return (int)pkg.is_recovering;
  608. }
  609. static struct dm_dirty_log_type _userspace_type = {
  610. .name = "userspace",
  611. .module = THIS_MODULE,
  612. .ctr = userspace_ctr,
  613. .dtr = userspace_dtr,
  614. .presuspend = userspace_presuspend,
  615. .postsuspend = userspace_postsuspend,
  616. .resume = userspace_resume,
  617. .get_region_size = userspace_get_region_size,
  618. .is_clean = userspace_is_clean,
  619. .in_sync = userspace_in_sync,
  620. .flush = userspace_flush,
  621. .mark_region = userspace_mark_region,
  622. .clear_region = userspace_clear_region,
  623. .get_resync_work = userspace_get_resync_work,
  624. .set_region_sync = userspace_set_region_sync,
  625. .get_sync_count = userspace_get_sync_count,
  626. .status = userspace_status,
  627. .is_remote_recovering = userspace_is_remote_recovering,
  628. };
  629. static int __init userspace_dirty_log_init(void)
  630. {
  631. int r = 0;
  632. flush_entry_pool = mempool_create(100, flush_entry_alloc,
  633. flush_entry_free, NULL);
  634. if (!flush_entry_pool) {
  635. DMWARN("Unable to create flush_entry_pool: No memory.");
  636. return -ENOMEM;
  637. }
  638. r = dm_ulog_tfr_init();
  639. if (r) {
  640. DMWARN("Unable to initialize userspace log communications");
  641. mempool_destroy(flush_entry_pool);
  642. return r;
  643. }
  644. r = dm_dirty_log_type_register(&_userspace_type);
  645. if (r) {
  646. DMWARN("Couldn't register userspace dirty log type");
  647. dm_ulog_tfr_exit();
  648. mempool_destroy(flush_entry_pool);
  649. return r;
  650. }
  651. DMINFO("version " DM_LOG_USERSPACE_VSN " loaded");
  652. return 0;
  653. }
  654. static void __exit userspace_dirty_log_exit(void)
  655. {
  656. dm_dirty_log_type_unregister(&_userspace_type);
  657. dm_ulog_tfr_exit();
  658. mempool_destroy(flush_entry_pool);
  659. DMINFO("version " DM_LOG_USERSPACE_VSN " unloaded");
  660. return;
  661. }
  662. module_init(userspace_dirty_log_init);
  663. module_exit(userspace_dirty_log_exit);
  664. MODULE_DESCRIPTION(DM_NAME " userspace dirty log link");
  665. MODULE_AUTHOR("Jonathan Brassow <dm-devel@redhat.com>");
  666. MODULE_LICENSE("GPL");