Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72d94861 authored by Alasdair G Kergon's avatar Alasdair G Kergon Committed by Linus Torvalds
Browse files

[PATCH] dm: improve error message consistency



Tidy device-mapper error messages to include context information
automatically.

Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 5c6bd75d
Loading
Loading
Loading
Loading
+28 −28
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@

#include "dm.h"

#define PFX	"crypt: "
#define DM_MSG_PREFIX "crypt"

/*
 * per bio private data
@@ -125,19 +125,19 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,
	u8 *salt;

	if (opts == NULL) {
		ti->error = PFX "Digest algorithm missing for ESSIV mode";
		ti->error = "Digest algorithm missing for ESSIV mode";
		return -EINVAL;
	}

	/* Hash the cipher key with the given hash algorithm */
	hash_tfm = crypto_alloc_tfm(opts, CRYPTO_TFM_REQ_MAY_SLEEP);
	if (hash_tfm == NULL) {
		ti->error = PFX "Error initializing ESSIV hash";
		ti->error = "Error initializing ESSIV hash";
		return -EINVAL;
	}

	if (crypto_tfm_alg_type(hash_tfm) != CRYPTO_ALG_TYPE_DIGEST) {
		ti->error = PFX "Expected digest algorithm for ESSIV hash";
		ti->error = "Expected digest algorithm for ESSIV hash";
		crypto_free_tfm(hash_tfm);
		return -EINVAL;
	}
@@ -145,7 +145,7 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,
	saltsize = crypto_tfm_alg_digestsize(hash_tfm);
	salt = kmalloc(saltsize, GFP_KERNEL);
	if (salt == NULL) {
		ti->error = PFX "Error kmallocing salt storage in ESSIV";
		ti->error = "Error kmallocing salt storage in ESSIV";
		crypto_free_tfm(hash_tfm);
		return -ENOMEM;
	}
@@ -159,20 +159,20 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,
	                             CRYPTO_TFM_MODE_ECB |
	                             CRYPTO_TFM_REQ_MAY_SLEEP);
	if (essiv_tfm == NULL) {
		ti->error = PFX "Error allocating crypto tfm for ESSIV";
		ti->error = "Error allocating crypto tfm for ESSIV";
		kfree(salt);
		return -EINVAL;
	}
	if (crypto_tfm_alg_blocksize(essiv_tfm)
	    != crypto_tfm_alg_ivsize(cc->tfm)) {
		ti->error = PFX "Block size of ESSIV cipher does "
		ti->error = "Block size of ESSIV cipher does "
			        "not match IV size of block cipher";
		crypto_free_tfm(essiv_tfm);
		kfree(salt);
		return -EINVAL;
	}
	if (crypto_cipher_setkey(essiv_tfm, salt, saltsize) < 0) {
		ti->error = PFX "Failed to set key for ESSIV cipher";
		ti->error = "Failed to set key for ESSIV cipher";
		crypto_free_tfm(essiv_tfm);
		kfree(salt);
		return -EINVAL;
@@ -521,7 +521,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
	unsigned long long tmpll;

	if (argc != 5) {
		ti->error = PFX "Not enough arguments";
		ti->error = "Not enough arguments";
		return -EINVAL;
	}

@@ -532,21 +532,21 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
	ivmode = strsep(&ivopts, ":");

	if (tmp)
		DMWARN(PFX "Unexpected additional cipher options");
		DMWARN("Unexpected additional cipher options");

	key_size = strlen(argv[1]) >> 1;

	cc = kmalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL);
	if (cc == NULL) {
		ti->error =
			PFX "Cannot allocate transparent encryption context";
			"Cannot allocate transparent encryption context";
		return -ENOMEM;
	}

	cc->key_size = key_size;
	if ((!key_size && strcmp(argv[1], "-") != 0) ||
	    (key_size && crypt_decode_key(cc->key, argv[1], key_size) < 0)) {
		ti->error = PFX "Error decoding key";
		ti->error = "Error decoding key";
		goto bad1;
	}

@@ -562,22 +562,22 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
	else if (strcmp(chainmode, "ecb") == 0)
		crypto_flags = CRYPTO_TFM_MODE_ECB;
	else {
		ti->error = PFX "Unknown chaining mode";
		ti->error = "Unknown chaining mode";
		goto bad1;
	}

	if (crypto_flags != CRYPTO_TFM_MODE_ECB && !ivmode) {
		ti->error = PFX "This chaining mode requires an IV mechanism";
		ti->error = "This chaining mode requires an IV mechanism";
		goto bad1;
	}

	tfm = crypto_alloc_tfm(cipher, crypto_flags | CRYPTO_TFM_REQ_MAY_SLEEP);
	if (!tfm) {
		ti->error = PFX "Error allocating crypto tfm";
		ti->error = "Error allocating crypto tfm";
		goto bad1;
	}
	if (crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER) {
		ti->error = PFX "Expected cipher algorithm";
		ti->error = "Expected cipher algorithm";
		goto bad2;
	}

