FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 11-27-2007, 07:57 PM
 
Default device-mapper ./WHATS_NEW dmsetup/dmsetup.c li ...

CVSROOT: /cvs/dm
Module name: device-mapper
Changes by: agk@sourceware.org 2007-11-27 20:57:05

Modified files:
. : WHATS_NEW
dmsetup : dmsetup.c
lib : .exported_symbols libdevmapper.h libdm-common.c
libdm-deptree.c
lib/ioctl : libdm-iface.c libdm-targets.h
man : dmsetup.8

Log message:
add read_ahead functions to library and dmsetup --readahead
(Not live yet.)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/WHATS_NEW.diff?cvsroot=dm&r1=1.210&r2=1.211
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/dmsetup/dmsetup.c.diff?cvsroot=dm&r1=1.96&r2=1.97
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/.exported_symbols.diff?cvsroot=dm&r1=1.31&r2=1.32
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdevmapper.h.diff?cvsroot=dm&r1=1.76&r2=1.77
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdm-common.c.diff?cvsroot=dm&r1=1.47&r2=1.48
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdm-deptree.c.diff?cvsroot=dm&r1=1.32&r2=1.33
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/ioctl/libdm-iface.c.diff?cvsroot=dm&r1=1.46&r2=1.47
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/ioctl/libdm-targets.h.diff?cvsroot=dm&r1=1.21&r2=1.22
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/man/dmsetup.8.diff?cvsroot=dm&r1=1.18&r2=1.19

--- device-mapper/WHATS_NEW 2007/11/27 12:26:06 1.210
+++ device-mapper/WHATS_NEW 2007/11/27 20:57:04 1.211
@@ -1,7 +1,8 @@
Version 1.02.23 -
==================================
- Fix possible double-free in libdevmapper-event.
- Define DM_READ_AHEAD_* values and flags.
+ Add --readahead to dmsetup.
+ Add external read_ahead library functions and DM_READ_AHEAD_* definitions.
+ Fix double free in a libdevmapper-event error path.
Fix configure --with-dmeventd-path substitution.
Allow $DM_DEV_DIR envvar to override default of "/dev".
Create e.g., libdevmapper.so.1.02, in build dir alongside the .so file.
--- device-mapper/dmsetup/dmsetup.c 2007/10/09 12:14:48 1.96
+++ device-mapper/dmsetup/dmsetup.c 2007/11/27 20:57:05 1.97
@@ -120,6 +120,7 @@
NOOPENCOUNT_ARG,
NOTABLE_ARG,
OPTIONS_ARG,
+ READAHEAD_ARG,
SEPARATOR_ARG,
SHOWKEYS_ARG,
SORT_ARG,
@@ -336,6 +337,8 @@
info->suspended ? "SUSPENDED" : "ACTIVE",
info->read_only ? " (READ-ONLY)" : "");

+ printf("Read Ahead: %d
", (int) dm_task_get_read_ahead(dmt));
+
if (!info->live_table && !info->inactive_table)
printf("Tables present: None
");
else
@@ -494,6 +497,11 @@
if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt))
goto out;

+ /* FIXME Provide way to set read_ahead_flags */
+ if (_switches[READAHEAD_ARG] &&
+ !dm_task_set_read_ahead(dmt, _int_args[READAHEAD_ARG], 0))
+ goto out;
+
if (!dm_task_run(dmt))
goto out;

@@ -673,6 +681,11 @@
if (_switches[NOLOCKFS_ARG] && !dm_task_skip_lockfs(dmt))
goto out;

+ /* FIXME Provide way to set read_ahead_flags */
+ if (_switches[READAHEAD_ARG] &&
+ !dm_task_set_read_ahead(dmt, _int_args[READAHEAD_ARG], 0))
+ goto out;
+
r = dm_task_run(dmt);

if (r && display && _switches[VERBOSE_ARG])
@@ -1594,6 +1607,16 @@
return dm_report_field_string(rh, field, &uuid);
}

