/* * This limit on the number of mark and clear request is, to a degree, * arbitrary. However, there is some basis for the choice in the limits * imposed on the size of data payload by dm-log-userspace-transfer.c: * dm_consult_userspace().
*/ #define MAX_FLUSH_GROUP_COUNT 32
/* * Mark and clear requests are held until a flush is issued * so that we can group, and thereby limit, the amount of * network traffic between kernel and userspace. The 'flush_lock' * is used to protect these lists.
*/
spinlock_t flush_lock; struct list_head mark_list; struct list_head clear_list;
/* * in_sync_hint gets set when doing is_remote_recovering. It * represents the first region that needs recovery. IOW, the * first zero bit of sync_bits. This can be useful for to limit * traffic for calls like is_remote_recovering and get_resync_work, * but be take care in its use for anything else.
*/
uint64_t in_sync_hint;
/* * Workqueue for flush of clear region requests.
*/ struct workqueue_struct *dmlog_wq; struct delayed_work flush_log_work;
atomic_t sched_flush;
/* * Combine userspace flush and mark requests for efficiency.
*/
uint32_t integrated_flush;
mempool_t flush_entry_pool;
};
staticstruct kmem_cache *_flush_entry_cache;
staticint userspace_do_request(struct log_c *lc, constchar *uuid, int request_type, char *data, size_t data_size, char *rdata, size_t *rdata_size)
{ int r;
/* * If the server isn't there, -ESRCH is returned, * and we must keep trying until the server is * restored.
*/
retry:
r = dm_consult_userspace(uuid, lc->luid, request_type, data,
data_size, rdata, rdata_size);
if (r != -ESRCH) return r;
DMERR(" Userspace log server not found."); while (1) {
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(2*HZ);
DMWARN("Attempting to contact userspace log server...");
r = dm_consult_userspace(uuid, lc->luid, DM_ULOG_CTR,
lc->usr_argv_str,
strlen(lc->usr_argv_str) + 1,
NULL, NULL); if (!r) break;
}
DMINFO("Reconnected to userspace log server... DM_ULOG_CTR complete");
r = dm_consult_userspace(uuid, lc->luid, DM_ULOG_RESUME, NULL,
0, NULL, NULL); if (!r) goto retry;
DMERR("Error trying to resume userspace log: %d", r);
return -ESRCH;
}
staticint build_constructor_string(struct dm_target *ti, unsignedint argc, char **argv, char **ctr_str)
{ int i, str_size; char *str = NULL;
*ctr_str = NULL;
/* * Determine overall size of the string.
*/ for (i = 0, str_size = 0; i < argc; i++)
str_size += strlen(argv[i]) + 1; /* +1 for space between args */
str_size += 20; /* Max number of chars in a printed u64 number */
str = kzalloc(str_size, GFP_KERNEL); if (!str) {
DMWARN("Unable to allocate memory for constructor string"); return -ENOMEM;
}
str_size = sprintf(str, "%llu", (unsignedlonglong)ti->len); for (i = 0; i < argc; i++)
str_size += sprintf(str + str_size, " %s", argv[i]);
r = userspace_do_request(lc, lc->uuid, DM_ULOG_FLUSH, NULL, 0, NULL, NULL);
if (r)
dm_table_event(lc->ti->table);
}
/* * userspace_ctr * * argv contains: * <UUID> [integrated_flush] <other args> * Where 'other args' are the userspace implementation-specific log * arguments. * * Example: * <UUID> [integrated_flush] clustered-disk <arg count> <log dev> * <region_size> [[no]sync] * * This module strips off the <UUID> and uses it for identification * purposes when communicating with userspace about a log. * * If integrated_flush is defined, the kernel combines flush * and mark requests. * * The rest of the line, beginning with 'clustered-disk', is passed * to the userspace ctr function.
*/ staticint userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti, unsignedint argc, char **argv)
{ int r = 0; int str_size; char *ctr_str = NULL; struct log_c *lc = NULL;
uint64_t rdata;
size_t rdata_size = sizeof(rdata); char *devices_rdata = NULL;
size_t devices_rdata_size = DM_NAME_LEN;
if (argc < 3) {
DMWARN("Too few arguments to userspace dirty log"); return -EINVAL;
}
lc = kzalloc(sizeof(*lc), GFP_KERNEL); if (!lc) {
DMWARN("Unable to allocate userspace log context."); return -ENOMEM;
}
/* The ptr value is sufficient for local unique id */
lc->luid = (unsignedlong)lc;
lc->ti = ti;
if (strlen(argv[0]) > (DM_UUID_LEN - 1)) {
DMWARN("UUID argument too long.");
kfree(lc); return -EINVAL;
}
devices_rdata = kzalloc(devices_rdata_size, GFP_KERNEL); if (!devices_rdata) {
DMERR("Failed to allocate memory for device information");
r = -ENOMEM; goto out;
}
r = mempool_init_slab_pool(&lc->flush_entry_pool, FLUSH_ENTRY_POOL_SIZE,
_flush_entry_cache); if (r) {
DMERR("Failed to create flush_entry_pool"); goto out;
}
/* * Send table string and get back any opened device.
*/
r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_CTR,
ctr_str, str_size,
devices_rdata, &devices_rdata_size);
if (r < 0) { if (r == -ESRCH)
DMERR("Userspace log server not found"); else
DMERR("Userspace log server failed to create log"); goto out;
}
/* Since the region size does not change, get it now */
rdata_size = sizeof(rdata);
r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_GET_REGION_SIZE,
NULL, 0, (char *)&rdata, &rdata_size);
if (r) {
DMERR("Failed to get region size of dirty log"); goto out;
}
if (devices_rdata_size) { if (devices_rdata[devices_rdata_size - 1] != '\0') {
DMERR("DM_ULOG_CTR device return string not properly terminated");
r = -EINVAL; goto out;
}
r = dm_get_device(ti, devices_rdata,
dm_table_get_mode(ti->table), &lc->log_dev); if (r)
DMERR("Failed to register %s with device-mapper",
devices_rdata);
}
if (lc->integrated_flush) {
lc->dmlog_wq = alloc_workqueue("dmlogd", WQ_MEM_RECLAIM, 0); if (!lc->dmlog_wq) {
DMERR("couldn't start dmlogd");
r = -ENOMEM; goto out;
}
/* * userspace_is_clean * * Check whether a region is clean. If there is any sort of * failure when consulting the server, we return not clean. * * Returns: 1 if clean, 0 otherwise
*/ staticint userspace_is_clean(struct dm_dirty_log *log, region_t region)
{ int r;
uint64_t region64 = (uint64_t)region;
int64_t is_clean;
size_t rdata_size; struct log_c *lc = log->context;
/* * userspace_in_sync * * Check if the region is in-sync. If there is any sort * of failure when consulting the server, we assume that * the region is not in sync. * * If 'can_block' is set, return immediately * * Returns: 1 if in-sync, 0 if not-in-sync, -EWOULDBLOCK
*/ staticint userspace_in_sync(struct dm_dirty_log *log, region_t region, int can_block)
{ int r;
uint64_t region64 = region;
int64_t in_sync;
size_t rdata_size; struct log_c *lc = log->context;
/* * We can never respond directly - even if in_sync_hint is * set. This is because another machine could see a device * failure and mark the region out-of-sync. If we don't go * to userspace to ask, we might think the region is in-sync * and allow a read to pick up data that is stale. (This is * very unlikely if a device actually fails; but it is very * likely if a connection to one device from one machine fails.) * * There still might be a problem if the mirror caches the region * state as in-sync... but then this call would not be made. So, * that is a mirror problem.
*/ if (!can_block) return -EWOULDBLOCK;
type = fe->type; if (count >= MAX_FLUSH_GROUP_COUNT) break;
}
if (flush_with_payload) {
r = userspace_do_request(lc, lc->uuid, DM_ULOG_FLUSH,
(char *)(group),
count * sizeof(uint64_t),
NULL, NULL); /* * Integrated flush failed.
*/ if (r) break;
} else {
r = userspace_do_request(lc, lc->uuid, type,
(char *)(group),
count * sizeof(uint64_t),
NULL, NULL); if (r) { /* * Group send failed. Attempt one-by-one.
*/
list_splice_init(&tmp_list, flush_list);
r = flush_one_by_one(lc, flush_list); break;
}
}
}
/* * Must collect flush_entrys that were successfully processed * as a group so that they will be free'd by the caller.
*/
list_splice_init(&tmp_list, flush_list);
return r;
}
/* * userspace_flush * * This function is ok to block. * The flush happens in two stages. First, it sends all * clear/mark requests that are on the list. Then it * tells the server to commit them. This gives the * server a chance to optimise the commit, instead of * doing it for every request. * * Additionally, we could implement another thread that * sends the requests up to the server - reducing the * load on flush. Then the flush would have less in * the list and be responsible for the finishing commit. * * Returns: 0 on success, < 0 on failure
*/ staticint userspace_flush(struct dm_dirty_log *log)
{ int r = 0; unsignedlong flags; struct log_c *lc = log->context;
LIST_HEAD(mark_list);
LIST_HEAD(clear_list); int mark_list_is_empty; int clear_list_is_empty; struct dm_dirty_log_flush_entry *fe, *tmp_fe;
mempool_t *flush_entry_pool = &lc->flush_entry_pool;
if (mark_list_is_empty && clear_list_is_empty) return 0;
r = flush_by_group(lc, &clear_list, 0); if (r) goto out;
if (!lc->integrated_flush) {
r = flush_by_group(lc, &mark_list, 0); if (r) goto out;
r = userspace_do_request(lc, lc->uuid, DM_ULOG_FLUSH,
NULL, 0, NULL, NULL); goto out;
}
/* * Send integrated flush request with mark_list as payload.
*/
r = flush_by_group(lc, &mark_list, 1); if (r) goto out;
if (mark_list_is_empty && !atomic_read(&lc->sched_flush)) { /* * When there are only clear region requests, * we schedule a flush in the future.
*/
queue_delayed_work(lc->dmlog_wq, &lc->flush_log_work, 3 * HZ);
atomic_set(&lc->sched_flush, 1);
} else { /* * Cancel pending flush because we * have already flushed in mark_region.
*/
cancel_delayed_work(&lc->flush_log_work);
atomic_set(&lc->sched_flush, 0);
}
out: /* * We can safely remove these entries, even after failure. * Calling code will receive an error and will know that * the log facility has failed.
*/
list_for_each_entry_safe(fe, tmp_fe, &mark_list, list) {
list_del(&fe->list);
mempool_free(fe, flush_entry_pool);
}
list_for_each_entry_safe(fe, tmp_fe, &clear_list, list) {
list_del(&fe->list);
mempool_free(fe, flush_entry_pool);
}
if (r)
dm_table_event(lc->ti->table);
return r;
}
/* * userspace_mark_region * * This function should avoid blocking unless absolutely required. * (Memory allocation is valid for blocking.)
*/ staticvoid userspace_mark_region(struct dm_dirty_log *log, region_t region)
{ unsignedlong flags; struct log_c *lc = log->context; struct dm_dirty_log_flush_entry *fe;
/* Wait for an allocation, but _never_ fail */
fe = mempool_alloc(&lc->flush_entry_pool, GFP_NOIO);
BUG_ON(!fe);
/* * userspace_clear_region * * This function must not block. * So, the alloc can't block. In the worst case, it is ok to * fail. It would simply mean we can't clear the region. * Does nothing to current sync context, but does mean * the region will be re-sync'ed on a reload of the mirror * even though it is in-sync.
*/ staticvoid userspace_clear_region(struct dm_dirty_log *log, region_t region)
{ unsignedlong flags; struct log_c *lc = log->context; struct dm_dirty_log_flush_entry *fe;
/* * If we fail to allocate, we skip the clearing of * the region. This doesn't hurt us in any way, except * to cause the region to be resync'ed when the * device is activated next time.
*/
fe = mempool_alloc(&lc->flush_entry_pool, GFP_ATOMIC); if (!fe) {
DMERR("Failed to allocate memory to clear region."); return;
}
/* * userspace_get_resync_work * * Get a region that needs recovery. It is valid to return * an error for this function. * * Returns: 1 if region filled, 0 if no work, <0 on error
*/ staticint userspace_get_resync_work(struct dm_dirty_log *log, region_t *region)
{ int r;
size_t rdata_size; struct log_c *lc = log->context; struct {
int64_t i; /* 64-bit for mix arch compatibility */
region_t r;
} pkg;
if (lc->in_sync_hint >= lc->region_count) return 0;
/* * userspace_set_region_sync * * Set the sync status of a given region. This function * must not fail.
*/ staticvoid userspace_set_region_sync(struct dm_dirty_log *log,
region_t region, int in_sync)
{ struct log_c *lc = log->context; struct {
region_t r;
int64_t i;
} pkg;
/* * It would be nice to be able to report failures. * However, it is easy enough to detect and resolve.
*/
}
/* * userspace_get_sync_count * * If there is any sort of failure when consulting the server, * we assume that the sync count is zero. * * Returns: sync count on success, 0 on failure
*/ static region_t userspace_get_sync_count(struct dm_dirty_log *log)
{ int r;
size_t rdata_size;
uint64_t sync_count; struct log_c *lc = log->context;
/* * Once the mirror has been reported to be in-sync, * it will never again ask for recovery work. So, * we can safely say there is not a remote machine * recovering if the device is in-sync. (in_sync_hint * must be reset at resume time.)
*/ if (region < lc->in_sync_hint) return 0; elseif (time_after(limit, jiffies)) return 1;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.