@@ -595,7 +595,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
	else if (strcmp(ivmode, "essiv") == 0)
		cc->iv_gen_ops = &crypt_iv_essiv_ops;
	else {
		ti->error = PFX "Invalid IV mode";
		ti->error = "Invalid IV mode";
		goto bad2;
	}

@@ -610,7 +610,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
	else {
		cc->iv_size = 0;
		if (cc->iv_gen_ops) {
			DMWARN(PFX "Selected cipher does not support IVs");
			DMWARN("Selected cipher does not support IVs");
			if (cc->iv_gen_ops->dtr)
				cc->iv_gen_ops->dtr(cc);
			cc->iv_gen_ops = NULL;
@@ -619,36 +619,36 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)

	cc->io_pool = mempool_create_slab_pool(MIN_IOS, _crypt_io_pool);
	if (!cc->io_pool) {
		ti->error = PFX "Cannot allocate crypt io mempool";
		ti->error = "Cannot allocate crypt io mempool";
		goto bad3;
	}

	cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0);
	if (!cc->page_pool) {
		ti->error = PFX "Cannot allocate page mempool";
		ti->error = "Cannot allocate page mempool";
		goto bad4;
	}

	if (tfm->crt_cipher.cit_setkey(tfm, cc->key, key_size) < 0) {
		ti->error = PFX "Error setting key";
		ti->error = "Error setting key";
		goto bad5;
	}

	if (sscanf(argv[2], "%llu", &tmpll) != 1) {
		ti->error = PFX "Invalid iv_offset sector";
		ti->error = "Invalid iv_offset sector";
		goto bad5;
	}
	cc->iv_offset = tmpll;

	if (sscanf(argv[4], "%llu", &tmpll) != 1) {
		ti->error = PFX "Invalid device sector";
		ti->error = "Invalid device sector";
		goto bad5;
	}
	cc->start = tmpll;

	if (dm_get_device(ti, argv[3], cc->start, ti->len,
	                  dm_table_get_mode(ti->table), &cc->dev)) {
		ti->error = PFX "Device lookup failed";
		ti->error = "Device lookup failed";
		goto bad5;
	}

@@ -657,7 +657,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
			*(ivopts - 1) = ':';
		cc->iv_mode = kmalloc(strlen(ivmode) + 1, GFP_KERNEL);
		if (!cc->iv_mode) {
			ti->error = PFX "Error kmallocing iv_mode string";
			ti->error = "Error kmallocing iv_mode string";
			goto bad5;
		}
		strcpy(cc->iv_mode, ivmode);
@@ -918,13 +918,13 @@ static int __init dm_crypt_init(void)
	_kcryptd_workqueue = create_workqueue("kcryptd");
	if (!_kcryptd_workqueue) {
		r = -ENOMEM;
		DMERR(PFX "couldn't create kcryptd");
		DMERR("couldn't create kcryptd");
		goto bad1;
	}

	r = dm_register_target(&crypt_target);
	if (r < 0) {
		DMERR(PFX "register failed %d", r);
		DMERR("register failed %d", r);
		goto bad2;
	}

@@ -942,7 +942,7 @@ static void __exit dm_crypt_exit(void)
	int r = dm_unregister_target(&crypt_target);

	if (r < 0)
		DMERR(PFX "unregister failed %d", r);
		DMERR("unregister failed %d", r);

	destroy_workqueue(_kcryptd_workqueue);
	kmem_cache_destroy(_crypt_io_pool);
+21 −19
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>

#define DM_MSG_PREFIX "multipath emc"

struct emc_handler {
	spinlock_t lock;

@@ -66,7 +68,7 @@ static struct bio *get_failover_bio(struct path *path, unsigned data_size)

	bio = bio_alloc(GFP_ATOMIC, 1);
	if (!bio) {
		DMERR("dm-emc: get_failover_bio: bio_alloc() failed.");
		DMERR("get_failover_bio: bio_alloc() failed.");
		return NULL;
	}

@@ -78,13 +80,13 @@ static struct bio *get_failover_bio(struct path *path, unsigned data_size)

	page = alloc_page(GFP_ATOMIC);
	if (!page) {
		DMERR("dm-emc: get_failover_bio: alloc_page() failed.");
		DMERR("get_failover_bio: alloc_page() failed.");
		bio_put(bio);
		return NULL;
	}