+static int _dm_read_ahead_disp(struct dm_report *rh,
+ struct dm_pool *mem __attribute((unused)),
+ struct dm_report_field *field, const void *data,
+ void *private __attribute((unused)))
+{
+ int32_t value = (int32_t) dm_task_get_read_ahead((const struct dm_task *) data);
+
+ return dm_report_field_int32(rh, field, &value);
+}
+
static int _dm_info_status_disp(struct dm_report *rh,
struct dm_pool *mem __attribute((unused)),
struct dm_report_field *field, const void *data,
@@ -1849,6 +1872,10 @@
/* *INDENT-OFF* */
FIELD_F(TASK, STR, "Name", 16, dm_name, "name", "Name of mapped device.")
FIELD_F(TASK, STR, "UUID", 32, dm_uuid, "uuid", "Unique (optional) identifier for mapped device.")
+
+/* FIXME Next one should be INFO */
+FIELD_F(TASK, NUM, "RAhead", 6, dm_read_ahead, "readahead", "Read ahead in sectors.")
+
FIELD_F(INFO, STR, "Stat", 4, dm_info_status, "attr", "(L)ive, (I)nactive, (s)uspended, (r)ead-only, read-(w)rite.")
FIELD_F(INFO, STR, "DevNo", 5, dm_info_devno, "devno", "Device major and minor numbers")
FIELD_O(INFO, dm_info, NUM, "Maj", major, 3, int32, "major", "Block device major number.")
@@ -2010,7 +2037,8 @@

fprintf(out, "Usage:

");
fprintf(out, "dmsetup [--version] [-v|--verbose [-v|--verbose ...]]
"
- " [-r|--readonly] [--noopencount] [--nolockfs]
"
+ " [-r|--readonly] [--noopencount] [--nolockfs] "
+ "[--readahead <sectors>]
"
" [-c|-C|--columns] [-o <fields>] [-O|--sort <sort_fields>]
"
" [--noheadings] [--separator <separator>]

");
for (i = 0; _commands[i].name; i++)
@@ -2374,6 +2402,7 @@
{"noopencount", 0, &ind, NOOPENCOUNT_ARG},
{"notable", 0, &ind, NOTABLE_ARG},
{"options", 1, &ind, OPTIONS_ARG},
+ {"readahead", 1, &ind, READAHEAD_ARG},
{"separator", 1, &ind, SEPARATOR_ARG},
{"showkeys", 0, &ind, SHOWKEYS_ARG},
{"sort", 1, &ind, SORT_ARG},
@@ -2506,6 +2535,11 @@
_switches[NOLOCKFS_ARG]++;
if ((ind == NOOPENCOUNT_ARG))
_switches[NOOPENCOUNT_ARG]++;
+ /* FIXME Accept auto/none & set read_ahead_flags too */
+ if ((ind == READAHEAD_ARG)) {
+ _switches[READAHEAD_ARG]++;
+ _int_args[READAHEAD_ARG] = atoi(optarg);
+ }
if ((ind == SHOWKEYS_ARG))
_switches[SHOWKEYS_ARG]++;
if ((ind == TABLE_ARG)) {
--- device-mapper/lib/.exported_symbols 2007/07/28 10:48:36 1.31
+++ device-mapper/lib/.exported_symbols 2007/11/27 20:57:05 1.32
@@ -18,6 +18,7 @@
dm_task_get_names
dm_task_get_versions
dm_task_get_uuid
+dm_task_get_read_ahead
dm_task_set_ro
dm_task_set_newname
dm_task_set_event_nr
@@ -28,6 +29,7 @@
dm_task_set_uid
dm_task_set_gid
dm_task_set_mode
+dm_task_set_read_ahead
dm_task_suppress_identical_reload
dm_task_add_target
dm_task_no_flush
@@ -67,6 +69,7 @@
dm_tree_node_add_mirror_target
dm_tree_node_add_mirror_target_log
dm_tree_node_add_target_area
+dm_tree_node_set_read_ahead
dm_tree_skip_lockfs
dm_tree_use_no_flush_suspend
dm_is_dm_major
--- device-mapper/lib/libdevmapper.h 2007/11/12 20:47:18 1.76
+++ device-mapper/lib/libdevmapper.h 2007/11/27 20:57:05 1.77
@@ -141,11 +141,6 @@
struct dm_names *dm_task_get_names(struct dm_task *dmt);
struct dm_versions *dm_task_get_versions(struct dm_task *dmt);

-#define DM_READ_AHEAD_AUTO UINT32_MAX /* Use kernel default readahead */
-#define DM_READ_AHEAD_NONE 0 /* Disable readahead */
-
-#define DM_READ_AHEAD_MINIMUM_FLAG 0x1 /* Value supplied is minimum */
-
int dm_task_set_ro(struct dm_task *dmt);
int dm_task_set_newname(struct dm_task *dmt, const char *newname);
int dm_task_set_minor(struct dm_task *dmt, int minor);
@@ -163,6 +158,18 @@
int dm_task_suppress_identical_reload(struct dm_task *dmt);

/*
+ * Control read_ahead.
+ */
+#define DM_READ_AHEAD_AUTO UINT32_MAX /* Use kernel default readahead */
+#define DM_READ_AHEAD_NONE 0 /* Disable readahead */
+
+#define DM_READ_AHEAD_MINIMUM_FLAG 0x1 /* Value supplied is minimum */
+
+int dm_task_set_read_ahead(struct dm_task *dmt, uint32_t read_ahead,
+ uint32_t read_ahead_flags);
+uint32_t dm_task_get_read_ahead(const struct dm_task *dmt);
+
+/*
* Use these to prepare for a create or reload.
*/
int dm_task_add_target(struct dm_task *dmt,
@@ -381,6 +388,13 @@
const char *dlid,
uint64_t offset);

+/*
+ * Set readahead (in sectors) after loading the node.
+ */
+void dm_tree_node_set_read_ahead(struct dm_tree_node *dnode,
+ uint32_t read_ahead,
+ uint32_t read_ahead_flags);
+
/************************************************** ***************************
* Library functions
************************************************** ***************************/
--- device-mapper/lib/libdm-common.c 2007/10/09 12:14:48 1.47
+++ device-mapper/lib/libdm-common.c 2007/11/27 20:57:05 1.48
@@ -118,6 +118,8 @@
dmt->gid = DEVICE_GID;
dmt->mode = DEVICE_MODE;
dmt->no_open_count = 0;
+ dmt->read_ahead = DM_READ_AHEAD_AUTO;
+ dmt->read_ahead_flags = 0;

return dmt;
}
--- device-mapper/lib/libdm-deptree.c 2007/08/21 16:26:06 1.32
+++ device-mapper/lib/libdm-deptree.c 2007/11/27 20:57:05 1.33
@@ -95,6 +95,9 @@
uint32_t major;
uint32_t minor;

+ uint32_t read_ahead;
+ uint32_t read_ahead_flags;
+
unsigned segment_count;
struct list segs;

@@ -609,6 +612,8 @@
}

dnode->props.read_only = read_only ? 1 : 0;
+ dnode->props.read_ahead = DM_READ_AHEAD_AUTO;
+ dnode->props.read_ahead_flags = 0;

if (clear_inactive && !_node_clear_table(dnode))
return_NULL;
@@ -618,6 +623,14 @@
return dnode;
}

+void dm_tree_node_set_read_ahead(struct dm_tree_node *dnode,
+ uint32_t read_ahead,
+ uint32_t read_ahead_flags)
+{
+ dnode->props.read_ahead = read_ahead;
+ dnode->props.read_ahead_flags = read_ahead_flags;
+}
+
int dm_tree_add_dev(struct dm_tree *dtree, uint32_t major, uint32_t minor)
{
return _add_dev(dtree, &dtree->root, major, minor) ? 1 : 0;
@@ -875,6 +888,7 @@

/* FIXME Merge with _suspend_node? */
static int _resume_node(const char *name, uint32_t major, uint32_t minor,
+ uint32_t read_ahead, uint32_t read_ahead_flags,
struct dm_info *newinfo)
{
struct dm_task *dmt;
@@ -896,6 +910,9 @@
if (!dm_task_no_open_count(dmt))
log_error("Failed to disable open_count");

+ if (!dm_task_set_read_ahead(dmt, read_ahead, read_ahead_flags))
+ log_error("Failed to set read ahead");
+
if ((r = dm_task_run(dmt)))
r = dm_task_get_info(dmt, newinfo);

@@ -1136,7 +1153,9 @@
if (!child->info.inactive_table && !child->info.suspended)
continue;

- if (!_resume_node(name, child->info.major, child->info.minor, &newinfo)) {
+ if (!_resume_node(name, child->info.major, child->info.minor,
+ child->props.read_ahead,
+ child->props.read_ahead_flags, &newinfo)) {
log_error("Unable to resume %s (%" PRIu32
":%" PRIu32 ")", name, child->info.major,
child->info.minor);
@@ -1527,7 +1546,9 @@
if (!child->info.inactive_table && !child->info.suspended)
continue;

- if (!_resume_node(name, child->info.major, child->info.minor, &newinfo)) {
+ if (!_resume_node(name, child->info.major, child->info.minor,
+ child->props.read_ahead,
+ child->props.read_ahead_flags, &newinfo)) {
log_error("Unable to resume %s (%" PRIu32
":%" PRIu32 ")", name, child->info.major,
child->info.minor);
--- device-mapper/lib/ioctl/libdm-iface.c 2007/08/21 16:26:07 1.46
+++ device-mapper/lib/ioctl/libdm-iface.c 2007/11/27 20:57:05 1.47
@@ -920,6 +920,14 @@
return 1;
}

+uint32_t dm_task_get_read_ahead(const struct dm_task *dmt)
+{
+ uint32_t read_ahead = 0; //FIXME default? How cope with failure below?
+ // FIXME (void) dm_blockdev_get_read_ahead(dmt->dev_name, &read_ahead);
+
+ return read_ahead;
+}
+
const char *dm_task_get_name(const struct dm_task *dmt)
{
#ifdef DM_COMPAT
@@ -974,6 +982,15 @@
return 1;
}

+int dm_task_set_read_ahead(struct dm_task *dmt, uint32_t read_ahead,
+ uint32_t read_ahead_flags)
+{
+ dmt->read_ahead = read_ahead;
+ dmt->read_ahead_flags = read_ahead_flags;
+
+ return 1;
+}
+
int dm_task_suppress_identical_reload(struct dm_task *dmt)
{
dmt->suppress_identical_reload = 1;
--- device-mapper/lib/ioctl/libdm-targets.h 2007/08/21 16:26:07 1.21
+++ device-mapper/lib/ioctl/libdm-targets.h 2007/11/27 20:57:05 1.22
@@ -44,6 +44,8 @@
uid_t uid;
gid_t gid;
mode_t mode;
+ uint32_t read_ahead;
+ uint32_t read_ahead_flags;
union {
struct dm_ioctl *v4;
struct dm_ioctl_v1 *v1;
--- device-mapper/man/dmsetup.8 2007/10/09 12:14:48 1.18
+++ device-mapper/man/dmsetup.8 2007/11/27 20:57:05 1.19
@@ -114,6 +114,9 @@
.IP fB-r|--readonly
.br
Set the table being loaded read-only.
+.IP fB--readahead <sectors>
+.br
+Specify read ahead size in units of sectors.
.IP fB--table <table>
.br
Specify a one-line table directly on the command line.

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 04-19-2008, 03:50 PM
 
Default device-mapper ./WHATS_NEW dmsetup/dmsetup.c li ...

CVSROOT: /cvs/dm
Module name: device-mapper
Changes by: agk@sourceware.org 2008-04-19 15:50:18

Modified files:
. : WHATS_NEW
dmsetup : dmsetup.c
lib : libdevmapper.h libdm-report.c
lib/mm : pool-debug.c pool-fast.c

Log message:
Calculate string size within dm_pool_grow_object.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/WHATS_NEW.diff?cvsroot=dm&r1=1.227&r2=1.228
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/dmsetup/dmsetup.c.diff?cvsroot=dm&r1=1.103&r2=1.104
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdevmapper.h.diff?cvsroot=dm&r1=1.79&r2=1.80
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdm-report.c.diff?cvsroot=dm&r1=1.16&r2=1.17
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/mm/pool-debug.c.diff?cvsroot=dm&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/mm/pool-fast.c.diff?cvsroot=dm&r1=1.4&r2=1.5

--- device-mapper/WHATS_NEW 2008/04/10 18:04:31 1.227
+++ device-mapper/WHATS_NEW 2008/04/19 15:50:17 1.228
@@ -1,5 +1,6 @@
Version 1.02.26 -
=================================
+ Calculate string size within dm_pool_grow_object.

Version 1.02.25 - 10th April 2008
=================================
--- device-mapper/dmsetup/dmsetup.c 2007/12/05 17:05:04 1.103
+++ device-mapper/dmsetup/dmsetup.c 2008/04/19 15:50:17 1.104
@@ -1697,7 +1697,7 @@
log_error("dm_pool_grow_object failed");
goto out_abandon;
}
- if (!dm_pool_grow_object(mem, name, strlen(name))) {
+ if (!dm_pool_grow_object(mem, name, 0)) {
log_error("dm_pool_grow_object failed");
goto out_abandon;
}
@@ -1763,7 +1763,7 @@
log_error("dm_snprintf failed");
goto out_abandon;
}
- if (!dm_pool_grow_object(mem, buf, strlen(buf))) {
+ if (!dm_pool_grow_object(mem, buf, 0)) {
log_error("dm_pool_grow_object failed");
goto out_abandon;
}
@@ -1816,7 +1816,7 @@
log_error("dm_snprintf failed");
goto out_abandon;
}
- if (!dm_pool_grow_object(mem, buf, strlen(buf))) {
+ if (!dm_pool_grow_object(mem, buf, 0)) {
log_error("dm_pool_grow_object failed");
goto out_abandon;
}
--- device-mapper/lib/libdevmapper.h 2007/12/05 16:28:19 1.79
+++ device-mapper/lib/libdevmapper.h 2008/04/19 15:50:18 1.80
@@ -500,7 +500,7 @@
*
* for (i = 0; i < 50; i++) {
* snprintf(buffer, sizeof(buffer), "%d, ", i);
- * if (!dm_pool_grow_object(mem, buffer, strlen(buffer)))
+ * if (!dm_pool_grow_object(mem, buffer, 0))
* goto bad;
* }
*
@@ -524,6 +524,7 @@
* dm_pool_grow_object. Finally get your object with
* a call to dm_pool_end_object.
*
+ * Setting delta to 0 means it will use strlen(extra).
*/
int dm_pool_begin_object(struct dm_pool *p, size_t hint);
int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t delta);
--- device-mapper/lib/libdm-report.c 2008/01/20 01:14:38 1.16
+++ device-mapper/lib/libdm-report.c 2008/04/19 15:50:18 1.17
@@ -668,15 +668,13 @@
log_error("dm_report: Failed to generate report headings for printing");
goto bad;
}
- } else if (!dm_pool_grow_object(rh->mem, heading,
- strlen(heading))) {
+ } else if (!dm_pool_grow_object(rh->mem, heading, 0)) {
log_error("dm_report: Failed to generate report headings for printing");
goto bad;
}

if (!list_end(&rh->field_props, &fp->list))
- if (!dm_pool_grow_object(rh->mem, rh->separator,
- strlen(rh->separator))) {
+ if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
log_error("dm_report: Failed to generate report headings for printing");
goto bad;
}
@@ -803,8 +801,7 @@
repstr = field->report_string;
width = field->props->width;
if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
- if (!dm_pool_grow_object(rh->mem, repstr,
- strlen(repstr))) {
+ if (!dm_pool_grow_object(rh->mem, repstr, 0)) {
log_error("dm_report: Unable to extend output line");
goto bad;
}
@@ -836,8 +833,7 @@
}

if (!list_end(&row->fields, fh))
- if (!dm_pool_grow_object(rh->mem, rh->separator,
- strlen(rh->separator))) {
+ if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
log_error("dm_report: Unable to extend output line");
goto bad;
}
--- device-mapper/lib/mm/pool-debug.c 2007/08/21 16:26:07 1.3
+++ device-mapper/lib/mm/pool-debug.c 2008/04/19 15:50:18 1.4
@@ -216,10 +216,10 @@
return 1;
}

-int dm_pool_grow_object(struct dm_pool *p, const void *buffer, size_t delta)
+int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t delta)
{
struct block *new;
- size_t size = delta;
+ size_t size = delta ? : strlen(extra);

assert(p->begun);

@@ -238,7 +238,7 @@
}
p->object = new;

- memcpy(new->data + size - delta, buffer, delta);
+ memcpy(new->data + size - delta, extra, delta);

return 1;
}
--- device-mapper/lib/mm/pool-fast.c 2007/08/21 16:26:07 1.4
+++ device-mapper/lib/mm/pool-fast.c 2008/04/19 15:50:18 1.5
@@ -162,14 +162,17 @@
return 1;
}

-int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t n)
+int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t delta)
{
struct chunk *c = p->chunk, *nc;

- if (c->end - (c->begin + p->object_len) < n) {
+ if (!delta)
+ delta = strlen(extra);
+
+ if (c->end - (c->begin + p->object_len) < delta) {
/* move into a new chunk */
- if (p->object_len + n > (p->chunk_size / 2))
- nc = _new_chunk(p, (p->object_len + n) * 2);
+ if (p->object_len + delta > (p->chunk_size / 2))
+ nc = _new_chunk(p, (p->object_len + delta) * 2);
else
nc = _new_chunk(p, p->chunk_size);

@@ -181,8 +184,8 @@
c = p->chunk;
}

- memcpy(c->begin + p->object_len, extra, n);
- p->object_len += n;
+ memcpy(c->begin + p->object_len, extra, delta);
+ p->object_len += delta;
return 1;
}


--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 06-24-2008, 08:16 PM
 
Default device-mapper ./WHATS_NEW dmsetup/dmsetup.c li ...

CVSROOT: /cvs/dm
Module name: device-mapper
Changes by: agk@sourceware.org 2008-06-24 20:16:47

Modified files:
. : WHATS_NEW
dmsetup : dmsetup.c
lib : libdevmapper.h libdm-report.c

Log message:
dmsetup --unquoted

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/WHATS_NEW.diff?cvsroot=dm&r1=1.242&r2=1.243
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/dmsetup/dmsetup.c.diff?cvsroot=dm&r1=1.109&r2=1.110
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdevmapper.h.diff?cvsroot=dm&r1=1.81&r2=1.82
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdm-report.c.diff?cvsroot=dm&r1=1.19&r2=1.20

--- device-mapper/WHATS_NEW 2008/06/18 10:19:25 1.242
+++ device-mapper/WHATS_NEW 2008/06/24 20:16:47 1.243
@@ -1,5 +1,6 @@
Version 1.02.27 -
===============================
+ Add --unquoted to dmsetup.
Avoid compiler warning about cast in dmsetup.c's OFFSET_OF macro.
Fix inverted no_flush debug message.
Remove --enable-jobs from configure. (Set at runtime instead.)
--- device-mapper/dmsetup/dmsetup.c 2008/06/18 10:19:25 1.109
+++ device-mapper/dmsetup/dmsetup.c 2008/06/24 20:16:47 1.110
@@ -130,6 +130,7 @@
TREE_ARG,
UID_ARG,
UNBUFFERED_ARG,
+ UNQUOTED_ARG,
UUID_ARG,
VERBOSE_ARG,
VERSION_ARG,
@@ -1975,7 +1976,7 @@
char *options = (char *) default_report_options;
const char *keys = "";
const char *separator = " ";
- int aligned = 1, headings = 1, buffered = 1, field_prefixes = 0;
+ int aligned = 1, headings = 1, buffered = 1, field_prefixes = 0, quoted = 1;
uint32_t flags = 0;
size_t len = 0;
int r = 0;
@@ -1990,6 +1991,9 @@
if (_switches[UNBUFFERED_ARG])
buffered = 0;

+ if (_switches[UNQUOTED_ARG])
+ quoted = 0;
+
if (_switches[NAMEPREFIXES_ARG]) {
aligned = 0;
field_prefixes = 1;
@@ -2040,6 +2044,9 @@
if (field_prefixes)
flags |= DM_REPORT_OUTPUT_FIELD_NAME_PREFIX;

+ if (!quoted)
+ flags |= DM_REPORT_OUTPUT_FIELD_UNQUOTED;
+
if (!(_report = dm_report_init(&_report_type,
_report_types, _report_fields,
options, separator, flags, keys, NULL)))
@@ -2492,6 +2499,7 @@
{"uid", 1, &ind, UID_ARG},
{"uuid", 1, &ind, UUID_ARG},
{"unbuffered", 0, &ind, UNBUFFERED_ARG},
+ {"unquoted", 0, &ind, UNQUOTED_ARG},
{"verbose", 1, &ind, VERBOSE_ARG},
{"version", 0, &ind, VERSION_ARG},
{0, 0, 0, 0}
@@ -2646,8 +2654,8 @@
}
if ((ind == TREE_ARG))
_switches[TREE_ARG]++;
- if ((ind == UNBUFFERED_ARG))
- _switches[UNBUFFERED_ARG]++;
+ if ((ind == UNQUOTED_ARG))
+ _switches[UNQUOTED_ARG]++;
if ((ind == VERSION_ARG))
_switches[VERSION_ARG]++;
}
--- device-mapper/lib/libdevmapper.h 2008/04/20 00:11:08 1.81
+++ device-mapper/lib/libdevmapper.h 2008/06/24 20:16:47 1.82
@@ -740,6 +740,7 @@
#define DM_REPORT_OUTPUT_BUFFERED 0x00000002
#define DM_REPORT_OUTPUT_HEADINGS 0x00000004
#define DM_REPORT_OUTPUT_FIELD_NAME_PREFIX 0x00000008
+#define DM_REPORT_OUTPUT_FIELD_UNQUOTED 0x00000010

