1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-05 13:18:20 +03:00

Import snapshot status & persistence + indent etc.

This commit is contained in:
Alasdair Kergon 2002-05-10 15:25:38 +00:00
parent 1951dba955
commit 92ad2d555b
3 changed files with 42 additions and 59 deletions

View File

@ -41,7 +41,6 @@ static char *dm_cmd_list[] = {
"waitevent"
};
static void *_align(void *ptr, unsigned int a)
{
register unsigned long align = --a;
@ -85,46 +84,46 @@ int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size)
return 1;
}
void *dm_get_next_target(struct dm_task *dmt, void *next, unsigned long long *start,
unsigned long long *length,
char **target_type,
char **params)
void *dm_get_next_target(struct dm_task *dmt, void *next,
uint64_t *start, uint64_t *length,
char **target_type, char **params)
{
struct target *t;
struct target *t = (struct target *) next;
if (!next)
next = dmt->head;
if (!t)
t = dmt->head;
t = next;
if (t) {
if (!t)
return NULL;
*start = t->start;
*length = t->length;
*target_type = t->type;
*params = t->params;
return t->next;
}
return NULL;
}
/* Unmarshall the target info returned from a status call */
static int unmarshal_status(struct dm_task *dmt, struct dm_ioctl *dmi)
static int _unmarshal_status(struct dm_task *dmt, struct dm_ioctl *dmi)
{
char *outbuf = (char *)dmi + sizeof(struct dm_ioctl);
char *outbuf = (char *) dmi + sizeof(struct dm_ioctl);
char *outptr = outbuf;
int i;
for (i=0; i < dmi->target_count; i++) {
struct dm_target_spec *spec = (struct dm_target_spec *)outptr;
for (i = 0; i < dmi->target_count; i++) {
struct dm_target_spec *spec = (struct dm_target_spec *) outptr;
if (!dm_task_add_target(dmt, spec->sector_start, spec->length,
spec->target_type, outptr+sizeof(*spec)))
return 0;
outptr += sizeof(struct dm_target_spec);
outptr += strlen(outptr) + 1;
_align(outptr, ALIGNMENT);
if (!dm_task_add_target(dmt, spec->sector_start, spec->length,
spec->target_type,
outptr + sizeof(*spec)))
return 0;
outptr += sizeof(struct dm_target_spec);
outptr += strlen(outptr) + 1;
_align(outptr, ALIGNMENT);
}
return 1;
}
@ -175,8 +174,8 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname)
return 1;
}
struct target *create_target(uint64_t start,
uint64_t len, const char *type, const char *params)
struct target *create_target(uint64_t start, uint64_t len, const char *type,
const char *params)
{
struct target *t = malloc(sizeof(*t));
@ -386,12 +385,12 @@ int dm_task_run(struct dm_task *dmt)
break;
case DM_DEVICE_TABLE:
dmi->flags |= DM_STATUS_TABLE_FLAG;
dmi->flags |= DM_STATUS_TABLE_FLAG;
command = DM_GET_STATUS;
break;
case DM_DEVICE_WAITEVENT:
command = DM_WAIT_EVENT;
command = DM_WAIT_EVENT;
break;
default:
@ -423,9 +422,9 @@ int dm_task_run(struct dm_task *dmt)
case DM_DEVICE_STATUS:
case DM_DEVICE_TABLE:
if (!unmarshal_status(dmt, dmi))
goto bad;
break;
if (!_unmarshal_status(dmt, dmi))
goto bad;
break;
}
dmt->dmi = dmi;

View File

@ -97,10 +97,8 @@ int dm_task_add_target(struct dm_task *dmt,
/* Use this to retrive target information returned from a STATUS call */
void *dm_get_next_target(struct dm_task *dmt,
void *next, unsigned long long *start,
unsigned long long *length,
char **target_type,
char **params);
void *next, uint64_t *start, uint64_t *length,
char **target_type, char **params);
/*
* Call this to actually run the ioctl.

View File

@ -229,21 +229,7 @@ static int _resume(int argc, char **argv)
static int _wait(int argc, char **argv)
{
struct dm_task *dmt;
if (!(dmt = dm_task_create(DM_DEVICE_WAITEVENT)))
return 0;
if (!dm_task_set_name(dmt, argv[1]))
goto out;
if (!dm_task_run(dmt))
goto out;
dm_task_destroy(dmt);
out:
return 1;
return _simple(DM_DEVICE_WAITEVENT, argv[1]);
}
static int _status(int argc, char **argv)
@ -251,15 +237,15 @@ static int _status(int argc, char **argv)
int r = 0;
struct dm_task *dmt;
void *next = NULL;
unsigned long long start, length;
uint64_t start, length;
char *target_type = NULL;
char *params;
int cmd;
if (strcmp(argv[0], "status") == 0)
cmd = DM_DEVICE_STATUS;
if (!strcmp(argv[0], "status"))
cmd = DM_DEVICE_STATUS;
else
cmd = DM_DEVICE_TABLE;
cmd = DM_DEVICE_TABLE;
if (!(dmt = dm_task_create(cmd)))
return 0;
@ -272,12 +258,12 @@ static int _status(int argc, char **argv)
/* Fetch targets and print 'em */
do {
next = dm_get_next_target(dmt, next, &start, &length,
&target_type, &params);
if (target_type) {
printf("%lld %lld %s %s\n",
start, length, target_type, params);
}
next = dm_get_next_target(dmt, next, &start, &length,
&target_type, &params);
if (target_type) {
printf("%"PRIu64" %"PRIu64" %s %s\n",
start, length, target_type, params);
}
} while (next);
r = 1;