Discussion:
[linux-lvm] HOWTO: create a thick logical snapshot from C
Tomas Dalebjörk
2014-04-21 09:59:05 UTC
Permalink
Hi,

I want to create the snapshot like this command, but from C.

lvcreate -s -c 512k -n snap -L 1G testvg/lvol1

Just to try; I compiled this program, but it can't resolve the references
-------
#include "lvm2app.h"

int snaplv(char *vgname, char *lvname)
{
int rc;
lvm_t handle;
vg_t vg;
lv_t lv;
lv_t lvsnap;
char msg[200];
char *snap_name="snap";
struct lvm_lv_create_params *lvcp = NULL;
uint64_t max_snap_size = 1*1024*1024*1024;

handle = lvm_init(NULL);

if(!handle)
return -1;

vg = lvm_vg_open(handle, vgname, "r", 0);
if(!vg && lvm_errno(handle))
{
lvm_quit(handle);
return -1;
}

lv = lvm_lv_from_name(vg, lvname);
if(!lv)
{
lvm_vg_close(vg);
lvm_quit(handle);

return -1;
}

lvsnap = lvm_lv_snapshot(lv, strdup(snap_name), max_snap_size);
lvm_vg_close(vg);
lvm_quit(handle);

return 0;
}

void main(void)
{
snaplv("testvg","test");
}
--------------------------------
Compiling gives error

[***@centos64 ~]# gcc -llvm2app snaplv.c
snaplv.c: In function ‘snaplv’:
snaplv.c:36: warning: assignment makes pointer from integer without a cast
/tmp/ccvgg1K0.o: In function `snaplv':
snaplv.c:(.text+0x105): undefined reference to `lvm_lv_snapshot'
collect2: ld returned 1 exit status
[***@centos64 ~]#

-----------------------------

Can anyone share an idea how to do this from C; without using system()

Regards Tomas

Loading...