Browse files

Merge commit '4a556d4599956c885c921fd8648149dbda3e43d2'

  • Loading branch information...
2 parents 010e8de + 4a556d4 commit 99e953882951f13f9874ca94e84a33bbf87fb22f Germano Percossi committed Jun 19, 2012
Showing with 67 additions and 14 deletions.
  1. +2 −1 control/tap-ctl-stats.c
  2. +32 −11 drivers/tapdisk-control.c
  3. +24 −2 drivers/tapdisk-stats.c
  4. +4 −0 drivers/tapdisk-stats.h
  5. +5 −0 vhd/lib/libvhd.c
View
3 control/tap-ctl-stats.c
@@ -148,11 +148,12 @@ tap_ctl_stats_fwrite(pid_t pid, int minor, FILE *stream)
len -= in;
out = fwrite(buf, in, 1, stream);
- if (out != in) {
+ if (out != 1) {
err = -errno;
goto out;
}
}
+ len = fwrite("\n", 1, 1, stream);
out:
if (sfd >= 0)
View
43 drivers/tapdisk-control.c
@@ -133,26 +133,22 @@ static void
tapdisk_ctl_conn_uninit(struct tapdisk_ctl_conn *conn)
{
if (conn->out.buf) {
- munmap(conn->out.buf, conn->out.bufsz);
+ free(conn->out.buf);
conn->out.buf = NULL;
}
}
static int
tapdisk_ctl_conn_init(struct tapdisk_ctl_conn *conn, size_t bufsz)
{
- int prot, flags, err;
+ int err;
memset(conn, 0, sizeof(*conn));
conn->out.event_id = -1;
conn->in.event_id = -1;
- prot = PROT_READ|PROT_WRITE;
- flags = MAP_ANONYMOUS|MAP_PRIVATE;
-
- conn->out.buf = mmap(NULL, bufsz, prot, flags, -1, 0);
- if (conn->out.buf == MAP_FAILED) {
- conn->out.buf = NULL;
+ conn->out.buf = malloc(bufsz);
+ if (!conn->out.buf) {
err = -ENOMEM;
goto fail;
}
@@ -960,10 +956,16 @@ tapdisk_control_stats(struct tapdisk_ctl_conn *conn,
td_stats_t _st, *st = &_st;
td_vbd_t *vbd;
size_t rv;
+ void *buf;
+ int new_size;
+
+ buf = malloc(TD_CTL_SEND_BUFSZ);
+ if (!buf) {
+ rv = -ENOMEM;
+ goto out;
+ }
- tapdisk_stats_init(st,
- conn->out.buf + sizeof(response),
- conn->out.bufsz - sizeof(response));
+ tapdisk_stats_init(st, buf, TD_CTL_SEND_BUFSZ);
if (request->cookie != (uint16_t)-1) {
@@ -987,7 +989,26 @@ tapdisk_control_stats(struct tapdisk_ctl_conn *conn,
}
rv = tapdisk_stats_length(st);
+
+ if (rv > conn->out.bufsz - sizeof(response)) {
+ ASSERT(conn->out.prod == conn->out.buf);
+ ASSERT(conn->out.cons == conn->out.buf);
+ new_size = rv + sizeof(response);
+ buf = realloc(conn->out.buf, new_size);
+ if (!buf) {
+ rv = -ENOMEM;
+ goto out;
+ }
+ conn->out.buf = buf;
+ conn->out.bufsz = new_size;
+ conn->out.prod = buf;
+ conn->out.cons = buf;
+ }
+ if (rv > 0) {
+ memcpy(conn->out.buf + sizeof(response), st->buf, rv);
+ }
out:
+ free(st->buf);
memset(&response, 0, sizeof(response));
response.type = TAPDISK_MESSAGE_STATS_RSP;
response.cookie = request->cookie;
View
26 drivers/tapdisk-stats.c
@@ -33,6 +33,8 @@
#include <stdio.h>
#include <stdarg.h>
+#include <stdlib.h>
+#include <errno.h>
#include "tapdisk.h"
#include "tapdisk-stats.h"
@@ -43,8 +45,28 @@ static void
__stats_vsprintf(td_stats_t *st,
const char *fmt, va_list ap)
{
- size_t size = st->buf + st->size - st->pos;
- st->pos += vsnprintf(st->pos, size, fmt, ap);
+ void *buf;
+ int written, new_size, off;
+ size_t size = 0;
+ written = 1;
+ while (written > size) {
+ size = st->buf + st->size - st->pos;
+ written = vsnprintf(st->pos, size, fmt, ap);
+ if (written <= size)
+ break;
+ new_size = st->size * 2;
+ buf = realloc(st->buf, new_size);
+ if (!buf) {
+ st->err = -ENOMEM;
+ written = size;
+ break;
+ }
+ off = st->pos - st->buf;
+ st->buf = buf;
+ st->size = new_size;
+ st->pos = st->buf + off;
+ }
+ st->pos += written;
}
static void __printf(2, 3)
View
4 drivers/tapdisk-stats.h
@@ -42,6 +42,7 @@ struct tapdisk_stats_ctx {
int n_elem[TD_STATS_MAX_DEPTH];
int depth;
+ int err;
};
typedef struct tapdisk_stats_ctx td_stats_t;
@@ -59,6 +60,9 @@ tapdisk_stats_init(td_stats_t *st, char *buf, size_t size)
static inline size_t
tapdisk_stats_length(td_stats_t *st)
{
+ if (st->err)
+ return st->err;
+
return st->pos - st->buf;
}
View
5 vhd/lib/libvhd.c
@@ -2804,6 +2804,11 @@ vhd_change_parent(vhd_context_t *child, char *parent_path, int raw)
vhd_context_t parent;
char __parent_path[PATH_MAX];
+ if (child->footer.type != HD_TYPE_DIFF) {
+ VHDLOG("would-be child is not a differencing disk\n");
+ return -EINVAL;
+ }
+
ppath = realpath(parent_path, __parent_path);
if (!ppath) {
VHDLOG("error resolving parent path %s for %s: %d\n",

0 comments on commit 99e9538

Please sign in to comment.