master - dev-io: open device read-only to obtain readahead value
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c8591b2ac7c99e...
Commit: c8591b2ac7c99ea43e7f94f3dfb183019c2fed6e
Parent: 6fc4c99b2fc745b0167520f9395e9e2e39c162e8
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Jun 25 11:34:21 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jun 25 11:55:37 2012 +0200
dev-io: open device read-only to obtain readahead value
There's no need to have the device open RW while obtaining the readahead value.
The RW open used before caused the CHANGE udev event to be generated if the
WATCH udev rule was set for the underlying device (and that is normally the
case both for non-dm and dm devices by default).
This did not cause any problems before since we were not interested in
*underlying* devices. However, with upcoming changes (autoactivation), we're
watching for events on underlying devices marked as PVs and such a spurious
event could cause the autoactivation code to be triggered. So when trying
to deactivate the volume, we could end up with immediate activation just after
that because of the CHANGE event originated in the WATCH udev rule since the
underlying device was open RW during the deactivation process.
Though maybe a better solution would be to completely filter such spurious
events out of the autoactivation process somehow, it's still useful if there
are as least spurious events generated as possible in the system itself.
---
WHATS_NEW | 1 +
lib/device/dev-io.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 90157c8..9479d6d 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.97 -
===============================
+ Open device read-only to obtain readahead value.
Fix lvconvert error path NULL pointer dereference.
Check for create_instance() fail in pvscan_lvmetad_single().
Use 64bit math for reserved memory and stack.
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index eecc759..3bb9d65 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -282,7 +282,7 @@ static int _dev_read_ahead_dev(struct device *dev, uint32_t *read_ahead)
return 1;
}
- if (!dev_open(dev))
+ if (!dev_open_readonly(dev))
return_0;
if (ioctl(dev->fd, BLKRAGET, &read_ahead_long) < 0) {
11 years, 10 months
master - cleanup: use dev_t type
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6fc4c99b2fc745...
Commit: 6fc4c99b2fc745b0167520f9395e9e2e39c162e8
Parent: 6bd3864b41fa1cb8e2763185ff860d320c45930f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jun 21 12:55:30 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Jun 22 13:50:21 2012 +0200
cleanup: use dev_t type
---
libdm/libdm-deptree.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c
index 6b428d6..91bafe5 100644
--- a/libdm/libdm-deptree.c
+++ b/libdm/libdm-deptree.c
@@ -462,7 +462,7 @@ static struct dm_tree_node *_create_dm_tree_node(struct dm_tree *dtree,
uint16_t udev_flags)
{
struct dm_tree_node *node;
- uint64_t dev;
+ dev_t dev;
if (!(node = dm_pool_zalloc(dtree->mem, sizeof(*node)))) {
log_error("_create_dm_tree_node alloc failed");
@@ -506,7 +506,7 @@ static struct dm_tree_node *_create_dm_tree_node(struct dm_tree *dtree,
static struct dm_tree_node *_find_dm_tree_node(struct dm_tree *dtree,
uint32_t major, uint32_t minor)
{
- uint64_t dev = MKDEV(major, minor);
+ dev_t dev = MKDEV(major, minor);
return dm_hash_lookup_binary(dtree->devs, (const char *) &dev,
sizeof(dev));
11 years, 10 months
master - thin: fix lvconvert error path NULL dereference
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6bd3864b41fa1c...
Commit: 6bd3864b41fa1cb8e2763185ff860d320c45930f
Parent: e9f9c6be26bb9c40269ebad6250e1a5b4759e74f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Jun 5 14:55:00 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Jun 22 13:50:21 2012 +0200
thin: fix lvconvert error path NULL dereference
For printing the name, use given command line parameter.
---
WHATS_NEW | 1 +
tools/lvconvert.c | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index f1216ff..90157c8 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.97 -
===============================
+ Fix lvconvert error path NULL pointer dereference.
Check for create_instance() fail in pvscan_lvmetad_single().
Use 64bit math for reserved memory and stack.
Add tests for kernel_send() errors in cmirrod.
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 39e196b..074821d 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1841,8 +1841,8 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
lp->pool_data_lv_name);
if (!pool_lv) {
- log_error("Can't find pool logical volume %s.", pool_lv->name);
- goto_out;
+ log_error("Can't find pool logical volume %s.", lp->lv_name);
+ return 0;
}
if ((pool_lv != metadata_lv)) {
11 years, 10 months
master - lvmetad: check for fid existance
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e9f9c6be26bb9c...
Commit: e9f9c6be26bb9c40269ebad6250e1a5b4759e74f
Parent: 2539769356cd73ffe6ff7abd9f9c3208ff24ee8b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jun 21 13:43:55 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Jun 22 13:50:21 2012 +0200
lvmetad: check for fid existance
Fail to update lvmetad with proper log error message.
---
WHATS_NEW | 1 +
lib/cache/lvmetad.c | 3 +++
2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index ed1b37f..f1216ff 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.97 -
===============================
+ Check for create_instance() fail in pvscan_lvmetad_single().
Use 64bit math for reserved memory and stack.
Add tests for kernel_send() errors in cmirrod.
Print clean_bits in pull_state, fix cut&paste typo in cmirrord.
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 291adfa..d70e490 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -691,6 +691,9 @@ int pvscan_lvmetad_single(struct cmd_context *cmd, struct device *dev)
baton.fid = lvmcache_fmt(info)->ops->create_instance(lvmcache_fmt(info),
&fic);
+ if (!baton.fid)
+ goto_bad;
+
lvmcache_foreach_mda(info, _pvscan_lvmetad_single, &baton);
if (!baton.vg)
lvmcache_fmt(info)->ops->destroy_instance(baton.fid);
11 years, 10 months
master - fix: limit preallocate stack size
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2539769356cd73...
Commit: 2539769356cd73ffe6ff7abd9f9c3208ff24ee8b
Parent: 192fa11dab177027ad349363b39ff6435524b23d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Jun 22 11:15:14 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Jun 22 13:48:04 2012 +0200
fix: limit preallocate stack size
If the user would set bigger reserved stack size then what
is allowed in resources (ulimit -s), then he would get coredump
So avoid coredump and ignore creation of such large stack size
(lvm should work properly, with just 64KB, so the option could
be eliminated).
---
lib/mm/memlock.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 17dee1c..dfc0d42 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -124,8 +124,12 @@ static void _touch_memory(void *mem, size_t size)
static void _allocate_memory(void)
{
void *stack_mem, *temp_malloc_mem;
+ struct rlimit limit;
- if ((stack_mem = alloca(_size_stack)))
+ /* Check if we could preallocate requested stack */
+ if ((getrlimit (RLIMIT_STACK, &limit) == 0) &&
+ ((_size_stack * 2) < limit.rlim_cur) &&
+ ((stack_mem = alloca(_size_stack))))
_touch_memory(stack_mem, _size_stack);
if ((temp_malloc_mem = malloc(_size_malloc_tmp)))
11 years, 10 months
master - fix: use 64bit math for reserved memory
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=192fa11dab1770...
Commit: 192fa11dab177027ad349363b39ff6435524b23d
Parent: 6f3cd63551db013e3cf5dfcebc41115322d5cfe9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jun 21 12:59:14 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Jun 22 13:32:19 2012 +0200
fix: use 64bit math for reserved memory
If the user specifies number in the range of [4G/1024, 4G>,
the used value would wrap around (32bit math).
So keep the math 64bit.
Note, using such large lvm.conf values is pointless with lvm2.
---
WHATS_NEW | 1 +
lib/mm/memlock.c | 8 ++++----
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 97bd680..ed1b37f 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.97 -
===============================
+ Use 64bit math for reserved memory and stack.
Add tests for kernel_send() errors in cmirrod.
Print clean_bits in pull_state, fix cut&paste typo in cmirrord.
Add tests for errors from closedir(), close() in cmirrord.
diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 8c631bf..17dee1c 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -446,12 +446,12 @@ void memlock_dec_daemon(struct cmd_context *cmd)
void memlock_init(struct cmd_context *cmd)
{
/* When threaded, caller already limited stack size so just use the default. */
- _size_stack = 1024 * (cmd->threaded ? DEFAULT_RESERVED_STACK :
- find_config_tree_int(cmd, "activation/reserved_stack",
- DEFAULT_RESERVED_STACK));
+ _size_stack = 1024ULL * (cmd->threaded ? DEFAULT_RESERVED_STACK :
+ find_config_tree_int(cmd, "activation/reserved_stack",
+ DEFAULT_RESERVED_STACK));
_size_malloc_tmp = find_config_tree_int(cmd,
"activation/reserved_memory",
- DEFAULT_RESERVED_MEMORY) * 1024;
+ DEFAULT_RESERVED_MEMORY) * 1024ULL;
_default_priority = find_config_tree_int(cmd,
"activation/process_priority",
DEFAULT_PROCESS_PRIORITY);
11 years, 10 months
master - cleanup: replace memset with struct initilization
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6f3cd63551db01...
Commit: 6f3cd63551db013e3cf5dfcebc41115322d5cfe9
Parent: da42ee3a1f0280742e87a96f5d0694fb869a23e0
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jun 21 21:19:28 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Jun 22 13:23:03 2012 +0200
cleanup: replace memset with struct initilization
Simplifies the code, properly detects too long socket paths,
drops unused parameter.
---
daemons/clvmd/clvmd-openais.c | 3 +--
daemons/clvmd/clvmd-singlenode.c | 14 ++++++++------
daemons/clvmd/clvmd.c | 25 +++++++++++++++----------
daemons/clvmd/refresh_clvmd.c | 12 ++++++------
daemons/cmirrord/cluster.c | 3 +--
daemons/cmirrord/functions.c | 8 ++------
daemons/dmeventd/dmeventd.c | 12 +++---------
lib/cache/lvmetad.c | 2 --
lib/commands/toolcontext.c | 4 +---
lib/format1/import-export.c | 3 +--
lib/format1/vg_number.c | 4 +---
lib/format_text/format-text.c | 3 +--
lib/locking/cluster_locking.c | 11 ++++++-----
lib/metadata/lv_manip.c | 4 +---
libdaemon/client/daemon-client.c | 5 ++---
libdaemon/server/daemon-server.c | 7 ++-----
libdm/libdm-deptree.c | 4 +---
liblvm/lvm_lv.c | 4 ++--
liblvm/lvm_misc.c | 3 +--
tools/pvscan.c | 8 +++-----
tools/toollib.c | 1 -
unit-tests/mm/pool_valgrind_t.c | 4 +---
22 files changed, 59 insertions(+), 85 deletions(-)
diff --git a/daemons/clvmd/clvmd-openais.c b/daemons/clvmd/clvmd-openais.c
index 5f237e9..9ce73d6 100644
--- a/daemons/clvmd/clvmd-openais.c
+++ b/daemons/clvmd/clvmd-openais.c
@@ -197,14 +197,13 @@ static int add_internal_client(int fd, fd_callback_t callback)
DEBUGLOG("Add_internal_client, fd = %d\n", fd);
- client = malloc(sizeof(struct local_client));
+ client = calloc(1, sizeof(struct local_client));
if (!client)
{
DEBUGLOG("malloc failed\n");
return -1;
}
- memset(client, 0, sizeof(struct local_client));
client->fd = fd;
client->type = CLUSTER_INTERNAL;
client->callback = callback;
diff --git a/daemons/clvmd/clvmd-singlenode.c b/daemons/clvmd/clvmd-singlenode.c
index 298abcb..3b35bf5 100644
--- a/daemons/clvmd/clvmd-singlenode.c
+++ b/daemons/clvmd/clvmd-singlenode.c
@@ -48,8 +48,15 @@ static void close_comms(void)
static int init_comms(void)
{
- struct sockaddr_un addr;
mode_t old_mask;
+ struct sockaddr_un addr = { .sun_family = AF_UNIX };
+
+ if (!dm_strncpy(addr.sun_path, SINGLENODE_CLVMD_SOCKNAME,
+ sizeof(addr.sun_path))) {
+ DEBUGLOG("%s: singlenode socket name too long.",
+ SINGLENODE_CLVMD_SOCKNAME);
+ return -1;
+ }
close_comms();
@@ -67,11 +74,6 @@ static int init_comms(void)
goto error;
}
- memset(&addr, 0, sizeof(addr));
- memcpy(addr.sun_path, SINGLENODE_CLVMD_SOCKNAME,
- sizeof(SINGLENODE_CLVMD_SOCKNAME));
- addr.sun_family = AF_UNIX;
-
if (bind(listen_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
DEBUGLOG("Can't bind local socket: %s\n", strerror(errno));
goto error;
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 0b866e6..4efa237 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -2092,20 +2092,23 @@ static int add_to_lvmqueue(struct local_client *client, struct clvm_header *msg,
static int check_local_clvmd(void)
{
int local_socket;
- struct sockaddr_un sockaddr;
int ret = 0;
+ struct sockaddr_un sockaddr = { .sun_family = AF_UNIX };
+
+ if (!dm_strncpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(sockaddr.sun_path))) {
+ log_error("%s: clvmd socket name too long.", CLVMD_SOCKNAME);
+ return -1;
+ }
/* Open local socket */
if ((local_socket = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
+ log_sys_error("socket", "local socket");
return -1;
}
- memset(&sockaddr, 0, sizeof(sockaddr));
- memcpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(CLVMD_SOCKNAME));
- sockaddr.sun_family = AF_UNIX;
-
if (connect(local_socket,(struct sockaddr *) &sockaddr,
sizeof(sockaddr))) {
+ log_sys_error("connect", "local socket");
ret = -1;
}
@@ -2127,9 +2130,14 @@ static void close_local_sock(int local_socket)
/* Open the local socket, that's the one we talk to libclvm down */
static int open_local_sock(void)
{
- int local_socket = -1;
- struct sockaddr_un sockaddr;
mode_t old_mask;
+ int local_socket = -1;
+ struct sockaddr_un sockaddr = { .sun_family = AF_UNIX };
+
+ if (!dm_strncpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(sockaddr.sun_path))) {
+ log_error("%s: clvmd socket name too long.", CLVMD_SOCKNAME);
+ return -1;
+ }
close_local_sock(local_socket);
@@ -2148,9 +2156,6 @@ static int open_local_sock(void)
DEBUGLOG("setting CLOEXEC on local_socket failed: %s\n", strerror(errno));
fcntl(local_socket, F_SETFL, fcntl(local_socket, F_GETFL, 0) | O_NONBLOCK);
- memset(&sockaddr, 0, sizeof(sockaddr));
- memcpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(CLVMD_SOCKNAME));
- sockaddr.sun_family = AF_UNIX;
if (bind(local_socket, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
log_error("can't bind local socket: %m");
diff --git a/daemons/clvmd/refresh_clvmd.c b/daemons/clvmd/refresh_clvmd.c
index 9ce02f2..28b5625 100644
--- a/daemons/clvmd/refresh_clvmd.c
+++ b/daemons/clvmd/refresh_clvmd.c
@@ -47,7 +47,12 @@ static int _clvmd_sock = -1;
static int _open_local_sock(void)
{
int local_socket;
- struct sockaddr_un sockaddr;
+ struct sockaddr_un sockaddr = { .sun_family = AF_UNIX };
+
+ if (!dm_strncpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(sockaddr.sun_path))) {
+ fprintf(stderr, "%s: clvmd socket name too long.", CLVMD_SOCKNAME);
+ return -1;
+ }
/* Open local socket */
if ((local_socket = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
@@ -55,11 +60,6 @@ static int _open_local_sock(void)
return -1;
}
- memset(&sockaddr, 0, sizeof(sockaddr));
- memcpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(CLVMD_SOCKNAME));
-
- sockaddr.sun_family = AF_UNIX;
-
if (connect(local_socket,(struct sockaddr *) &sockaddr,
sizeof(sockaddr))) {
int saved_errno = errno;
diff --git a/daemons/cmirrord/cluster.c b/daemons/cmirrord/cluster.c
index 9fbf800..70c76c3 100644
--- a/daemons/cmirrord/cluster.c
+++ b/daemons/cmirrord/cluster.c
@@ -1249,7 +1249,7 @@ static void cpg_join_callback(struct clog_cpg *match,
uint32_t my_pid = (uint32_t)getpid();
uint32_t lowest = match->lowest_id;
struct clog_request *rq;
- char dbuf[32];
+ char dbuf[32] = { 0 };
/* Assign my_cluster_id */
if ((my_cluster_id == 0xDEAD) && (joined->pid == my_pid))
@@ -1265,7 +1265,6 @@ static void cpg_join_callback(struct clog_cpg *match,
if (joined->nodeid == my_cluster_id)
goto out;
- memset(dbuf, 0, sizeof(dbuf));
for (i = 0; i < member_list_entries - 1; i++)
sprintf(dbuf+strlen(dbuf), "%u-", member_list[i].nodeid);
sprintf(dbuf+strlen(dbuf), "(%u)", joined->nodeid);
diff --git a/daemons/cmirrord/functions.c b/daemons/cmirrord/functions.c
index 3e8fd20..f6e0918 100644
--- a/daemons/cmirrord/functions.c
+++ b/daemons/cmirrord/functions.c
@@ -235,11 +235,9 @@ static int rw_log(struct log_c *lc, int do_write)
*/
static int read_log(struct log_c *lc)
{
- struct log_header lh;
+ struct log_header lh = { 0 };
size_t bitset_size;
- memset(&lh, 0, sizeof(struct log_header));
-
if (rw_log(lc, 0))
return -EIO; /* Failed disk read */
@@ -1724,14 +1722,12 @@ int do_request(struct clog_request *rq, int server)
static void print_bits(dm_bitset_t bs, int print)
{
int i, size;
- char outbuf[128];
+ char outbuf[128] = { 0 };
unsigned char *buf = (unsigned char *)(bs + 1);
size = (*bs % 8) ? 1 : 0;
size += (*bs / 8);
- memset(outbuf, 0, sizeof(outbuf));
-
for (i = 0; i < size; i++) {
if (!(i % 16)) {
if (outbuf[0] != '\0') {
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 91ef690..2ffe7f4 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1437,11 +1437,9 @@ static int _do_process_request(struct dm_event_daemon_message *msg)
{
int ret;
char *answer;
- static struct message_data message_data;
+ struct message_data message_data = { .msg = msg };
/* Parse the message. */
- memset(&message_data, 0, sizeof(message_data));
- message_data.msg = msg;
if (msg->cmd == DM_EVENT_CMD_HELLO || msg->cmd == DM_EVENT_CMD_DIE) {
ret = 0;
answer = msg->data;
@@ -1473,9 +1471,7 @@ static int _do_process_request(struct dm_event_daemon_message *msg)
static void _process_request(struct dm_event_fifos *fifos)
{
int die = 0;
- struct dm_event_daemon_message msg;
-
- memset(&msg, 0, sizeof(msg));
+ struct dm_event_daemon_message msg = { 0 };
/*
* Read the request from the client (client_read, client_write
@@ -1580,10 +1576,8 @@ static void _sig_alarm(int signum __attribute__((unused)))
static void _init_thread_signals(void)
{
sigset_t my_sigset;
- struct sigaction act;
+ struct sigaction act = { .sa_handler = _sig_alarm };
- memset(&act, 0, sizeof(act));
- act.sa_handler = _sig_alarm;
sigaction(SIGALRM, &act, NULL);
sigfillset(&my_sigset);
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index f2bb8eb..291adfa 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -669,7 +669,6 @@ int pvscan_lvmetad_single(struct cmd_context *cmd, struct device *dev)
{
struct label *label;
struct lvmcache_info *info;
- struct physical_volume pv;
struct _pvscan_lvmetad_baton baton;
/* Create a dummy instance. */
struct format_instance_ctx fic = { .type = 0 };
@@ -687,7 +686,6 @@ int pvscan_lvmetad_single(struct cmd_context *cmd, struct device *dev)
}
info = (struct lvmcache_info *) label->info;
- memset(&pv, 0, sizeof(pv));
baton.vg = NULL;
baton.fid = lvmcache_fmt(info)->ops->create_instance(lvmcache_fmt(info),
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index cc23163..529bd51 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -736,11 +736,9 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
{
int nr_filt = 0;
const struct dm_config_node *cn;
- struct dev_filter *filters[MAX_FILTERS];
+ struct dev_filter *filters[MAX_FILTERS] = { 0 };
struct dev_filter *composite;
- memset(filters, 0, sizeof(filters));
-
/*
* Filters listed in order: top one gets applied first.
* Failure to initialise some filters is not fatal.
diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c
index f1a874d..1370d12 100644
--- a/lib/format1/import-export.c
+++ b/lib/format1/import-export.c
@@ -556,7 +556,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
int import_snapshots(struct dm_pool *mem __attribute__((unused)), struct volume_group *vg,
struct dm_list *pvds)
{
- struct logical_volume *lvs[MAX_LV];
+ struct logical_volume *lvs[MAX_LV] = { 0 };
struct disk_list *dl;
struct lvd_list *ll;
struct lv_disk *lvd;
@@ -564,7 +564,6 @@ int import_snapshots(struct dm_pool *mem __attribute__((unused)), struct volume_
struct logical_volume *org, *cow;
/* build an index of lv numbers */
- memset(lvs, 0, sizeof(lvs));
dm_list_iterate_items(dl, pvds) {
dm_list_iterate_items(ll, &dl->lvds) {
lvd = &ll->lvd;
diff --git a/lib/format1/vg_number.c b/lib/format1/vg_number.c
index 47570f5..ed52554 100644
--- a/lib/format1/vg_number.c
+++ b/lib/format1/vg_number.c
@@ -29,7 +29,7 @@ int get_free_vg_number(struct format_instance *fid, struct dev_filter *filter,
struct dm_list all_pvs;
struct disk_list *dl;
struct dm_pool *mem = dm_pool_create("lvm1 vg_number", 10 * 1024);
- int numbers[MAX_VG], i, r = 0;
+ int i, r = 0, numbers[MAX_VG] = { 0 };
dm_list_init(&all_pvs);
@@ -39,8 +39,6 @@ int get_free_vg_number(struct format_instance *fid, struct dev_filter *filter,
if (!read_pvs_in_vg(fid->fmt, NULL, filter, mem, &all_pvs))
goto_out;
- memset(numbers, 0, sizeof(numbers));
-
dm_list_iterate_items(dl, &all_pvs) {
if (!*dl->pvd.vg_name || !strcmp((char *)dl->pvd.vg_name, candidate_vg))
continue;
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 3c89dfa..aea03c9 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -1266,11 +1266,10 @@ static int _write_single_mda(struct metadata_area *mda, void *baton)
struct _write_single_mda_baton *p = baton;
struct mda_context *mdac;
- char buf[MDA_HEADER_SIZE] __attribute__((aligned(8)));
+ char buf[MDA_HEADER_SIZE] __attribute__((aligned(8))) = { 0 };
struct mda_header *mdah = (struct mda_header *) buf;
mdac = mda->metadata_locn;
- memset(&buf, 0, sizeof(buf));
mdah->size = mdac->area.size;
rlocn_set_ignored(mdah->raw_locns, mda_is_ignored(mda));
diff --git a/lib/locking/cluster_locking.c b/lib/locking/cluster_locking.c
index 3e2543b..f9d6328 100644
--- a/lib/locking/cluster_locking.c
+++ b/lib/locking/cluster_locking.c
@@ -65,7 +65,12 @@ static int _clvmd_sock = -1;
static int _open_local_sock(int suppress_messages)
{
int local_socket;
- struct sockaddr_un sockaddr;
+ struct sockaddr_un sockaddr = { .sun_family = AF_UNIX };
+
+ if (!dm_strncpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(sockaddr.sun_path))) {
+ log_error("%s: clvmd socket name too long.", CLVMD_SOCKNAME);
+ return -1;
+ }
/* Open local socket */
if ((local_socket = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
@@ -74,10 +79,6 @@ static int _open_local_sock(int suppress_messages)
return -1;
}
- memset(&sockaddr, 0, sizeof(sockaddr));
- memcpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(CLVMD_SOCKNAME));
-
- sockaddr.sun_family = AF_UNIX;
if (connect(local_socket,(struct sockaddr *) &sockaddr,
sizeof(sockaddr))) {
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 3913680..5c715a8 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -180,13 +180,11 @@ static struct seg_pvs *_find_seg_pvs_by_le(struct dm_list *list, uint32_t le)
*/
uint32_t find_free_lvnum(struct logical_volume *lv)
{
- int lvnum_used[MAX_RESTRICTED_LVS + 1];
+ int lvnum_used[MAX_RESTRICTED_LVS + 1] = { 0 };
uint32_t i = 0;
struct lv_list *lvl;
int lvnum;
- memset(&lvnum_used, 0, sizeof(lvnum_used));
-
dm_list_iterate_items(lvl, &lv->vg->lvs) {
lvnum = lvnum_from_lvid(&lvl->lv->lvid);
if (lvnum <= MAX_RESTRICTED_LVS)
diff --git a/libdaemon/client/daemon-client.c b/libdaemon/client/daemon-client.c
index 906de38..6aad75c 100644
--- a/libdaemon/client/daemon-client.c
+++ b/libdaemon/client/daemon-client.c
@@ -26,17 +26,16 @@
daemon_handle daemon_open(daemon_info i) {
daemon_handle h = { .protocol_version = 0, .error = 0 };
daemon_reply r = { .cft = NULL };
- struct sockaddr_un sockaddr;
+ struct sockaddr_un sockaddr = { .sun_family = AF_UNIX };
if ((h.socket_fd = socket(PF_UNIX, SOCK_STREAM /* | SOCK_NONBLOCK */, 0)) < 0)
goto error;
- memset(&sockaddr, 0, sizeof(sockaddr));
if (!dm_strncpy(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path))) {
fprintf(stderr, "%s: daemon socket path too long.\n", i.socket);
goto error;
}
- sockaddr.sun_family = AF_UNIX;
+
if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr)))
goto error;
diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index 568ef36..65b28e4 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -129,7 +129,7 @@ union sockaddr_union {
static int _handle_preloaded_socket(int fd, const char *path)
{
struct stat st_fd;
- union sockaddr_union sockaddr;
+ union sockaddr_union sockaddr = { .sa.sa_family = 0 };
int type = 0;
socklen_t len = sizeof(type);
size_t path_len = strlen(path);
@@ -144,7 +144,6 @@ static int _handle_preloaded_socket(int fd, const char *path)
len != sizeof(type) || type != SOCK_STREAM)
return 0;
- memset(&sockaddr, 0, sizeof(sockaddr));
len = sizeof(sockaddr);
if (getsockname(fd, &sockaddr.sa, &len) < 0 ||
len < sizeof(sa_family_t) ||
@@ -204,7 +203,7 @@ out:
static int _open_socket(daemon_state s)
{
int fd = -1;
- struct sockaddr_un sockaddr;
+ struct sockaddr_un sockaddr = { .sun_family = AF_UNIX };
mode_t old_mask;
(void) dm_prepare_selinux_context(s.socket_path, S_IFSOCK);
@@ -223,12 +222,10 @@ static int _open_socket(daemon_state s)
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
fprintf(stderr, "[D] creating %s\n", s.socket_path);
- memset(&sockaddr, 0, sizeof(sockaddr));
if (!dm_strncpy(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path))) {
fprintf(stderr, "%s: daemon socket path too long.\n", s.socket_path);
goto error;
}
- sockaddr.sun_family = AF_UNIX;
if (bind(fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
perror("can't bind local socket.");
diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c
index 5ce44d0..6b428d6 100644
--- a/libdm/libdm-deptree.c
+++ b/libdm/libdm-deptree.c
@@ -1082,7 +1082,7 @@ struct dm_tree_node *dm_tree_add_new_dev_with_udev_flags(struct dm_tree *dtree,
uint16_t udev_flags)
{
struct dm_tree_node *dnode;
- struct dm_info info;
+ struct dm_info info = { 0 };
const char *name2;
const char *uuid2;
@@ -1102,8 +1102,6 @@ struct dm_tree_node *dm_tree_add_new_dev_with_udev_flags(struct dm_tree *dtree,
return NULL;
}
- memset(&info, 0, sizeof(info));
-
if (!(dnode = _create_dm_tree_node(dtree, name2, uuid2, &info,
context, 0)))
return_NULL;
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index 336b714..23ccbe8 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -144,7 +144,7 @@ static int _lv_set_default_linear_params(struct cmd_context *cmd,
*/
lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
{
- struct lvcreate_params lp;
+ struct lvcreate_params lp = { 0 };
uint64_t extents;
struct lv_list *lvl;
@@ -152,7 +152,7 @@ lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
return NULL;
if (!vg_check_write_mode(vg))
return NULL;
- memset(&lp, 0, sizeof(lp));
+
extents = extents_from_size(vg->cmd, size / SECTOR_SIZE,
vg->extent_size);
_lv_set_default_params(&lp, vg, name, extents);
diff --git a/liblvm/lvm_misc.c b/liblvm/lvm_misc.c
index 3bf6a04..0a0ea12 100644
--- a/liblvm/lvm_misc.c
+++ b/liblvm/lvm_misc.c
@@ -50,9 +50,8 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
const pvseg_t pvseg, const char *name)
{
struct lvm_property_type prop;
- struct lvm_property_value v;
+ struct lvm_property_value v = { 0 };
- memset(&v, 0, sizeof(v));
prop.id = name;
if (pv) {
diff --git a/tools/pvscan.c b/tools/pvscan.c
index f0e7408..62034c9 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -28,9 +28,9 @@ static void _pvscan_display_single(struct cmd_context *cmd,
char uuid[64] __attribute__((aligned(8)));
unsigned vg_name_len = 0;
- char pv_tmp_name[NAME_LEN] = { 0, };
- char vg_tmp_name[NAME_LEN] = { 0, };
- char vg_name_this[NAME_LEN] = { 0, };
+ char pv_tmp_name[NAME_LEN] = { 0 };
+ char vg_tmp_name[NAME_LEN] = { 0 };
+ char vg_name_this[NAME_LEN] = { 0 };
/* short listing? */
if (arg_count(cmd, short_ARG) > 0) {
@@ -49,8 +49,6 @@ static void _pvscan_display_single(struct cmd_context *cmd,
/* return; */
}
- memset(pv_tmp_name, 0, sizeof(pv_tmp_name));
-
vg_name_len = strlen(pv_vg_name(pv)) + 1;
if (arg_count(cmd, uuid_ARG)) {
diff --git a/tools/toollib.c b/tools/toollib.c
index d5ad805..361052b 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -674,7 +674,6 @@ static int _process_all_devs(struct cmd_context *cmd, void *handle,
dm_list_init(&pv_dummy.tags);
dm_list_init(&pv_dummy.segments);
pv_dummy.dev = dev;
- pv_dummy.fmt = NULL;
pv = &pv_dummy;
}
ret = process_single_pv(cmd, NULL, pv, handle);
diff --git a/unit-tests/mm/pool_valgrind_t.c b/unit-tests/mm/pool_valgrind_t.c
index b430a9c..704f116 100644
--- a/unit-tests/mm/pool_valgrind_t.c
+++ b/unit-tests/mm/pool_valgrind_t.c
@@ -158,11 +158,9 @@ static void check_object_growth()
{
int i;
struct dm_pool *p = dm_pool_create("", 32);
- char data[100];
+ char data[100] = { 0 };
void *obj;
- memset(data, 0, sizeof(data));
-
dm_pool_begin_object(p, 43);
for (i = 1; i < 100; i++)
dm_pool_grow_object(p, data, i);
11 years, 10 months
master - kernel docs: Refresh kernel target documentation
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=da42ee3a1f0280...
Commit: da42ee3a1f0280742e87a96f5d0694fb869a23e0
Parent: 461eb1ac6adbf8e1938bd6e726dd4048c341cb49
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Thu Jun 21 23:48:40 2012 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Thu Jun 21 23:48:40 2012 +0100
kernel docs: Refresh kernel target documentation
Update the packaged copy of the in-kernel target documentation files.
Adds dm-verity, updates thin provisioning and makes minor corrections
elsewhere.
---
doc/kernel/persistent-data.txt | 2 +-
doc/kernel/raid.txt | 2 +-
doc/kernel/striped.txt | 7 +-
doc/kernel/thin-provisioning.txt | 78 +++++++++++++++----
doc/kernel/verity.txt | 155 ++++++++++++++++++++++++++++++++++++++
5 files changed, 222 insertions(+), 22 deletions(-)
diff --git a/doc/kernel/persistent-data.txt b/doc/kernel/persistent-data.txt
index 0e5df9b..a333bcb 100644
--- a/doc/kernel/persistent-data.txt
+++ b/doc/kernel/persistent-data.txt
@@ -3,7 +3,7 @@ Introduction
The more-sophisticated device-mapper targets require complex metadata
that is managed in kernel. In late 2010 we were seeing that various
-different targets were rolling their own data strutures, for example:
+different targets were rolling their own data structures, for example:
- Mikulas Patocka's multisnap implementation
- Heinz Mauelshagen's thin provisioning target
diff --git a/doc/kernel/raid.txt b/doc/kernel/raid.txt
index 2a8c113..946c733 100644
--- a/doc/kernel/raid.txt
+++ b/doc/kernel/raid.txt
@@ -28,7 +28,7 @@ The target is named "raid" and it accepts the following parameters:
raid6_nc RAID6 N continue
- rotating parity N (right-to-left) with data continuation
- Refererence: Chapter 4 of
+ Reference: Chapter 4 of
http://www.snia.org/sites/default/files/SNIA_DDF_Technical_Position_v2.0.pdf
<#raid_params>: The number of parameters that follow.
diff --git a/doc/kernel/striped.txt b/doc/kernel/striped.txt
index f34d323..45f3b91 100644
--- a/doc/kernel/striped.txt
+++ b/doc/kernel/striped.txt
@@ -9,15 +9,14 @@ devices in parallel.
Parameters: <num devs> <chunk size> [<dev path> <offset>]+
<num devs>: Number of underlying devices.
- <chunk size>: Size of each chunk of data. Must be a power-of-2 and at
- least as large as the system's PAGE_SIZE.
+ <chunk size>: Size of each chunk of data. Must be at least as
+ large as the system's PAGE_SIZE.
<dev path>: Full pathname to the underlying block-device, or a
"major:minor" device-number.
<offset>: Starting sector within the device.
One or more underlying devices can be specified. The striped device size must
-be a multiple of the chunk size and a multiple of the number of underlying
-devices.
+be a multiple of the chunk size multiplied by the number of underlying devices.
Example scripts
diff --git a/doc/kernel/thin-provisioning.txt b/doc/kernel/thin-provisioning.txt
index 801d9d1..f5cfc62 100644
--- a/doc/kernel/thin-provisioning.txt
+++ b/doc/kernel/thin-provisioning.txt
@@ -1,7 +1,7 @@
Introduction
============
-This document descibes a collection of device-mapper targets that
+This document describes a collection of device-mapper targets that
between them implement thin-provisioning and snapshots.
The main highlight of this implementation, compared to the previous
@@ -75,10 +75,12 @@ less sharing than average you'll need a larger-than-average metadata device.
As a guide, we suggest you calculate the number of bytes to use in the
metadata device as 48 * $data_dev_size / $data_block_size but round it up
-to 2MB if the answer is smaller. The largest size supported is 16GB.
+to 2MB if the answer is smaller. If you're creating large numbers of
+snapshots which are recording large amounts of change, you may find you
+need to increase this.
-If you're creating large numbers of snapshots which are recording large
-amounts of change, you may need find you need to increase this.
+The largest size supported is 16GB: If the device is larger,
+a warning will be issued and the excess space will not be used.
Reloading a pool table
----------------------
@@ -167,6 +169,38 @@ ii) Using an internal snapshot.
dmsetup create snap --table "0 2097152 thin /dev/mapper/pool 1"
+External snapshots
+------------------
+
+You can use an external _read only_ device as an origin for a
+thinly-provisioned volume. Any read to an unprovisioned area of the
+thin device will be passed through to the origin. Writes trigger
+the allocation of new blocks as usual.
+
+One use case for this is VM hosts that want to run guests on
+thinly-provisioned volumes but have the base image on another device
+(possibly shared between many VMs).
+
+You must not write to the origin device if you use this technique!
+Of course, you may write to the thin device and take internal snapshots
+of the thin volume.
+
+i) Creating a snapshot of an external device
+
+ This is the same as creating a thin device.
+ You don't mention the origin at this stage.
+
+ dmsetup message /dev/mapper/pool 0 "create_thin 0"
+
+ii) Using a snapshot of an external device.
+
+ Append an extra parameter to the thin target specifying the origin:
+
+ dmsetup create snap --table "0 2097152 thin /dev/mapper/pool 0 /dev/image"
+
+ N.B. All descendants (internal snapshots) of this snapshot require the
+ same extra origin parameter.
+
Deactivation
------------
@@ -189,7 +223,13 @@ i) Constructor
<low water mark (blocks)> [<number of feature args> [<arg>]*]
Optional feature arguments:
- - 'skip_block_zeroing': skips the zeroing of newly-provisioned blocks.
+
+ skip_block_zeroing: Skip the zeroing of newly-provisioned blocks.
+
+ ignore_discard: Disable discard support.
+
+ no_discard_passdown: Don't pass discards down to the underlying
+ data device, but just remove the mapping.
Data block size must be between 64KB (128 sectors) and 1GB
(2097152 sectors) inclusive.
@@ -237,16 +277,6 @@ iii) Messages
Deletes a thin device. Irreversible.
- trim <dev id> <new size in sectors>
-
- Delete mappings from the end of a thin device. Irreversible.
- You might want to use this if you're reducing the size of
- your thinly-provisioned device. In many cases, due to the
- sharing of blocks between devices, it is not possible to
- determine in advance how much space 'trim' will release. (In
- future a userspace tool might be able to perform this
- calculation.)
-
set_transaction_id <current id> <new id>
Userland volume managers, such as LVM, need a way to
@@ -257,12 +287,23 @@ iii) Messages
the current transaction id is when you change it with this
compare-and-swap message.
+ reserve_metadata_snap
+
+ Reserve a copy of the data mapping btree for use by userland.
+ This allows userland to inspect the mappings as they were when
+ this message was executed. Use the pool's status command to
+ get the root block associated with the metadata snapshot.
+
+ release_metadata_snap
+
+ Release a previously reserved copy of the data mapping btree.
+
'thin' target
-------------
i) Constructor
- thin <pool dev> <dev id>
+ thin <pool dev> <dev id> [<external origin dev>]
pool dev:
the thin-pool device, e.g. /dev/mapper/my_pool or 253:0
@@ -271,6 +312,11 @@ i) Constructor
the internal device identifier of the device to be
activated.
+ external origin dev:
+ an optional block device outside the pool to be treated as a
+ read-only snapshot origin: reads to unprovisioned areas of the
+ thin target will be mapped to this device.
+
The pool doesn't store any size against the thin devices. If you
load a thin target that is smaller than you've been using previously,
then you'll have no access to blocks mapped beyond the end. If you
diff --git a/doc/kernel/verity.txt b/doc/kernel/verity.txt
new file mode 100644
index 0000000..9884681
--- /dev/null
+++ b/doc/kernel/verity.txt
@@ -0,0 +1,155 @@
+dm-verity
+==========
+
+Device-Mapper's "verity" target provides transparent integrity checking of
+block devices using a cryptographic digest provided by the kernel crypto API.
+This target is read-only.
+
+Construction Parameters
+=======================
+ <version> <dev> <hash_dev>
+ <data_block_size> <hash_block_size>
+ <num_data_blocks> <hash_start_block>
+ <algorithm> <digest> <salt>
+
+<version>
+ This is the type of the on-disk hash format.
+
+ 0 is the original format used in the Chromium OS.
+ The salt is appended when hashing, digests are stored continuously and
+ the rest of the block is padded with zeros.
+
+ 1 is the current format that should be used for new devices.
+ The salt is prepended when hashing and each digest is
+ padded with zeros to the power of two.
+
+<dev>
+ This is the device containing data, the integrity of which needs to be
+ checked. It may be specified as a path, like /dev/sdaX, or a device number,
+ <major>:<minor>.
+
+<hash_dev>
+ This is the device that supplies the hash tree data. It may be
+ specified similarly to the device path and may be the same device. If the
+ same device is used, the hash_start should be outside the configured
+ dm-verity device.
+
+<data_block_size>
+ The block size on a data device in bytes.
+ Each block corresponds to one digest on the hash device.
+
+<hash_block_size>
+ The size of a hash block in bytes.
+
+<num_data_blocks>
+ The number of data blocks on the data device. Additional blocks are
+ inaccessible. You can place hashes to the same partition as data, in this
+ case hashes are placed after <num_data_blocks>.
+
+<hash_start_block>
+ This is the offset, in <hash_block_size>-blocks, from the start of hash_dev
+ to the root block of the hash tree.
+
+<algorithm>
+ The cryptographic hash algorithm used for this device. This should
+ be the name of the algorithm, like "sha1".
+
+<digest>
+ The hexadecimal encoding of the cryptographic hash of the root hash block
+ and the salt. This hash should be trusted as there is no other authenticity
+ beyond this point.
+
+<salt>
+ The hexadecimal encoding of the salt value.
+
+Theory of operation
+===================
+
+dm-verity is meant to be set up as part of a verified boot path. This
+may be anything ranging from a boot using tboot or trustedgrub to just
+booting from a known-good device (like a USB drive or CD).
+
+When a dm-verity device is configured, it is expected that the caller
+has been authenticated in some way (cryptographic signatures, etc).
+After instantiation, all hashes will be verified on-demand during
+disk access. If they cannot be verified up to the root node of the
+tree, the root hash, then the I/O will fail. This should detect
+tampering with any data on the device and the hash data.
+
+Cryptographic hashes are used to assert the integrity of the device on a
+per-block basis. This allows for a lightweight hash computation on first read
+into the page cache. Block hashes are stored linearly, aligned to the nearest
+block size.
+
+Hash Tree
+---------
+
+Each node in the tree is a cryptographic hash. If it is a leaf node, the hash
+of some data block on disk is calculated. If it is an intermediary node,
+the hash of a number of child nodes is calculated.
+
+Each entry in the tree is a collection of neighboring nodes that fit in one
+block. The number is determined based on block_size and the size of the
+selected cryptographic digest algorithm. The hashes are linearly-ordered in
+this entry and any unaligned trailing space is ignored but included when
+calculating the parent node.
+
+The tree looks something like:
+
+alg = sha256, num_blocks = 32768, block_size = 4096
+
+ [ root ]
+ / . . . \
+ [entry_0] [entry_1]
+ / . . . \ . . . \
+ [entry_0_0] . . . [entry_0_127] . . . . [entry_1_127]
+ / ... \ / . . . \ / \
+ blk_0 ... blk_127 blk_16256 blk_16383 blk_32640 . . . blk_32767
+
+
+On-disk format
+==============
+
+The verity kernel code does not read the verity metadata on-disk header.
+It only reads the hash blocks which directly follow the header.
+It is expected that a user-space tool will verify the integrity of the
+verity header.
+
+Alternatively, the header can be omitted and the dmsetup parameters can
+be passed via the kernel command-line in a rooted chain of trust where
+the command-line is verified.
+
+Directly following the header (and with sector number padded to the next hash
+block boundary) are the hash blocks which are stored a depth at a time
+(starting from the root), sorted in order of increasing index.
+
+The full specification of kernel parameters and on-disk metadata format
+is available at the cryptsetup project's wiki page
+ http://code.google.com/p/cryptsetup/wiki/DMVerity
+
+Status
+======
+V (for Valid) is returned if every check performed so far was valid.
+If any check failed, C (for Corruption) is returned.
+
+Example
+=======
+Set up a device:
+ # dmsetup create vroot --readonly --table \
+ "0 2097152 verity 1 /dev/sda1 /dev/sda2 4096 4096 262144 1 sha256 "\
+ "4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 "\
+ "1234000000000000000000000000000000000000000000000000000000000000"
+
+A command line tool veritysetup is available to compute or verify
+the hash tree or activate the kernel device. This is available from
+the cryptsetup upstream repository http://code.google.com/p/cryptsetup/
+(as a libcryptsetup extension).
+
+Create hash on the device:
+ # veritysetup format /dev/sda1 /dev/sda2
+ ...
+ Root hash: 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
+
+Activate the device:
+ # veritysetup create vroot /dev/sda1 /dev/sda2 \
+ 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
11 years, 10 months
master - cmirrord: add missing checks for kernel_send
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=461eb1ac6adbf8...
Commit: 461eb1ac6adbf8e1938bd6e726dd4048c341cb49
Parent: ac8a931889d796cf1e74b7c38ee6fb201ae2963b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Jun 19 23:28:59 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Jun 20 14:48:26 2012 +0200
cmirrord: add missing checks for kernel_send
Log errors if kernel_send fails.
---
WHATS_NEW | 1 +
daemons/cmirrord/cluster.c | 9 ++++++---
daemons/cmirrord/local.c | 4 +++-
3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 34da256..97bd680 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.97 -
===============================
+ Add tests for kernel_send() errors in cmirrod.
Print clean_bits in pull_state, fix cut&paste typo in cmirrord.
Add tests for errors from closedir(), close() in cmirrord.
Fix missing sync of filesystem when creating thin volume snapshot.
diff --git a/daemons/cmirrord/cluster.c b/daemons/cmirrord/cluster.c
index 3a6bb03..9fbf800 100644
--- a/daemons/cmirrord/cluster.c
+++ b/daemons/cmirrord/cluster.c
@@ -910,8 +910,9 @@ static int resend_requests(struct clog_cpg *entry)
rq->u_rq.seq);
rq->u_rq.data_size = 0;
- kernel_send(&rq->u_rq);
-
+ if (kernel_send(&rq->u_rq))
+ LOG_ERROR("Failed to respond to kernel [%s]",
+ RQ_TYPE(rq->u_rq.request_type));
break;
default:
@@ -1346,7 +1347,9 @@ static void cpg_leave_callback(struct clog_cpg *match,
dm_list_del(&rq->u.list);
if (rq->u_rq.request_type == DM_ULOG_POSTSUSPEND)
- kernel_send(&rq->u_rq);
+ if (kernel_send(&rq->u_rq))
+ LOG_ERROR("Failed to respond to kernel [%s]",
+ RQ_TYPE(rq->u_rq.request_type));
free(rq);
}
diff --git a/daemons/cmirrord/local.c b/daemons/cmirrord/local.c
index 50711a1..500f6dc 100644
--- a/daemons/cmirrord/local.c
+++ b/daemons/cmirrord/local.c
@@ -279,7 +279,9 @@ static int do_local_work(void *data __attribute__((unused)))
if (r) {
u_rq->data_size = 0;
u_rq->error = r;
- kernel_send(u_rq);
+ if (kernel_send(u_rq))
+ LOG_ERROR("Failed to respond to kernel [%s]",
+ RQ_TYPE(u_rq->request_type));
}
break;
11 years, 10 months
master - headers: add some __attribute__ instrumentation
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ac8a931889d796...
Commit: ac8a931889d796cf1e74b7c38ee6fb201ae2963b
Parent: ba222c6e35dd08d7e3665b187eacdd61e6f678d4
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 25 09:39:36 2010 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Jun 20 14:48:11 2012 +0200
headers: add some __attribute__ instrumentation
Use some malloc and strdup instrumentation and warning attributes
and standard systems headers.
---
libdm/libdevmapper.h | 39 ++++++++++++++++++++++++++-------------
1 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 1f780a3..a8bf885 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -713,13 +713,19 @@ uint32_t dm_tree_get_cookie(struct dm_tree_node *node);
* Memory management
*******************/
-void *dm_malloc_aux(size_t s, const char *file, int line);
-void *dm_malloc_aux_debug(size_t s, const char *file, int line);
-void *dm_zalloc_aux(size_t s, const char *file, int line);
-void *dm_zalloc_aux_debug(size_t s, const char *file, int line);
-char *dm_strdup_aux(const char *str, const char *file, int line);
+void *dm_malloc_aux(size_t s, const char *file, int line)
+ __attribute__((malloc)) __attribute__((__warn_unused_result__));
+void *dm_malloc_aux_debug(size_t s, const char *file, int line)
+ __attribute__((__warn_unused_result__));
+void *dm_zalloc_aux(size_t s, const char *file, int line)
+ __attribute__((malloc)) __attribute__((__warn_unused_result__));
+void *dm_zalloc_aux_debug(size_t s, const char *file, int line)
+ __attribute__((__warn_unused_result__));
+char *dm_strdup_aux(const char *str, const char *file, int line)
+ __attribute__((malloc)) __attribute__((__warn_unused_result__));
void dm_free_aux(void *p);
-void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line);
+void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line)
+ __attribute__((__warn_unused_result__));
int dm_dump_memory_debug(void);
void dm_bounds_check_debug(void);
@@ -782,12 +788,15 @@ void dm_bounds_check_debug(void);
struct dm_pool;
/* constructor and destructor */
-struct dm_pool *dm_pool_create(const char *name, size_t chunk_hint);
+struct dm_pool *dm_pool_create(const char *name, size_t chunk_hint)
+ __attribute__((__warn_unused_result__));
void dm_pool_destroy(struct dm_pool *p);
/* simple allocation/free routines */
-void *dm_pool_alloc(struct dm_pool *p, size_t s);
-void *dm_pool_alloc_aligned(struct dm_pool *p, size_t s, unsigned alignment);
+void *dm_pool_alloc(struct dm_pool *p, size_t s)
+ __attribute__((__warn_unused_result__));
+void *dm_pool_alloc_aligned(struct dm_pool *p, size_t s, unsigned alignment)
+ __attribute__((__warn_unused_result__));
void dm_pool_empty(struct dm_pool *p);
void dm_pool_free(struct dm_pool *p, void *ptr);
@@ -858,9 +867,12 @@ void *dm_pool_end_object(struct dm_pool *p);
void dm_pool_abandon_object(struct dm_pool *p);
/* utilities */
-char *dm_pool_strdup(struct dm_pool *p, const char *str);
-char *dm_pool_strndup(struct dm_pool *p, const char *str, size_t n);
-void *dm_pool_zalloc(struct dm_pool *p, size_t s);
+char *dm_pool_strdup(struct dm_pool *p, const char *str)
+ __attribute__((__warn_unused_result__));
+char *dm_pool_strndup(struct dm_pool *p, const char *str, size_t n)
+ __attribute__((__warn_unused_result__));
+void *dm_pool_zalloc(struct dm_pool *p, size_t s)
+ __attribute__((__warn_unused_result__));
/******************
* bitset functions
@@ -918,7 +930,8 @@ struct dm_hash_node;
typedef void (*dm_hash_iterate_fn) (void *data);
-struct dm_hash_table *dm_hash_create(unsigned size_hint);
+struct dm_hash_table *dm_hash_create(unsigned size_hint)
+ __attribute__((__warn_unused_result__));
void dm_hash_destroy(struct dm_hash_table *t);
void dm_hash_wipe(struct dm_hash_table *t);
11 years, 10 months