struct dm_report *dm_report_init(uint32_t *report_types,
const struct dm_report_object_type *types,
--- device-mapper/lib/libdm-report.c 2008/06/06 19:07:47 1.19
+++ device-mapper/lib/libdm-report.c 2008/06/24 20:16:47 1.20
@@ -845,7 +845,13 @@

free(field_id);

- if (!dm_pool_grow_object(rh->mem, "='", 2)) {
+ if (!dm_pool_grow_object(rh->mem, "=", 1)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+
+ if (!(rh->flags & DM_REPORT_OUTPUT_FIELD_UNQUOTED) &&
+ !dm_pool_grow_object(rh->mem, "'", 1)) {
log_error("dm_report: Unable to extend output line");
goto bad;
}
@@ -885,7 +891,8 @@
}
}

- if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX)
+ if ((rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) &&
+ !(rh->flags & DM_REPORT_OUTPUT_FIELD_UNQUOTED))
if (!dm_pool_grow_object(rh->mem, "'", 1)) {
log_error("dm_report: Unable to extend output line");
goto bad;

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 06-24-2008, 10:53 PM
 
Default device-mapper ./WHATS_NEW dmsetup/dmsetup.c li ...

CVSROOT: /cvs/dm
Module name: device-mapper
Changes by: agk@sourceware.org 2008-06-24 22:53:48

Modified files:
. : WHATS_NEW
dmsetup : dmsetup.c
lib : libdevmapper.h libdm-report.c

Log message:
Add --rows to dmsetup.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/WHATS_NEW.diff?cvsroot=dm&r1=1.243&r2=1.244
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/dmsetup/dmsetup.c.diff?cvsroot=dm&r1=1.110&r2=1.111
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdevmapper.h.diff?cvsroot=dm&r1=1.82&r2=1.83
http://sourceware.org/cgi-bin/cvsweb.cgi/device-mapper/lib/libdm-report.c.diff?cvsroot=dm&r1=1.20&r2=1.21

--- device-mapper/WHATS_NEW 2008/06/24 20:16:47 1.243
+++ device-mapper/WHATS_NEW 2008/06/24 22:53:47 1.244
@@ -1,6 +1,6 @@
Version 1.02.27 -
===============================
- Add --unquoted to dmsetup.
+ Add --unquoted and --rows to dmsetup.
Avoid compiler warning about cast in dmsetup.c's OFFSET_OF macro.
Fix inverted no_flush debug message.
Remove --enable-jobs from configure. (Set at runtime instead.)
--- device-mapper/dmsetup/dmsetup.c 2008/06/24 20:16:47 1.110
+++ device-mapper/dmsetup/dmsetup.c 2008/06/24 22:53:47 1.111
@@ -122,6 +122,7 @@
NOTABLE_ARG,
OPTIONS_ARG,
READAHEAD_ARG,
+ ROWS_ARG,
SEPARATOR_ARG,
SHOWKEYS_ARG,
SORT_ARG,
@@ -1976,7 +1977,8 @@
char *options = (char *) default_report_options;
const char *keys = "";
const char *separator = " ";
- int aligned = 1, headings = 1, buffered = 1, field_prefixes = 0, quoted = 1;
+ int aligned = 1, headings = 1, buffered = 1, field_prefixes = 0;
+ int quoted = 1, columns_as_rows = 0;
uint32_t flags = 0;
size_t len = 0;
int r = 0;
@@ -1991,6 +1993,9 @@
if (_switches[UNBUFFERED_ARG])
buffered = 0;

+ if (_switches[ROWS_ARG])
+ columns_as_rows = 1;
+
if (_switches[UNQUOTED_ARG])
quoted = 0;

@@ -2047,6 +2052,9 @@
if (!quoted)
flags |= DM_REPORT_OUTPUT_FIELD_UNQUOTED;

+ if (columns_as_rows)
+ flags |= DM_REPORT_OUTPUT_COLUMNS_AS_ROWS;
+
if (!(_report = dm_report_init(&_report_type,
_report_types, _report_fields,
options, separator, flags, keys, NULL)))
@@ -2490,6 +2498,7 @@
{"notable", 0, &ind, NOTABLE_ARG},
{"options", 1, &ind, OPTIONS_ARG},
{"readahead", 1, &ind, READAHEAD_ARG},
+ {"rows", 0, &ind, ROWS_ARG},
{"separator", 1, &ind, SEPARATOR_ARG},
{"showkeys", 0, &ind, SHOWKEYS_ARG},
{"sort", 1, &ind, SORT_ARG},
@@ -2646,6 +2655,8 @@
}
}
}
+ if ((ind == ROWS_ARG))
+ _switches[ROWS_ARG]++;
if ((ind == SHOWKEYS_ARG))
_switches[SHOWKEYS_ARG]++;
if ((ind == TABLE_ARG)) {
--- device-mapper/lib/libdevmapper.h 2008/06/24 20:16:47 1.82
+++ device-mapper/lib/libdevmapper.h 2008/06/24 22:53:48 1.83
@@ -741,6 +741,7 @@
#define DM_REPORT_OUTPUT_HEADINGS 0x00000004
#define DM_REPORT_OUTPUT_FIELD_NAME_PREFIX 0x00000008
#define DM_REPORT_OUTPUT_FIELD_UNQUOTED 0x00000010
+#define DM_REPORT_OUTPUT_COLUMNS_AS_ROWS 0x00000020

struct dm_report *dm_report_init(uint32_t *report_types,
const struct dm_report_object_type *types,
--- device-mapper/lib/libdm-report.c 2008/06/24 20:16:47 1.20
+++ device-mapper/lib/libdm-report.c 2008/06/24 22:53:48 1.21
@@ -513,6 +513,14 @@

rh->flags |= output_flags & DM_REPORT_OUTPUT_MASK;

+ /* With columns_as_rows we must buffer and not align. */
+ if (output_flags & DM_REPORT_OUTPUT_COLUMNS_AS_ROWS) {
+ if (!(output_flags & DM_REPORT_OUTPUT_BUFFERED))
+ rh->flags |= DM_REPORT_OUTPUT_BUFFERED;
+ if (output_flags & DM_REPORT_OUTPUT_ALIGNED)
+ rh->flags &= ~DM_REPORT_OUTPUT_ALIGNED;
+ }
+
if (output_flags & DM_REPORT_OUTPUT_BUFFERED)
rh->flags |= RH_SORT_REQUIRED;

@@ -793,23 +801,146 @@
/*
* Produce report output
*/
-int dm_report_output(struct dm_report *rh)
+static int _output_field(struct dm_report *rh, struct dm_report_field *field)
{
- struct list *fh, *rowh, *ftmp, *rtmp;
- struct row *row = NULL;
- struct dm_report_field *field;
- const char *repstr;
char *field_id;
- char buf[4096];
int32_t width;
uint32_t align;
+ const char *repstr;
+ char buf[4096];

- if (list_empty(&rh->rows))
- return 1;
+ if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
+ if (!(field_id = strdup(rh->fields[field->props->field_num].id))) {
+ log_error("dm_report: Failed to copy field name");
+ return 0;
+ }

- /* Sort rows */
- if ((rh->flags & RH_SORT_REQUIRED))
- _sort_rows(rh);
+ if (!dm_pool_grow_object(rh->mem, rh->output_field_name_prefix, 0)) {
+ log_error("dm_report: Unable to extend output line");
+ return 0;
+ }
+
+ if (!dm_pool_grow_object(rh->mem, _toupperstr(field_id), 0)) {
+ log_error("dm_report: Unable to extend output line");
+ return 0;
+ }
+
+ free(field_id);
+
+ if (!dm_pool_grow_object(rh->mem, "=", 1)) {
+ log_error("dm_report: Unable to extend output line");
+ return 0;
+ }
+
+ if (!(rh->flags & DM_REPORT_OUTPUT_FIELD_UNQUOTED) &&
+ !dm_pool_grow_object(rh->mem, "'", 1)) {
+ log_error("dm_report: Unable to extend output line");
+ return 0;
+ }
+ }
+
+ repstr = field->report_string;
+ width = field->props->width;
+ if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
+ if (!dm_pool_grow_object(rh->mem, repstr, 0)) {
+ log_error("dm_report: Unable to extend output line");
+ return 0;
+ }
+ } else {
+ if (!(align = field->props->flags & DM_REPORT_FIELD_ALIGN_MASK))
+ align = (field->props->flags & DM_REPORT_FIELD_TYPE_NUMBER) ?
+ DM_REPORT_FIELD_ALIGN_RIGHT : DM_REPORT_FIELD_ALIGN_LEFT;
+ if (align & DM_REPORT_FIELD_ALIGN_LEFT) {
+ if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
+ width, width, repstr) < 0) {
+ log_error("dm_report: left-aligned snprintf() failed");
+ return 0;
+ }
+ if (!dm_pool_grow_object(rh->mem, buf, width)) {
+ log_error("dm_report: Unable to extend output line");
+ return 0;
+ }
+ } else if (align & DM_REPORT_FIELD_ALIGN_RIGHT) {
+ if (dm_snprintf(buf, sizeof(buf), "%*.*s",
+ width, width, repstr) < 0) {
+ log_error("dm_report: right-aligned snprintf() failed");
+ return 0;
+ }
+ if (!dm_pool_grow_object(rh->mem, buf, width)) {
+ log_error("dm_report: Unable to extend output line");
+ return 0;
+ }
+ }
+ }
+
+ if ((rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) &&
+ !(rh->flags & DM_REPORT_OUTPUT_FIELD_UNQUOTED))
+ if (!dm_pool_grow_object(rh->mem, "'", 1)) {
+ log_error("dm_report: Unable to extend output line");
+ return 0;
+ }
+
+ return 1;
+}
+
+static int _output_as_rows(struct dm_report *rh)
+{
+ struct field_properties *fp;
+ struct dm_report_field *field;
+ struct row *row;
+
+ if (!dm_pool_begin_object(rh->mem, 512)) {
+ log_error("dm_report: Unable to allocate output line");
+ return 0;
+ }
+
+ list_iterate_items(fp, &rh->field_props) {
+ if (fp->flags & FLD_HIDDEN)
+ continue;
+
+ if ((rh->flags & DM_REPORT_OUTPUT_HEADINGS)) {
+ if (!dm_pool_grow_object(rh->mem, rh->fields[fp->field_num].heading, 0)) {
+ log_error("dm_report: Failed to extend row for field name");
+ goto bad;
+ }
+ if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
+ log_error("dm_report: Failed to extend row with separator");
+ goto bad;
+ }
+ }
+
+ list_iterate_items(row, &rh->rows) {
+ field = list_item(list_first(&row->fields), struct dm_report_field);
+ if (!_output_field(rh, field))
+ goto bad;
+ list_del(&field->list);
+
+ if (!list_end(&rh->rows, &row->list))
+ if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+ }
+
+ if (!dm_pool_grow_object(rh->mem, "", 1)) {
+ log_error("dm_report: Failed to terminate row");
+ goto bad;
+ }
+ log_print("%s", (char *) dm_pool_end_object(rh->mem));
+ }
+
+ return 1;
+
+ bad:
+ dm_pool_abandon_object(rh->mem);
+ return 0;
+}
+
+static int _output_as_columns(struct dm_report *rh)
+{
+ struct list *fh, *rowh, *ftmp, *rtmp;
+ struct row *row = NULL;
+ struct dm_report_field *field;

/* If headings not printed yet, calculate field widths and print them */
if (!(rh->flags & RH_HEADINGS_PRINTED))
@@ -827,82 +958,15 @@
if (field->props->flags & FLD_HIDDEN)
continue;

- if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
- if (!(field_id = strdup(rh->fields[field->props->field_num].id))) {
- log_error("dm_report: Failed to copy field name");
- goto bad;
- }
-
- if (!dm_pool_grow_object(rh->mem, rh->output_field_name_prefix, 0)) {
- log_error("dm_report: Unable to extend output line");
- goto bad;
- }
-
- if (!dm_pool_grow_object(rh->mem, _toupperstr(field_id), 0)) {
- log_error("dm_report: Unable to extend output line");
- goto bad;
- }
-
- free(field_id);
-
- if (!dm_pool_grow_object(rh->mem, "=", 1)) {
- log_error("dm_report: Unable to extend output line");
- goto bad;
- }
-
- if (!(rh->flags & DM_REPORT_OUTPUT_FIELD_UNQUOTED) &&
- !dm_pool_grow_object(rh->mem, "'", 1)) {
- log_error("dm_report: Unable to extend output line");
- goto bad;
- }
- }
-
- repstr = field->report_string;
- width = field->props->width;
- if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
- if (!dm_pool_grow_object(rh->mem, repstr, 0)) {
- log_error("dm_report: Unable to extend output line");
- goto bad;
- }
- } else {
- if (!(align = field->props->flags & DM_REPORT_FIELD_ALIGN_MASK))
- align = (field->props->flags & DM_REPORT_FIELD_TYPE_NUMBER) ?
- DM_REPORT_FIELD_ALIGN_RIGHT : DM_REPORT_FIELD_ALIGN_LEFT;
- if (align & DM_REPORT_FIELD_ALIGN_LEFT) {
- if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
- width, width, repstr) < 0) {
- log_error("dm_report: left-aligned snprintf() failed");
- goto bad;
- }
- if (!dm_pool_grow_object(rh->mem, buf, width)) {
- log_error("dm_report: Unable to extend output line");
- goto bad;
- }
- } else if (align & DM_REPORT_FIELD_ALIGN_RIGHT) {
- if (dm_snprintf(buf, sizeof(buf), "%*.*s",
- width, width, repstr) < 0) {
- log_error("dm_report: right-aligned snprintf() failed");
- goto bad;
- }
- if (!dm_pool_grow_object(rh->mem, buf, width)) {
- log_error("dm_report: Unable to extend output line");
- goto bad;
- }
- }
- }
+ if (!_output_field(rh, field))
+ goto bad;

- if ((rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) &&
- !(rh->flags & DM_REPORT_OUTPUT_FIELD_UNQUOTED))
- if (!dm_pool_grow_object(rh->mem, "'", 1)) {
- log_error("dm_report: Unable to extend output line");
- goto bad;
- }
-
if (!list_end(&row->fields, fh))
if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
log_error("dm_report: Unable to extend output line");
goto bad;
}
+
list_del(&field->list);
}
if (!dm_pool_grow_object(rh->mem, "", 1)) {
@@ -922,3 +986,17 @@
dm_pool_abandon_object(rh->mem);
return 0;
}
+
+int dm_report_output(struct dm_report *rh)
+{
+ if (list_empty(&rh->rows))
+ return 1;
+
+ if ((rh->flags & RH_SORT_REQUIRED))
+ _sort_rows(rh);
+
+ if ((rh->flags & DM_REPORT_OUTPUT_COLUMNS_AS_ROWS))
+ return _output_as_rows(rh);
+ else
+ return _output_as_columns(rh);
+}

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 

Thread Tools




All times are GMT. The time now is 10:24 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org