Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <blockdev/blockdev.h>
#include <blockdev/lvm.h>
#include <glib.h>
#include <stdio.h>
#include <unistd.h>
#define VGNAME "mergetest"
#define SNAPNAME "lvol0_snap"
void _log (gint level, const gchar *msg) {
g_print ("bd log: %s\n", msg);
}
int main(void) {
gboolean ret = FALSE;
GError *error = NULL;
BDExtraArg lv_arg = {"--background",""};
const BDExtraArg *extra_args[2] = {&lv_arg, NULL};
BDPluginSpec lvm_plugin = {BD_PLUGIN_LVM, "libbd_lvm.so.2"};
BDPluginSpec *plugins[] = {&lvm_plugin, NULL};
ret = bd_switch_init_checks (FALSE, &error);
if (!ret) {
g_print ("Error disabling dependencies checks during init: %s (%s, %d)\n",
error->message, g_quark_to_string (error->domain), error->code);
return 1;
}
ret = bd_ensure_init (plugins, (BDUtilsLogFunc) _log, &error);
if (!ret) {
g_print ("Error initializing libblockdev library: %s (%s, %d)\n",
error->message, g_quark_to_string (error->domain), error->code);
return 1;
}
ret = bd_lvm_set_global_config ("log {level=7 file=/tmp/lvm.log syslog=0}", &error);
if (!ret) {
g_print ("Error setting LVM global config: %s (%s, %d)\n",
error->message, g_quark_to_string (error->domain), error->code);
return 1;
}
ret = bd_lvm_lvsnapshotmerge (VGNAME, SNAPNAME, extra_args, &error);
if (!ret) {
g_print ("Error running snapshot merge: %s (%s, %d)\n",
error->message, g_quark_to_string (error->domain), error->code);
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment