2011-12-05 08:09:55

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 0/10] pnfs-block ctl

Folks,

The following are fixes to Rick McNeal's user-space ctl daemon
for the pnfs block server.

They are available on:
git://linux-nfs.org/~bhalevy/pnfsd-block-ctl.git

The daemon is required on the server side to get the pnfs
block device EFI signature and volume signature.


[PATCH 01/10] use gcc
[PATCH 02/10] efi: fix user-land debug printouts
[PATCH 03/10] ctl: improve debug printouts
[PATCH 04/10] increase compiler warning level
[PATCH 05/10] ctl: always return a value from find_dm_name
[PATCH 06/10] add missing includes
[PATCH 07/10] ctl: fix compiler warnings
[PATCH 08/10] fix compiler warnings around get_output use of argv
[PATCH 09/10] ctl: main should return 0 on success
[PATCH 10/10] efi: fix compiler warnings


2011-12-05 08:14:41

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 10/10] efi: fix compiler warnings

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
efi.c | 10 +---------
1 files changed, 1 insertions(+), 9 deletions(-)

diff --git a/efi.c b/efi.c
index 67b6211..a8c70d2 100644
--- a/efi.c
+++ b/efi.c
@@ -123,8 +123,6 @@
static size_t
read_lba(int fd, u64 lba, u8 * buffer, size_t count)
{
- size_t totalreadcount = 0;
-
lseek(fd, lba * 512LL, 0);
return read(fd, buffer, count);
}
@@ -205,9 +203,6 @@ static int
is_gpt_valid(int fd, u64 lba,
gpt_header **gpt, gpt_entry **ptes)
{
- u32 crc, origcrc;
- u64 lastlba;
-
if (!(*gpt = alloc_read_gpt_header(fd, lba)))
return 0;

@@ -236,9 +231,6 @@ is_gpt_valid(int fd, u64 lba,
/* We're done, all's well */
return 1;

- fail_ptes:
- free(*ptes);
- *ptes = NULL;
fail:
free(*gpt);
*gpt = NULL;
@@ -284,7 +276,7 @@ efi_signature(int fd, struct partition_sig *sig)
gpt_entry *ptes = NULL;
int rval = 0;

- sig->ps_sector_off = (u32)&((gpt_header *)0)->disk_guid.b[0];
+ sig->ps_sector_off = __builtin_offsetof(gpt_header, disk_guid.b);
sig->ps_sector = GPT_PRIMARY_PARTITION_TABLE_LBA;
sig->ps_len = sizeof (efi_guid_t);

--
1.7.6


2011-12-05 08:13:11

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 02/10] efi: fix user-land debug printouts

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
efi.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/efi.c b/efi.c
index 20efb2b..b653092 100644
--- a/efi.c
+++ b/efi.c
@@ -98,9 +98,12 @@

#include "efi.h"

+#ifndef EFI_DEBUG
+#define EFI_DEBUG
+#endif
#undef EFI_DEBUG
#ifdef EFI_DEBUG
-#define Dprintk(x...) printk(KERN_DEBUG x)
+#define Dprintk(x...) fprintf(stderr, x)
#else
#define Dprintk(x...)
#endif
--
1.7.6


2011-12-05 08:14:18

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 08/10] fix compiler warnings around get_output use of argv

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
ctl.c | 20 +++++++++-----------
1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/ctl.c b/ctl.c
index e5d16e3..f1d878d 100644
--- a/ctl.c
+++ b/ctl.c
@@ -52,7 +52,7 @@ static int __token_count(token_t *t);
static const char * __token_next(token_t *t);
static const char * __token_str(token_t *t);
static int __token_next_int(token_t *t);
-static int get_output(char *prog, const char **argv);
+static int get_output(char *prog, char * const *argv);
static char *find_dm_name(int major, int minor);
static void hexdump(char *p, int len, int off);

@@ -277,7 +277,7 @@ get_vers(bl_comm_msg_t *msg, bl_comm_res_t *res, int *len)
bl_comm_res_t *
get_dm(bl_comm_msg_t *msg, bl_comm_res_t *res, int *lenp)
{
- const char *argv[4] = {"dmsetup", "table", NULL, NULL};
+ char *argv[4] = {"dmsetup", "table", NULL, NULL};
char buf[128],
*name;
int major,
@@ -298,7 +298,7 @@ get_dm(bl_comm_msg_t *msg, bl_comm_res_t *res, int *lenp)
return res;
}
argv[2] = name;
- if (((fd = get_output("/sbin/dmsetup", argv)) == -1) ||
+ if (((fd = get_output("/sbin/dmsetup", (char * const *)argv)) == -1) ||
((fp = fdopen(fd, "r")) == NULL)) {
printf("%s: get_output/fdopen failed\n", __func__);
res->res_status = PNFS_BLOCK_FAILURE;
@@ -479,7 +479,7 @@ set_operation(int op)
static char *
find_dm_name(int major, int minor)
{
- const char *argv[5] = {"dmsetup", "ls", "--target", "striped", NULL};
+ char * const argv[5] = {"dmsetup", "ls", "--target", "striped", NULL};
char buf[128],
*name;
const char *majmin;
@@ -549,7 +549,7 @@ error:
}

static int
-get_output(char *prog, const char **argv)
+get_output(char *prog, char * const *argv)
{
int fildes[2];

@@ -567,13 +567,11 @@ get_output(char *prog, const char **argv)
close(fildes[0]);
dup2(fildes[1], 1);
dup2(fildes[1], 2);
- if (execv(prog, argv) == -1) {
- perror("execv");
- exit(1);
- }
- break;
+ execv(prog, argv);
+ perror("execv");
+ exit(1);

- default:
+ default:
close(fildes[1]);
return fildes[0];
}
--
1.7.6


2011-12-05 08:13:00

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 01/10] use gcc

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
Makefile | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 14bb2ff..2b40126 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,9 @@
+CC= gcc
OBJS= ctl.o efi.o
CFLAGS= -I../../linux-pnfs.working/include

ctl: $(OBJS)
- cc -o ctl $(OBJS) -levent -lpthread -lparted
+ $(CC) -o ctl $(OBJS) -levent -lpthread -lparted

clean:
rm -f $(OBJS) ctl
--
1.7.6


2011-12-05 08:13:56

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 06/10] add missing includes

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
ctl.c | 2 ++
efi.c | 2 ++
2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/ctl.c b/ctl.c
index 7432a09..d989ab8 100644
--- a/ctl.c
+++ b/ctl.c
@@ -1,7 +1,9 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
#include <sys/time.h>
+#include <sys/wait.h>
#include <event.h>
#include <pthread.h>

diff --git a/efi.c b/efi.c
index b653092..67b6211 100644
--- a/efi.c
+++ b/efi.c
@@ -95,6 +95,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>

#include "efi.h"

--
1.7.6


2011-12-05 08:13:33

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 04/10] increase compiler warning level

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
Makefile | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 2b40126..df074dd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
CC= gcc
OBJS= ctl.o efi.o
-CFLAGS= -I../../linux-pnfs.working/include
+CFLAGS= -I../../linux-pnfs.working/include -Wall

ctl: $(OBJS)
$(CC) -o ctl $(OBJS) -levent -lpthread -lparted
--
1.7.6


2011-12-05 08:14:07

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 07/10] ctl: fix compiler warnings

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
ctl.c | 20 +++++++++-----------
1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/ctl.c b/ctl.c
index d989ab8..e5d16e3 100644
--- a/ctl.c
+++ b/ctl.c
@@ -75,11 +75,10 @@ struct event ge;
int
main(int argc, char **argv)
{
- int upcall_fd,
- operation = -1,
- len;
- char c,
- *prog;
+ int upcall_fd;
+ int operation = -1;
+ char c;
+ char *prog;
pthread_t t;
void *thr_val;

@@ -162,7 +161,7 @@ process_msg(int fd, short ev_type, void *arg)
return;
len = sizeof (bl_comm_res_t);
if ((cc = read(fd, &msg, sizeof (msg))) != sizeof (msg)) {
- printf("Failed to get all of message. Got %d, expected %d\n",
+ printf("Failed to get all of message. Got %d, expected %Zd\n",
cc, sizeof (msg));
resp->res_status = PNFS_BLOCK_FAILURE;
write(fd, resp, len);
@@ -352,9 +351,7 @@ get_dm(bl_comm_msg_t *msg, bl_comm_res_t *res, int *lenp)
bl_comm_res_t *
check_dm(bl_comm_msg_t *msg, bl_comm_res_t *res, int *len)
{
- int fd,
- major,
- minor;
+ int major, minor;
char *name;

res->res_status = PNFS_BLOCK_SUCCESS;
@@ -391,7 +388,7 @@ get_slice(bl_comm_msg_t *msg, bl_comm_res_t *res, int *len)
partition = minor & 0xf;
res->res_status = PNFS_BLOCK_FAILURE; // Default condition

- printf("%s: %u:%u: ", __func__, major, minor); fflush(stdout);
+ printf("%s: %u:%u: ", __func__, (unsigned)major, (unsigned)minor); fflush(stdout);

if (mknod(path, S_IFBLK | 0600, dev)) {
perror("mknod");
@@ -421,7 +418,8 @@ get_slice(bl_comm_msg_t *msg, bl_comm_res_t *res, int *len)
res->res_status = PNFS_BLOCK_SUCCESS;
res->u.slice.start = ppart->geom.start;
res->u.slice.length = ppart->geom.length;
- printf("Dev: %d:%d, Start: %llu, Length: %llu\n", major, minor,
+ printf("Dev: %u:%u, Start: %llu, Length: %llu\n",
+ (unsigned)major, (unsigned)minor,
res->u.slice.start, res->u.slice.length);
out:
(void) unlink(path);
--
1.7.6


2011-12-05 08:13:22

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 03/10] ctl: improve debug printouts

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
ctl.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/ctl.c b/ctl.c
index 2071b0e..959ef6a 100644
--- a/ctl.c
+++ b/ctl.c
@@ -176,6 +176,7 @@ process_msg(int fd, short ev_type, void *arg)
resp->res_status = PNFS_BLOCK_FAILURE;
} else {
printf("Processing: %s: ", table[msg.msg_type].msg_name);
+ fflush(stdout);
resp = table[msg.msg_type].msg_func(&msg, resp, &len);
}

@@ -215,6 +216,8 @@ get_sig(bl_comm_msg_t *msg, bl_comm_res_t *res, int *lenp)
minor = msg->u.msg_dev & 0xfffff;
dev = (major << 8) | (minor & ~0xf);

+ printf("%s: %d:%d: ", __func__, major, minor);
+ fflush(stdout);
res->res_status = PNFS_BLOCK_FAILURE; // Default condition

if (mknod(path, S_IFBLK | 0600, dev)) {
@@ -386,6 +389,8 @@ get_slice(bl_comm_msg_t *msg, bl_comm_res_t *res, int *len)
partition = minor & 0xf;
res->res_status = PNFS_BLOCK_FAILURE; // Default condition

+ printf("%s: %u:%u: ", __func__, major, minor); fflush(stdout);
+
if (mknod(path, S_IFBLK | 0600, dev)) {
perror("mknod");
goto out;
--
1.7.6


2011-12-05 08:13:44

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 05/10] ctl: always return a value from find_dm_name

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
ctl.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/ctl.c b/ctl.c
index 959ef6a..7432a09 100644
--- a/ctl.c
+++ b/ctl.c
@@ -494,7 +494,7 @@ find_dm_name(int major, int minor)
if (((fd = get_output("/sbin/dmsetup", argv)) == -1) ||
((fp = fdopen(fd, "r")) == NULL)) {
printf("%s: get_output/fdopen failed\n", __func__);
- return;
+ return NULL;
}
while (fgets(buf, sizeof (buf), fp) != NULL) {
t = __token_init(buf, '\t');
@@ -545,6 +545,7 @@ error:

fclose(fp);
(void) wait(&status);
+ return NULL;
}

static int
--
1.7.6


2011-12-05 08:14:29

by Benny Halevy

[permalink] [raw]
Subject: [PATCH 09/10] ctl: main should return 0 on success

From: Benny Halevy <[email protected]>

Signed-off-by: Benny Halevy <[email protected]>
---
ctl.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/ctl.c b/ctl.c
index f1d878d..a28c9e9 100644
--- a/ctl.c
+++ b/ctl.c
@@ -131,6 +131,8 @@ main(int argc, char **argv)
close(upcall_fd);
pthread_join(t, &thr_val);
}
+
+ return 0;
}

/*
--
1.7.6