Linux Audio

Check our new training course

Loading...
v3.1
  1/*
  2 * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
  3 * Copyright (C) 2006-2008 Red Hat GmbH
  4 *
  5 * This file is released under the GPL.
  6 */
  7
  8#include "dm-exception-store.h"
  9
 10#include <linux/mm.h>
 11#include <linux/pagemap.h>
 12#include <linux/vmalloc.h>
 
 13#include <linux/slab.h>
 14#include <linux/dm-io.h>
 15
 16#define DM_MSG_PREFIX "transient snapshot"
 17
 18/*-----------------------------------------------------------------
 19 * Implementation of the store for non-persistent snapshots.
 20 *---------------------------------------------------------------*/
 21struct transient_c {
 22	sector_t next_free;
 23};
 24
 25static void transient_dtr(struct dm_exception_store *store)
 26{
 27	kfree(store->context);
 28}
 29
 30static int transient_read_metadata(struct dm_exception_store *store,
 31				   int (*callback)(void *callback_context,
 32						   chunk_t old, chunk_t new),
 33				   void *callback_context)
 34{
 35	return 0;
 36}
 37
 38static int transient_prepare_exception(struct dm_exception_store *store,
 39				       struct dm_exception *e)
 40{
 41	struct transient_c *tc = store->context;
 42	sector_t size = get_dev_size(dm_snap_cow(store->snap)->bdev);
 43
 44	if (size < (tc->next_free + store->chunk_size))
 45		return -1;
 46
 47	e->new_chunk = sector_to_chunk(store, tc->next_free);
 48	tc->next_free += store->chunk_size;
 49
 50	return 0;
 51}
 52
 53static void transient_commit_exception(struct dm_exception_store *store,
 54				       struct dm_exception *e,
 55				       void (*callback) (void *, int success),
 56				       void *callback_context)
 57{
 58	/* Just succeed */
 59	callback(callback_context, 1);
 60}
 61
 62static void transient_usage(struct dm_exception_store *store,
 63			    sector_t *total_sectors,
 64			    sector_t *sectors_allocated,
 65			    sector_t *metadata_sectors)
 66{
 67	*sectors_allocated = ((struct transient_c *) store->context)->next_free;
 68	*total_sectors = get_dev_size(dm_snap_cow(store->snap)->bdev);
 69	*metadata_sectors = 0;
 70}
 71
 72static int transient_ctr(struct dm_exception_store *store,
 73			 unsigned argc, char **argv)
 74{
 75	struct transient_c *tc;
 76
 77	tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL);
 78	if (!tc)
 79		return -ENOMEM;
 80
 81	tc->next_free = 0;
 82	store->context = tc;
 83
 84	return 0;
 85}
 86
 87static unsigned transient_status(struct dm_exception_store *store,
 88				 status_type_t status, char *result,
 89				 unsigned maxlen)
 90{
 91	unsigned sz = 0;
 92
 93	switch (status) {
 94	case STATUSTYPE_INFO:
 95		break;
 96	case STATUSTYPE_TABLE:
 97		DMEMIT(" N %llu", (unsigned long long)store->chunk_size);
 98	}
 99
100	return sz;
101}
102
103static struct dm_exception_store_type _transient_type = {
104	.name = "transient",
105	.module = THIS_MODULE,
106	.ctr = transient_ctr,
107	.dtr = transient_dtr,
108	.read_metadata = transient_read_metadata,
109	.prepare_exception = transient_prepare_exception,
110	.commit_exception = transient_commit_exception,
111	.usage = transient_usage,
112	.status = transient_status,
113};
114
115static struct dm_exception_store_type _transient_compat_type = {
116	.name = "N",
117	.module = THIS_MODULE,
118	.ctr = transient_ctr,
119	.dtr = transient_dtr,
120	.read_metadata = transient_read_metadata,
121	.prepare_exception = transient_prepare_exception,
122	.commit_exception = transient_commit_exception,
123	.usage = transient_usage,
124	.status = transient_status,
125};
126
127int dm_transient_snapshot_init(void)
128{
129	int r;
130
131	r = dm_exception_store_type_register(&_transient_type);
132	if (r) {
133		DMWARN("Unable to register transient exception store type");
134		return r;
135	}
136
137	r = dm_exception_store_type_register(&_transient_compat_type);
138	if (r) {
139		DMWARN("Unable to register old-style transient "
140		       "exception store type");
141		dm_exception_store_type_unregister(&_transient_type);
142		return r;
143	}
144
145	return r;
146}
147
148void dm_transient_snapshot_exit(void)
149{
150	dm_exception_store_type_unregister(&_transient_type);
151	dm_exception_store_type_unregister(&_transient_compat_type);
152}
v5.9
  1/*
  2 * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
  3 * Copyright (C) 2006-2008 Red Hat GmbH
  4 *
  5 * This file is released under the GPL.
  6 */
  7
  8#include "dm-exception-store.h"
  9
 10#include <linux/mm.h>
 11#include <linux/pagemap.h>
 12#include <linux/vmalloc.h>
 13#include <linux/export.h>
 14#include <linux/slab.h>
 15#include <linux/dm-io.h>
 16
 17#define DM_MSG_PREFIX "transient snapshot"
 18
 19/*-----------------------------------------------------------------
 20 * Implementation of the store for non-persistent snapshots.
 21 *---------------------------------------------------------------*/
 22struct transient_c {
 23	sector_t next_free;
 24};
 25
 26static void transient_dtr(struct dm_exception_store *store)
 27{
 28	kfree(store->context);
 29}
 30
 31static int transient_read_metadata(struct dm_exception_store *store,
 32				   int (*callback)(void *callback_context,
 33						   chunk_t old, chunk_t new),
 34				   void *callback_context)
 35{
 36	return 0;
 37}
 38
 39static int transient_prepare_exception(struct dm_exception_store *store,
 40				       struct dm_exception *e)
 41{
 42	struct transient_c *tc = store->context;
 43	sector_t size = get_dev_size(dm_snap_cow(store->snap)->bdev);
 44
 45	if (size < (tc->next_free + store->chunk_size))
 46		return -1;
 47
 48	e->new_chunk = sector_to_chunk(store, tc->next_free);
 49	tc->next_free += store->chunk_size;
 50
 51	return 0;
 52}
 53
 54static void transient_commit_exception(struct dm_exception_store *store,
 55				       struct dm_exception *e, int valid,
 56				       void (*callback) (void *, int success),
 57				       void *callback_context)
 58{
 59	/* Just succeed */
 60	callback(callback_context, valid);
 61}
 62
 63static void transient_usage(struct dm_exception_store *store,
 64			    sector_t *total_sectors,
 65			    sector_t *sectors_allocated,
 66			    sector_t *metadata_sectors)
 67{
 68	*sectors_allocated = ((struct transient_c *) store->context)->next_free;
 69	*total_sectors = get_dev_size(dm_snap_cow(store->snap)->bdev);
 70	*metadata_sectors = 0;
 71}
 72
 73static int transient_ctr(struct dm_exception_store *store, char *options)
 
 74{
 75	struct transient_c *tc;
 76
 77	tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL);
 78	if (!tc)
 79		return -ENOMEM;
 80
 81	tc->next_free = 0;
 82	store->context = tc;
 83
 84	return 0;
 85}
 86
 87static unsigned transient_status(struct dm_exception_store *store,
 88				 status_type_t status, char *result,
 89				 unsigned maxlen)
 90{
 91	unsigned sz = 0;
 92
 93	switch (status) {
 94	case STATUSTYPE_INFO:
 95		break;
 96	case STATUSTYPE_TABLE:
 97		DMEMIT(" N %llu", (unsigned long long)store->chunk_size);
 98	}
 99
100	return sz;
101}
102
103static struct dm_exception_store_type _transient_type = {
104	.name = "transient",
105	.module = THIS_MODULE,
106	.ctr = transient_ctr,
107	.dtr = transient_dtr,
108	.read_metadata = transient_read_metadata,
109	.prepare_exception = transient_prepare_exception,
110	.commit_exception = transient_commit_exception,
111	.usage = transient_usage,
112	.status = transient_status,
113};
114
115static struct dm_exception_store_type _transient_compat_type = {
116	.name = "N",
117	.module = THIS_MODULE,
118	.ctr = transient_ctr,
119	.dtr = transient_dtr,
120	.read_metadata = transient_read_metadata,
121	.prepare_exception = transient_prepare_exception,
122	.commit_exception = transient_commit_exception,
123	.usage = transient_usage,
124	.status = transient_status,
125};
126
127int dm_transient_snapshot_init(void)
128{
129	int r;
130
131	r = dm_exception_store_type_register(&_transient_type);
132	if (r) {
133		DMWARN("Unable to register transient exception store type");
134		return r;
135	}
136
137	r = dm_exception_store_type_register(&_transient_compat_type);
138	if (r) {
139		DMWARN("Unable to register old-style transient "
140		       "exception store type");
141		dm_exception_store_type_unregister(&_transient_type);
142		return r;
143	}
144
145	return r;
146}
147
148void dm_transient_snapshot_exit(void)
149{
150	dm_exception_store_type_unregister(&_transient_type);
151	dm_exception_store_type_unregister(&_transient_compat_type);
152}