Skip to content

Instantly share code, notes, and snippets.

@vojtechtrefny
Created January 3, 2022 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojtechtrefny/7f379596958a0c4cd4c287c3f7a7dddd to your computer and use it in GitHub Desktop.
Save vojtechtrefny/7f379596958a0c4cd4c287c3f7a7dddd to your computer and use it in GitHub Desktop.
#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