src/client.c | 21 ++++++++++++--------- src/main.c | 23 ++++++++++++----------- src/sanlock_admin.h | 6 ++---- 3 files changed, 26 insertions(+), 24 deletions(-)
New commits: commit 1c6186c3df0f0cf097fdf0b637003ba5b5ced632 Author: David Teigland teigland@redhat.com Date: Tue Jan 8 16:03:42 2013 -0600
sanlock: make get_lockspaces allocate space for data
Change get_lockspaces api so the client lib will allocate memory for the lockspace data and return it to the caller who will free it.
Signed-off-by: David Teigland teigland@redhat.com
diff --git a/src/client.c b/src/client.c index ec2953f..5c78354 100644 --- a/src/client.c +++ b/src/client.c @@ -163,10 +163,10 @@ int sanlock_rem_lockspace(struct sanlk_lockspace *ls, uint32_t flags) return cmd_lockspace(SM_CMD_REM_LOCKSPACE, ls, flags, 0); }
-int sanlock_get_lockspaces(struct sanlk_lockspace *lss, int lss_size, - int *lss_count, uint32_t flags) +int sanlock_get_lockspaces(struct sanlk_lockspace **lss, int *lss_count, + uint32_t flags) { - struct sanlk_lockspace *ls; + struct sanlk_lockspace *lsbuf, *ls; struct sm_header h; int rv, fd, i, ret, recv_count;
@@ -202,30 +202,33 @@ int sanlock_get_lockspaces(struct sanlk_lockspace *lss, int lss_size, *lss_count = h.data2; recv_count = h.data2;
- if (recv_count * sizeof(struct sanlk_lockspace) > lss_size) { - recv_count = lss_size / sizeof(struct sanlk_lockspace); - rv = -ENOBUFS; - } - if (!lss) goto out;
- ls = lss; + lsbuf = malloc(recv_count * sizeof(struct sanlk_lockspace)); + if (!lsbuf) + goto out; + + ls = lsbuf;
for (i = 0; i < recv_count; i++) { ret = recv(fd, ls, sizeof(struct sanlk_lockspace), MSG_WAITALL); if (ret < 0) { rv = -errno; + free(lsbuf); goto out; }
if (ret != sizeof(struct sanlk_lockspace)) { rv = -1; + free(lsbuf); goto out; }
ls++; } + + *lss = lsbuf; out: close(fd); return rv; diff --git a/src/main.c b/src/main.c index 0291e22..90436a5 100644 --- a/src/main.c +++ b/src/main.c @@ -2145,10 +2145,9 @@ static int do_client(void) { struct sanlk_resource **res_args = NULL; struct sanlk_resource *res; - struct sanlk_lockspace *ls; + struct sanlk_lockspace *lss, *ls; char *res_state = NULL; char *res_str = NULL; - char *buf; uint32_t io_timeout = 0; int i, fd, count; int rv = 0; @@ -2173,21 +2172,23 @@ static int do_client(void) break;
case ACT_GETS: - buf = malloc(ONEMB); - if (!buf) - break; - memset(buf, 0, ONEMB); - ls = (struct sanlk_lockspace *)buf; + lss = NULL;
- rv = sanlock_get_lockspaces(ls, ONEMB, &count, 0); + rv = sanlock_get_lockspaces(&lss, &count, 0); if (rv < 0) log_tool("gets error %d", rv);
- if (rv < 0 && rv != -ENOBUFS && rv != -ENOSPC) { - free(buf); + if (rv < 0 && rv != -ENOSPC) { + if (lss) + free(lss); break; }
+ if (!lss) + break; + + ls = lss; + for (i = 0; i < count; i++) { log_tool("s %.48s:%llu:%s:%llu %s", ls->name, @@ -2198,7 +2199,7 @@ static int do_client(void) ls++; }
- free(buf); + free(lss); break;
case ACT_LOG_DUMP: diff --git a/src/sanlock_admin.h b/src/sanlock_admin.h index dadd034..5d3d5af 100644 --- a/src/sanlock_admin.h +++ b/src/sanlock_admin.h @@ -67,14 +67,12 @@ int sanlock_rem_lockspace(struct sanlk_lockspace *ls, uint32_t flags); * 0: all lockspaces copied out, lss_count set to number * -ENOSPC: sanlock internal buffer ran out of space * (lss_count set to number that would have been copied) - * -ENOBUFS: lss_size too small - * (lss_count set to number that would have been copied) * * sanlk_lockspace.flags set to SANLK_LSF_ */
-int sanlock_get_lockspaces(struct sanlk_lockspace *lss, int lss_size, - int *lss_count, uint32_t flags); +int sanlock_get_lockspaces(struct sanlk_lockspace **lss, int *lss_count, + uint32_t flags);
/* * Returns the alignment in bytes required by sanlock_init()
sanlock-devel@lists.fedorahosted.org