	if (bio_add_page(bio, page, data_size, 0) != data_size) {
		DMERR("dm-emc: get_failover_bio: alloc_page() failed.");
		DMERR("get_failover_bio: alloc_page() failed.");
		__free_page(page);
		bio_put(bio);
		return NULL;
@@ -103,7 +105,7 @@ static struct request *get_failover_req(struct emc_handler *h,
	/* FIXME: Figure out why it fails with GFP_ATOMIC. */
	rq = blk_get_request(q, WRITE, __GFP_WAIT);
	if (!rq) {
		DMERR("dm-emc: get_failover_req: blk_get_request failed");
		DMERR("get_failover_req: blk_get_request failed");
		return NULL;
	}

@@ -160,7 +162,7 @@ static struct request *emc_trespass_get(struct emc_handler *h,

	bio = get_failover_bio(path, data_size);
	if (!bio) {
		DMERR("dm-emc: emc_trespass_get: no bio");
		DMERR("emc_trespass_get: no bio");
		return NULL;
	}

@@ -173,7 +175,7 @@ static struct request *emc_trespass_get(struct emc_handler *h,
	/* get request for block layer packet command */
	rq = get_failover_req(h, bio, path);
	if (!rq) {
		DMERR("dm-emc: emc_trespass_get: no rq");
		DMERR("emc_trespass_get: no rq");
		free_bio(bio);
		return NULL;
	}
@@ -200,18 +202,18 @@ static void emc_pg_init(struct hw_handler *hwh, unsigned bypassed,
	 * initial state passed into us and then get an update here.
	 */
	if (!q) {
		DMINFO("dm-emc: emc_pg_init: no queue");
		DMINFO("emc_pg_init: no queue");
		goto fail_path;
	}

	/* FIXME: The request should be pre-allocated. */
	rq = emc_trespass_get(hwh->context, path);
	if (!rq) {
		DMERR("dm-emc: emc_pg_init: no rq");
		DMERR("emc_pg_init: no rq");
		goto fail_path;
	}

	DMINFO("dm-emc: emc_pg_init: sending switch-over command");
	DMINFO("emc_pg_init: sending switch-over command");
	elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 1);
	return;

@@ -241,18 +243,18 @@ static int emc_create(struct hw_handler *hwh, unsigned argc, char **argv)
		hr = 0;
		short_trespass = 0;
	} else if (argc != 2) {
		DMWARN("dm-emc hwhandler: incorrect number of arguments");
		DMWARN("incorrect number of arguments");
		return -EINVAL;
	} else {
		if ((sscanf(argv[0], "%u", &short_trespass) != 1)
			|| (short_trespass > 1)) {
			DMWARN("dm-emc: invalid trespass mode selected");
			DMWARN("invalid trespass mode selected");
			return -EINVAL;
		}

		if ((sscanf(argv[1], "%u", &hr) != 1)
			|| (hr > 1)) {
			DMWARN("dm-emc: invalid honor reservation flag selected");
			DMWARN("invalid honor reservation flag selected");
			return -EINVAL;
		}
	}
@@ -264,14 +266,14 @@ static int emc_create(struct hw_handler *hwh, unsigned argc, char **argv)
	hwh->context = h;

	if ((h->short_trespass = short_trespass))
		DMWARN("dm-emc: short trespass command will be send");
		DMWARN("short trespass command will be send");
	else
		DMWARN("dm-emc: long trespass command will be send");
		DMWARN("long trespass command will be send");

	if ((h->hr = hr))
		DMWARN("dm-emc: honor reservation bit will be set");
		DMWARN("honor reservation bit will be set");
	else
		DMWARN("dm-emc: honor reservation bit will not be set (default)");
		DMWARN("honor reservation bit will not be set (default)");

	return 0;
}
@@ -336,9 +338,9 @@ static int __init dm_emc_init(void)
	int r = dm_register_hw_handler(&emc_hwh);

	if (r < 0)
		DMERR("emc: register failed %d", r);
		DMERR("register failed %d", r);

	DMINFO("dm-emc version 0.0.3 loaded");
	DMINFO("version 0.0.3 loaded");

	return r;
}
@@ -348,7 +350,7 @@ static void __exit dm_emc_exit(void)
	int r = dm_unregister_hw_handler(&emc_hwh);

	if (r < 0)
		DMERR("emc: unregister failed %d", r);
		DMERR("unregister failed %d", r);
}

module_init(dm_emc_init);
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
#include <linux/vmalloc.h>
#include <linux/slab.h>

#define DM_MSG_PREFIX "snapshots"

/*-----------------------------------------------------------------
 * Persistent snapshots, by persistent we mean that the snapshot
 * will survive a reboot.
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <asm/uaccess.h>

#define DM_MSG_PREFIX "ioctl"
#define DM_DRIVER_EMAIL "dm-devel@redhat.com"

/*-----------------------------------------------------------------
+5 −3
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@
#include <linux/bio.h>
#include <linux/slab.h>

#define DM_MSG_PREFIX "linear"

/*
 * Linear: maps a linear range of a device.
 */
@@ -29,7 +31,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
	unsigned long long tmp;

	if (argc != 2) {
		ti->error = "dm-linear: Invalid argument count";
		ti->error = "Invalid argument count";
		return -EINVAL;
	}

@@ -111,7 +113,7 @@ int __init dm_linear_init(void)
	int r = dm_register_target(&linear_target);

	if (r < 0)
		DMERR("linear: register failed %d", r);
		DMERR("register failed %d", r);

	return r;
}
@@ -121,5 +123,5 @@ void dm_linear_exit(void)
	int r = dm_unregister_target(&linear_target);

	if (r < 0)
		DMERR("linear: unregister failed %d", r);
		DMERR("unregister failed %d", r);
}
Loading