From 4707ac7200ba559ad080e4349f660c0a7559610c Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sun, 26 May 2013 16:57:50 +0200 Subject: [PATCH] libdm: add dm_get_status_snapshot Add dm_get_status_snapshot() for parsing snapshot status. --- WHATS_NEW_DM | 1 + libdm/libdevmapper.h | 20 +++++++++++++++++++- libdm/libdm-deptree.c | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 9132e01f0..99e826911 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.78 - =================================== + Add dm_get_status_snapshot() for parsing snapshot status. Detecte mounted fs also via reading /proc/self/mountinfo. Add dm_mountinfo_read() for parsing /proc/self/mountinfo. Report error for nonexisting devices in dmeventd communication. diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index d9cd280a1..1bf580762 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. - * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved. * * This file is part of the device-mapper userspace tools. * @@ -286,6 +286,24 @@ struct dm_status_raid { int dm_get_status_raid(struct dm_pool *mem, const char *params, struct dm_status_raid **status); + +/* + * Snapshot target's format: + * <= 1.7.0: / + * >= 1.8.0: / + */ +struct dm_status_snapshot { + uint64_t used_sectors; /* in 512b units */ + uint64_t total_sectors; + uint64_t metadata_sectors; + unsigned has_metadata_sectors : 1; /* set when metadata_sectors is present */ + unsigned invalid : 1; /* set when snapshot is invalidated */ + unsigned merge_failed : 1; /* set when snapshot merge failed */ +}; + +int dm_get_status_snapshot(struct dm_pool *mem, const char *params, + struct dm_status_snapshot **status); + /* * Parse params from STATUS call for thin_pool target */ diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c index 115754bf5..56522f182 100644 --- a/libdm/libdm-deptree.c +++ b/libdm/libdm-deptree.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2012 Red Hat, Inc. All rights reserved. + * Copyright (C) 2005-2013 Red Hat, Inc. All rights reserved. * * This file is part of the device-mapper userspace tools. * @@ -2718,6 +2718,43 @@ int dm_tree_node_add_snapshot_merge_target(struct dm_tree_node *node, merge_uuid, 1, chunk_size); } +int dm_get_status_snapshot(struct dm_pool *mem, const char *params, + struct dm_status_snapshot **status) +{ + struct dm_status_snapshot *s; + int r; + + if (!params) { + log_error("Failed to parse invalid snapshot params."); + return 0; + } + + if (!(s = dm_pool_zalloc(mem, sizeof(*s)))) { + log_error("Failed to allocate snapshot status structure."); + return 0; + } + + r = sscanf(params, "%" PRIu64 "/%" PRIu64 " %" PRIu64, + &s->used_sectors, &s->total_sectors, + &s->metadata_sectors); + + if (r == 3 || r == 2) + s->has_metadata_sectors = (r == 3); + else if (!strcmp(params, "Invalid")) + s->invalid = 1; + else if (!strcmp(params, "Merge failed")) + s->merge_failed = 1; + else { + dm_pool_free(mem, s); + log_error("Failed to parse snapshot params: %s.", params); + return 0; + } + + *status = s; + + return 1; +} + int dm_tree_node_add_error_target(struct dm_tree_node *node, uint64_t size) { -- 2.43.5