blkmapd: use new sunrpc pipefs interface
Subsystems (2)
PATCH 1/1 blkmapd: use new sunrpc pipefs interface
From: Peng Tao <[email protected]>
Signed-off-by Peng Tao <[email protected]>
--- utils/blkmapd/device-discovery.c | 48 +++++++++++-------------------------- utils/blkmapd/device-discovery.h | 12 +++++---- 2 files changed, 21 insertions(+), 39 deletions(-)
utils/blkmapd/device-discovery.c +14 -34
@@ -50,7 +50,7 @@#include "device-discovery.h" -#define BL_PIPE_FILE "/var/lib/nfs/rpc_pipefs/bl_device_pipe" +#define BL_PIPE_FILE "/var/lib/nfs/rpc_pipefs/nfs/blocklayout"#define PID_FILE "/var/run/blkmapd.pid"struct bl_disk *visible_disk_list;
@@ -265,20 +265,14 @@ int bl_discover_devices(void)int bl_disk_inquiry_process (int fd) {int ret =0 ; -struct pipefs_hdr *head =NULL , *tmp; +struct bl_pipemsg_hdr head;char *buf =NULL ;uint32_t major, minor;uint16_t buflen; -unsigned int len =0 ; - - head =calloc (1 ,sizeof (struct pipefs_hdr )); -if (!head) { -BL_LOG_ERR ("%s: Out of memory!\n" , __func__); -return -ENOMEM ; - } +struct bl_dev_msg reply;/* read request */ -if (atomicio (read, fd, head,sizeof (*head)) !=sizeof (*head)) { +if (atomicio (read, fd, &head,sizeof (head)) !=sizeof (head)) {/* Note that an error in this or the next read is pretty * catastrophic, as there is no good way to resync into * the pipe's stream.
@@ -288,7 +282,7 @@ int bl_disk_inquiry_process(int fd) goto out; } - buflen = head->totallen -sizeof (*head); + buflen = head.totallen; buf =malloc (buflen);if (!buf) {BL_LOG_ERR ("%s: Out of memory!\n" , __func__);
@@ -302,9 +296,9 @@ int bl_disk_inquiry_process(int fd) goto out; } - head->status =BL_DEVICE_REQUEST_PROC ; + reply.status =BL_DEVICE_REQUEST_PROC ; -switch (head->type) { +switch (head.type) {case BL_DEVICE_MOUNT :/* * It shouldn't be necessary to discover devices here, since
@@ -316,36 +310,24 @@ int bl_disk_inquiry_process(int fd)*/ bl_discover_devices ();if (!process_deviceinfo (buf, buflen, &major, &minor)) { - head->status =BL_DEVICE_REQUEST_ERR ; + reply.status =BL_DEVICE_REQUEST_ERR ;break ; } - tmp =realloc (head,sizeof (major) +sizeof (minor) + -sizeof (struct pipefs_hdr )); -if (!tmp) { -BL_LOG_ERR ("%s: Out of memory!\n" , __func__); - ret = -ENOMEM ; - goto out; - } - head = tmp; -memcpy ((void *)head +sizeof (struct pipefs_hdr ), - &major,sizeof (major)); -memcpy ((void *)head +sizeof (struct pipefs_hdr ) +sizeof (major), - &minor,sizeof (minor)); - len =sizeof (major) +sizeof (minor); + reply.major = major; + reply.minor = minor;break ;case BL_DEVICE_UMOUNT :if (!dm_device_remove_all ((uint64_t *) buf)) - head->status =BL_DEVICE_REQUEST_ERR ; + reply.status =BL_DEVICE_REQUEST_ERR ;break ;default : - head->status =BL_DEVICE_REQUEST_ERR ; + reply.status =BL_DEVICE_REQUEST_ERR ;break ; } - head->totallen =sizeof (struct pipefs_hdr ) + len;/* write to pipefs */ -if (atomicio ((void *)write, fd, head, head->totallen) - != head->totallen) { +if (atomicio ((void *)write, fd, &reply,sizeof (reply)) + !=sizeof (reply)) {BL_LOG_ERR ("Write pipefs error!\n" ); ret = -EIO ; }
@@ -353,8 +335,6 @@ int bl_disk_inquiry_process(int fd) out:if (buf)free (buf); -if (head) -free (head);return ret; }
utils/blkmapd/device-discovery.h +7 -5
@@ -102,12 +102,14 @@ struct bl_dev_id {char data[0 ]; }; -struct pipefs_hdr { -uint32_t msgid; +struct bl_dev_msg { +int status; +uint32_t major, minor; +}; + +struct bl_pipemsg_hdr {uint8_t type; -uint8_t flags; -uint16_t totallen;/* length of message including hdr */ -uint32_t status; +uint16_t totallen;/* length of message excluding hdr */ };#define BL_DEVICE_UMOUNT 0x0/* Umount--delete devices */
Signature · 1 line
1.7.4.1
I submitted both patches togit://linux-nfs.org/~bhalevy/pnfs-nfs-utils.git
tag pnfs-nfs-utils-1-2-4-2011-07-18
Benny
Quoted 143 lines · Jim Rees
From: Peng Tao <[email protected]>
Signed-off-by Peng Tao <[email protected]>--- utils/blkmapd/device-discovery.c | 48 +++++++++++-------------------------- utils/blkmapd/device-discovery.h | 12 +++++---- 2 files changed, 21 insertions(+), 39 deletions(-)utils/blkmapd/device-discovery.c +14
-34@@ -50,7 +50,7 @@#include "device-discovery.h" -#define BL_PIPE_FILE "/var/lib/nfs/rpc_pipefs/bl_device_pipe" +#define BL_PIPE_FILE "/var/lib/nfs/rpc_pipefs/nfs/blocklayout"#define PID_FILE "/var/run/blkmapd.pid"struct bl_disk *visible_disk_list;@@ -265,20 +265,14 @@ int bl_discover_devices(void)int bl_disk_inquiry_process (int fd) {int ret =0 ; -struct pipefs_hdr *head =NULL , *tmp; +struct bl_pipemsg_hdr head;char *buf =NULL ;uint32_t major, minor;uint16_t buflen; -unsigned int len =0 ; - - head =calloc (1 ,sizeof (struct pipefs_hdr )); -if (!head) { -BL_LOG_ERR ("%s: Out of memory!\n" , __func__); -return -ENOMEM ; - } +struct bl_dev_msg reply;/* read request */ -if (atomicio (read, fd, head,sizeof (*head)) !=sizeof (*head)) { +if (atomicio (read, fd, &head,sizeof (head)) !=sizeof (head)) {/* Note that an error in this or the next read is pretty * catastrophic, as there is no good way to resync into * the pipe's stream. @@ -288,7 +282,7 @@ int bl_disk_inquiry_process(int fd) goto out; } - buflen = head->totallen -sizeof (*head); + buflen = head.totallen; buf =malloc (buflen);if (!buf) {BL_LOG_ERR ("%s: Out of memory!\n" , __func__);@@ -302,9 +296,9 @@ int bl_disk_inquiry_process(int fd) goto out; } - head->status =BL_DEVICE_REQUEST_PROC ; + reply.status =BL_DEVICE_REQUEST_PROC ; -switch (head->type) { +switch (head.type) {case BL_DEVICE_MOUNT :/* * It shouldn't be necessary to discover devices here, since @@ -316,36 +310,24 @@ int bl_disk_inquiry_process(int fd)*/ bl_discover_devices ();if (!process_deviceinfo (buf, buflen, &major, &minor)) { - head->status =BL_DEVICE_REQUEST_ERR ; + reply.status =BL_DEVICE_REQUEST_ERR ;break ; } - tmp =realloc (head,sizeof (major) +sizeof (minor) + -sizeof (struct pipefs_hdr )); -if (!tmp) { -BL_LOG_ERR ("%s: Out of memory!\n" , __func__); - ret = -ENOMEM ; - goto out; - } - head = tmp; -memcpy ((void *)head +sizeof (struct pipefs_hdr ), - &major,sizeof (major)); -memcpy ((void *)head +sizeof (struct pipefs_hdr ) +sizeof (major), - &minor,sizeof (minor)); - len =sizeof (major) +sizeof (minor); + reply.major = major; + reply.minor = minor;break ;case BL_DEVICE_UMOUNT :if (!dm_device_remove_all ((uint64_t *) buf)) - head->status =BL_DEVICE_REQUEST_ERR ; + reply.status =BL_DEVICE_REQUEST_ERR ;break ;default : - head->status =BL_DEVICE_REQUEST_ERR ; + reply.status =BL_DEVICE_REQUEST_ERR ;break ; } - head->totallen =sizeof (struct pipefs_hdr ) + len;/* write to pipefs */ -if (atomicio ((void *)write, fd, head, head->totallen) - != head->totallen) { +if (atomicio ((void *)write, fd, &reply,sizeof (reply)) + !=sizeof (reply)) {BL_LOG_ERR ("Write pipefs error!\n" ); ret = -EIO ; }@@ -353,8 +335,6 @@ int bl_disk_inquiry_process(int fd) out:if (buf)free (buf); -if (head) -free (head);return ret; }utils/blkmapd/device-discovery.h +7
-5@@ -102,12 +102,14 @@ struct bl_dev_id {char data[0 ]; }; -struct pipefs_hdr { -uint32_t msgid; +struct bl_dev_msg { +int status; +uint32_t major, minor; +}; + +struct bl_pipemsg_hdr {uint8_t type; -uint8_t flags; -uint16_t totallen;/* length of message including hdr */ -uint32_t status; +uint16_t totallen;/* length of message excluding hdr */ };#define BL_DEVICE_UMOUNT 0x0/* Umount--delete devices */