]> sourceware.org Git - lvm2.git/commitdiff
libdm: add dm_get_status_snapshot
authorZdenek Kabelac <zkabelac@redhat.com>
Sun, 26 May 2013 14:57:50 +0000 (16:57 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 27 May 2013 08:30:51 +0000 (10:30 +0200)
Add dm_get_status_snapshot() for parsing snapshot status.

WHATS_NEW_DM
libdm/libdevmapper.h
libdm/libdm-deptree.c

index 9132e01f08d7e3ece58e572694e3e972bf9bbdd1..99e826911b0b22fd1fbbd05de5a644563ba2b884 100644 (file)
@@ -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.
index d9cd280a11e01e94f0855ce10a118cefbc923b1c..1bf580762b38b7e3d90463dce481018f494ca568 100644 (file)
@@ -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: <used_sectors>/<total_sectors>
+ * >= 1.8.0: <used_sectors>/<total_sectors> <metadata_sectors>
+ */
+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
  */
index 115754bf5a9a901448f5e2c65aa313b0bcab0a83..56522f1825b8748f4278b280b83559d95836b30b 100644 (file)
@@ -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)
 {
This page took 0.048963 seconds and 5 git commands to generate.