]> sourceware.org Git - lvm2.git/commitdiff
Add lvm functions for sending messages.
authorZdenek Kabelac <zkabelac@redhat.com>
Mon, 3 Oct 2011 18:37:47 +0000 (18:37 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 3 Oct 2011 18:37:47 +0000 (18:37 +0000)
Functions are currently only needed for thin provissioning.

WHATS_NEW
lib/activate/activate.c
lib/activate/activate.h
lib/activate/dev_manager.c
lib/activate/dev_manager.h

index 93c2512b7257a6fc246fd17453a373b2e06ce4d2..01d4e67be2e82ae62aa9d949d07b8b121ed9a45d 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.89 - 
 ==================================
+  Introduce lv_send_message and dev_manager_send_message.
   Introduce revert_lv for better pvmove cleanup.
   Replace incomplete pvmove activation failure recovery code with a message.
   Abort if _finish_pvmove suspend_lvs fails instead of cleaning up incompletely.
index 51862ac3d1a5cc076465205d70d393b76e4f7872..b315603bb4374b434a8383c29cfa7646530d1bed 100644 (file)
@@ -215,6 +215,10 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
 {
        return 1;
 }
+int lv_send_message(const struct logical_volume *lv, const char *message)
+{
+       return 0;
+}
 int pv_uses_vg(struct physical_volume *pv,
               struct volume_group *vg)
 {
@@ -1643,6 +1647,55 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
        return r;
 }
 
+#if 0
+// FIXME: Remove this - example of supported messages thin pool
+"create_thin %u", dev_id
+"create_snap %u", dev_id
+"delete %u", dev_id
+"trim %u %" PRIu64, dev_id, new_size_sec
+"set_transaction_id %" PRIu64 " %" PRIu64, cur_id, new_id
+#endif
+
+int lv_send_message(const struct logical_volume *lv, const char *msg_format, ...)
+{
+       va_list ap;
+       struct dev_manager *dm;
+       const size_t buf_size = 128;
+       char *buf = NULL;
+       int r = 0, pr;
+
+       if (!activation())
+               return 0;
+
+       if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name, 1)))
+               return_0;
+
+       if (!(buf = dm_malloc(buf_size))) {
+               log_error("Failed to allocate message buffer.");
+               goto out;
+       }
+
+       va_start(ap, msg_format);
+       pr = vsnprintf(buf, buf_size, msg_format, ap);
+       va_end(ap);
+
+       if (pr < 0 || pr >= buf_size) {
+               log_error("Failed to create message in reserved buffer size "
+                         "%" PRIsize_t, buf_size);
+               goto out;
+       }
+
+       log_debug("Sending message '%s' to LV %s/%s", buf, lv->vg->name, lv->name);
+
+       if (!(r = dev_manager_send_message(dm, lv, buf)))
+               stack;
+out:
+       dm_free(buf);
+       dev_manager_destroy(dm);
+
+       return r;
+}
+
 /*
  * Does PV use VG somewhere in its construction?
  * Returns 1 on failure.
index 3b3d738a82709e2d61fde33f16aea066a6310f77..28ecd52d35a853f0ee2d486208c37419d41418e6 100644 (file)
@@ -71,6 +71,8 @@ int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s,
 int lv_deactivate(struct cmd_context *cmd, const char *lvid_s);
 
 int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv);
+__attribute__ ((format(printf, 2, 3)))
+int lv_send_message(const struct logical_volume *lv, const char *msg_format, ...);
 
 /*
  * Returns 1 if info structure has been populated, else 0.
index e7c73e9391b06f8c776adb645d63d277e9213e94..33e08c83b37b0d12362c1ce507f2291cf5c4383e 100644 (file)
@@ -876,6 +876,34 @@ int dev_manager_mknodes(const struct logical_volume *lv)
        return r;
 }
 
+/*
+ * Send message
+ */
+int dev_manager_send_message(struct dev_manager *dm, const struct logical_volume *lv, const char *message)
+{
+       const char *name;
+       struct dm_task *dmt;
+       int r = 0;
+
+       if (!(name = dm_build_dm_name(dm->mem, lv->vg->name, lv->name, NULL)))
+               return_0;
+
+       if (!(dmt = _setup_task(name, NULL, NULL, DM_DEVICE_TARGET_MSG, 0, 0)))
+               return_0;
+
+       if (!dm_task_set_message(dmt, message))
+               goto_out;
+
+       if (!dm_task_run(dmt))
+               goto_out;
+
+       r = 1;
+out:
+       dm_task_destroy(dmt);
+
+       return r;
+}
+
 static uint16_t _get_udev_flags(struct dev_manager *dm, struct logical_volume *lv,
                                const char *layer)
 {
index 9d414b20ee89f449ef8019fd8689123166648820..e3aae5d5e57f8cdd66cd272635308fe07d1f227c 100644 (file)
@@ -62,6 +62,7 @@ int dev_manager_deactivate(struct dev_manager *dm, struct logical_volume *lv);
 int dev_manager_transient(struct dev_manager *dm, struct logical_volume *lv) __attribute__((nonnull(1, 2)));
 
 int dev_manager_mknodes(const struct logical_volume *lv);
+int dev_manager_send_message(struct dev_manager *dm, const struct logical_volume *lv, const char *message);
 
 /*
  * Put the desired changes into effect.
This page took 0.0468 seconds and 5 git commands to generate.