nfs-utils: Cumulative patches for blkmapd
Subsystems (2)
cover nfs-utils: Cumulative patches for blkmapd
Cumulative patches for blkmapd.
Jim Rees (6):
blkmapd: get rid of config file and instead examine all block devices
blkmapd: don't rescan periodically
blkmapd: don't use atomicio() where it's not needed
ignore passive devices before checking serial numbers
add "-d" option to just do discovery then exit
Various bug fixes and cleanups.
utils/blkmapd/Makefile.am | 3 - utils/blkmapd/atomicio.c | 54 -------- utils/blkmapd/cfg.c | 248 -------------------------------------- utils/blkmapd/cfg.h | 47 ------- utils/blkmapd/device-discovery.c | 216 +++++++++++++++------------------ utils/blkmapd/device-discovery.h | 5 +- utils/blkmapd/device-inq.c | 43 +++---- utils/blkmapd/device-process.c | 30 ++--- utils/blkmapd/dm-device.c | 1 + 9 files changed, 129 insertions(+), 518 deletions(-) delete mode 100644 utils/blkmapd/atomicio.c delete mode 100644 utils/blkmapd/cfg.c delete mode 100644 utils/blkmapd/cfg.h
PATCH 1/6 blkmapd: get rid of config file and instead examine all block devices
Only examine actual block devices rather than everything in /dev. Since we're looking for pnfs signatures, it usually doesn't hurt to examine a device that isn't part of a layout, and in general it's hard to tell ahead of time which devices should be considered, so I think having a config file does more harm than good.
It may be useful later on to be able to blacklist some devices but I'd rather not do this through yet another config file. Maybe this can be done via udev rules.
--- utils/blkmapd/Makefile.am | 2 - utils/blkmapd/cfg.c | 248 -------------------------------------- utils/blkmapd/cfg.h | 47 ------- utils/blkmapd/device-discovery.c | 103 ++++------------ 4 files changed, 26 insertions(+), 374 deletions(-) delete mode 100644 utils/blkmapd/cfg.c delete mode 100644 utils/blkmapd/cfg.h
utils/blkmapd/Makefile.am +0 -2
@@ -7,13 +7,11 @@ sbin_PROGRAMS = blkmapd blkmapd_SOURCES = \ atomicio.c \ - cfg.c \ device-discovery.c \ device-inq.c \ device-process.c \ dm-device.c \ \ - cfg.h \ device-discovery.h blkmapd_LDADD = -ldevmapper ../../support/nfs/libnfs.a
utils/blkmapd/cfg.c deleted +0 -248
248 lines not on this page · raw message
utils/blkmapd/cfg.h deleted +0 -47
47 lines not on this page · raw message
utils/blkmapd/device-discovery.c +26 -77
156 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 2/6 blkmapd: don't rescan periodically
In reply to Jim ReesPeriodic device rescanning is always going to be wrong, since the interval will either be too long and miss an important change, or too short and waste resources. It's not even needed in the normal case, only when the devices change during the life of a layout. For now, just rescan when the kernel asks for a layout. A later patch will re-introduce rescanning during the life of a layout, but will be triggered by configuration change notifications from udev, rather than by expiration of an arbitrary time interval.
--- utils/blkmapd/device-discovery.c | 14 ++++++++++---- utils/blkmapd/device-discovery.h | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-)
utils/blkmapd/device-discovery.c +10 -4
@@ -308,6 +308,15 @@ int bl_disk_inquiry_process(int fd) head->status =BL_DEVICE_REQUEST_PROC ;switch (head->type) {case BL_DEVICE_MOUNT : +/* +* It shouldn't be necessary to discover devices here, since +* process_deviceinfo() will re-discover if it can't find +* the devices it needs. But in the case of multipath +* devices (ones that appear more than once, for example an +* active and a standby LUN), this will re-order them in the +* correct priority. +*/ +bl_discover_devices ();if (!process_deviceinfo (buf, buflen, &major, &minor)) { head->status =BL_DEVICE_REQUEST_ERR ; goto out;
@@ -329,7 +338,6 @@ int bl_disk_inquiry_process(int fd)case BL_DEVICE_UMOUNT :if (!dm_device_remove_all ((uint64_t *) buf)) head->status =BL_DEVICE_REQUEST_ERR ; -bl_discover_devices ();break ;default : head->status =BL_DEVICE_REQUEST_ERR ;
@@ -357,7 +365,6 @@ unsigned int bl_process_stop;int bl_run_disk_inquiry_process (int fd) {fd_set rset; -struct timeval tv;int ret; bl_process_stop =0 ;
@@ -368,8 +375,7 @@ int bl_run_disk_inquiry_process(int fd)FD_ZERO (&rset);FD_SET (fd, &rset); ret =0 ; - tv.tv_sec =BL_DEVICE_DISCOVERY_INTERVAL ; -switch (select (fd +1 , &rset,NULL ,NULL , &tv)) { +switch (select (fd +1 , &rset,NULL ,NULL ,NULL )) {case -1 :if (errno ==EINTR )continue ;
utils/blkmapd/device-discovery.h +0 -2
@@ -27,8 +27,6 @@#ifndef BL_DEVICE_DISCOVERY_H #define BL_DEVICE_DISCOVERY_H -#define BL_DEVICE_DISCOVERY_INTERVAL 60 -#include <stdint.h> #include <syslog.h>
Signature · 1 line
1.7.1
PATCH 3/6 blkmapd: don't use atomicio() where it's not needed
In reply to Jim Rees--- utils/blkmapd/device-process.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
utils/blkmapd/device-process.c +1 -1
@@ -121,7 +121,7 @@ read_cmp_blk_sig(const char *dev_name, struct bl_sig_comp *comp, goto error; } -if (atomicio (read, fd, sig, comp->bs_length) != comp->bs_length) { +if (read (fd, sig, comp->bs_length) != comp->bs_length) {BL_LOG_ERR ("File %s read error\n" , dev_name); goto error; }
Signature · 1 line
1.7.1
PATCH 4/6 ignore passive devices before checking serial numbers
In reply to Jim Rees--- utils/blkmapd/device-discovery.c | 33 +++++++++++++++++---------------- utils/blkmapd/device-inq.c | 19 +++++++++++-------- 2 files changed, 28 insertions(+), 24 deletions(-)
utils/blkmapd/device-discovery.c +17 -16
@@ -26,24 +26,25 @@* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <dirent.h> -#include <ctype.h> -#include <linux/kdev_t.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/select.h> +#include <linux/kdev_t.h> +#include <scsi/scsi.h> +#include <scsi/scsi_ioctl.h> +#include <scsi/sg.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <dirent.h> +#include <ctype.h> #include <fcntl.h> #include <unistd.h> #include <libgen.h> #include <errno.h> -#include <scsi/scsi.h> -#include <scsi/scsi_ioctl.h> -#include <scsi/sg.h> #include "device-discovery.h"
@@ -127,7 +128,7 @@ void bl_add_disk(char *filepath)struct stat sb;off_t size =0 ;struct bl_serial *serial =NULL ; -enum bl_path_state_e ap_state =BL_PATH_STATE_PASSIVE ; +enum bl_path_state_e ap_state;struct bl_disk_path *diskpath =NULL , *path =NULL ;dev_t dev;
@@ -152,6 +153,11 @@ void bl_add_disk(char *filepath) dev = sb.st_rdev; serial =bldev_read_serial (fd, filepath); +bldev_read_ap_state (fd, &ap_state); +close (fd); + +if (ap_state ==BL_PATH_STATE_PASSIVE ) +return ;for (disk = visible_disk_list; disk !=NULL ; disk = disk->next) {/* Already scanned or a partition?
@@ -164,13 +170,8 @@ void bl_add_disk(char *filepath) } } -if (disk && diskpath) { -close (fd); +if (disk && diskpath)return ; - } - -bldev_read_ap_state (fd, &ap_state); -close (fd);BL_LOG_ERR ("%s: %s\n" , __func__, filepath);
utils/blkmapd/device-inq.c +11 -8
@@ -28,23 +28,25 @@* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <dirent.h> -#include <ctype.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/select.h> +#include <scsi/scsi.h> +#include <scsi/scsi_ioctl.h> +#include <scsi/sg.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <dirent.h> +#include <ctype.h> #include <fcntl.h> #include <unistd.h> #include <libgen.h> #include <errno.h> -#include <scsi/scsi.h> -#include <scsi/scsi_ioctl.h> -#include <scsi/sg.h> +#include "device-discovery.h" #define DEF_ALLOC_LEN 255
@@ -161,6 +163,7 @@ void bldev_read_ap_state(int fd, enum bl_path_state_e *ap_state_out)if (status) goto out; +printf ("buffer[4]=%d\n" , (int ) buffer[4 ]);if (buffer[4 ] <0x02 ) *ap_state_out =BL_PATH_STATE_PASSIVE ; out:
Signature · 1 line
1.7.1
PATCH 5/6 add "-d" option to just do discovery then exit
In reply to Jim Rees--- utils/blkmapd/device-discovery.c | 69 +++++++++++++++++++++---------------- 1 files changed, 39 insertions(+), 30 deletions(-)
utils/blkmapd/device-discovery.c +39 -30
@@ -398,54 +398,63 @@ int bl_run_disk_inquiry_process(int fd)/* Daemon */ int main (int argc,char **argv) { -int fd, opt, fg =0 , ret =1 ; +int fd =-1 , opt, dflag =0 , fg =0 , ret =1 ;struct stat statbuf;char pidbuf[64 ]; -while ((opt =getopt (argc, argv,"f" )) !=-1 ) { +while ((opt =getopt (argc, argv,"df" )) !=-1 ) {switch (opt) { +case 'd' : + dflag =1 ; +break ;case 'f' : fg =1 ;break ; } } -if (!stat (PID_FILE , &statbuf)) { -fprintf (stderr,"Pid file already existed\n" ); -return -1 ; - } +if (fg) { +openlog ("blkmapd" ,LOG_PERROR ,0 ); + }else { +if (!stat (PID_FILE , &statbuf)) { +fprintf (stderr,"Pid file already existed\n" ); +return -1 ; + } -if (!fg &&daemon (0 ,0 ) !=0 ) { -fprintf (stderr,"Daemonize failed\n" ); -return -1 ; - } +if (daemon (0 ,0 ) !=0 ) { +fprintf (stderr,"Daemonize failed\n" ); +return -1 ; + } -openlog ("blkmapd" ,LOG_PID ,0 ); - fd =open (PID_FILE ,O_WRONLY |O_CREAT ,0644 ); -if (fd <0 ) { -BL_LOG_ERR ("Create pid file failed\n" ); -return -1 ; - } +openlog ("blkmapd" ,LOG_PID ,0 ); + fd =open (PID_FILE ,O_WRONLY |O_CREAT ,0644 ); +if (fd <0 ) { +BL_LOG_ERR ("Create pid file failed\n" ); +return -1 ; + } -if (lockf (fd,F_TLOCK ,0 ) <0 ) { -BL_LOG_ERR ("Lock pid file failed\n" ); -close (fd); -return -1 ; - } -ftruncate (fd,0 ); -sprintf (pidbuf,"%d\n" ,getpid ()); -write (fd, pidbuf,strlen (pidbuf)); - -/* open pipe file */ - fd =open (BL_PIPE_FILE ,O_RDWR ); -if (fd <0 ) { -BL_LOG_ERR ("open pipe file error\n" ); -return -1 ; +if (lockf (fd,F_TLOCK ,0 ) <0 ) { +BL_LOG_ERR ("Lock pid file failed\n" ); +close (fd); +return -1 ; + } +ftruncate (fd,0 ); +sprintf (pidbuf,"%d\n" ,getpid ()); +write (fd, pidbuf,strlen (pidbuf)); + +/* open pipe file */ + fd =open (BL_PIPE_FILE ,O_RDWR ); +if (fd <0 ) { +BL_LOG_ERR ("open pipe file error\n" ); +return -1 ; + } }while (1 ) {/* discover device when needed */ bl_discover_devices (); +if (dflag) +break ; ret =bl_run_disk_inquiry_process (fd);if (ret <0 ) {
Signature · 1 line
1.7.1
PATCH 6/6 Various bug fixes and cleanups.
In reply to Jim ReesDon't log EUI errors. These aren't really errors, since we'll fall back to a different id type, or just use the file name.
Get rid of useless default case.
eliminate fd/pidfd confusion
use INFO syslog level instead of ERR for info messages
Remove atomicio.c from blkmapd now that it's in the support lib
--- utils/blkmapd/Makefile.am | 1 - utils/blkmapd/atomicio.c | 54 -------------------------------- utils/blkmapd/device-discovery.c | 63 +++++++++++++++++++++---------------- utils/blkmapd/device-discovery.h | 3 +- utils/blkmapd/device-inq.c | 26 ++++++--------- utils/blkmapd/device-process.c | 28 ++++++----------- utils/blkmapd/dm-device.c | 1 + 7 files changed, 59 insertions(+), 117 deletions(-) delete mode 100644 utils/blkmapd/atomicio.c
utils/blkmapd/Makefile.am +0 -1
@@ -6,7 +6,6 @@ AM_CFLAGS += -D_LARGEFILE64_SOURCE sbin_PROGRAMS = blkmapd blkmapd_SOURCES = \ - atomicio.c \ device-discovery.c \ device-inq.c \ device-process.c \
utils/blkmapd/atomicio.c deleted +0 -54
54 lines not on this page · raw message
utils/blkmapd/device-discovery.c +36 -27
120 lines not on this page · raw message
utils/blkmapd/device-discovery.h +2 -1
@@ -151,9 +151,10 @@ uint64_t process_deviceinfo(const char *dev_addr_buf,extern ssize_t atomicio (ssize_t (*f) (int ,void *,size_t ),int fd,void *_s,size_t n);extern struct bl_serial *bldev_read_serial (int fd,const char *filename); -extern void bldev_read_ap_state (int fd,enum bl_path_state_e *ap_state_out); +extern enum bl_path_state_e bldev_read_ap_state (int fd);extern int bl_discover_devices (void ); +#define BL_LOG_INFO(fmt...) syslog(LOG_INFO, fmt) #define BL_LOG_WARNING(fmt...) syslog(LOG_WARNING, fmt) #define BL_LOG_ERR(fmt...) syslog(LOG_ERR, fmt) #define BL_LOG_DEBUG(fmt...) syslog(LOG_DEBUG, fmt)
utils/blkmapd/device-inq.c +10 -16
@@ -52,9 +52,10 @@#define DEF_ALLOC_LEN 255#define MX_ALLOC_LEN (0xc000 + 0x80) -struct bl_serial *bl_create_scsi_string (int len,const char *bytes) +static struct bl_serial *bl_create_scsi_string (int len,const char *bytes) {struct bl_serial *s; + s =malloc (sizeof (*s) + len);if (s) { s->data = (char *)&s[1 ];
@@ -64,7 +65,7 @@ struct bl_serial *bl_create_scsi_string(int len, const char *bytes)return s; } -void bl_free_scsi_string (struct bl_serial *str) +static void bl_free_scsi_string (struct bl_serial *str) {if (str)free (str);
@@ -107,7 +108,7 @@ static int bldev_inquire_page(int fd, int page, char *buffer, int len)return -1 ; } -int bldev_inquire_pages (int fd,int page,char **buffer) +static int bldev_inquire_pages (int fd,int page,char **buffer) {int status =0 ;char *tmp;
@@ -152,24 +153,22 @@ int bldev_inquire_pages(int fd, int page, char **buffer)/* For EMC multipath devices, use VPD page (0xc0) to get status. * For other devices, return ACTIVE for now */ -void bldev_read_ap_state (int fd,enum bl_path_state_e *ap_state_out) +extern enum bl_path_state_e bldev_read_ap_state (int fd) {int status =0 ; -char *buffer; - - *ap_state_out =BL_PATH_STATE_ACTIVE ; +char *buffer =NULL ; +enum bl_path_state_e ap_state =BL_PATH_STATE_ACTIVE ; status =bldev_inquire_pages (fd,0xc0 , &buffer);if (status) goto out; -printf ("buffer[4]=%d\n" , (int ) buffer[4 ]);if (buffer[4 ] <0x02 ) - *ap_state_out =BL_PATH_STATE_PASSIVE ; + ap_state =BL_PATH_STATE_PASSIVE ; out:if (buffer)free (buffer); -return ; +return ap_state; }struct bl_serial *bldev_read_serial (int fd,const char *filename)
@@ -200,11 +199,8 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)*/ case 2 :/* EUI-64 based */ if ((dev_id->len !=8 ) && (dev_id->len !=12 ) && - (dev_id->len !=16 )) { -BL_LOG_ERR ("EUI-64 only decodes 8, " -"12 and 16\n" ); + (dev_id->len !=16 ))break ; - }case 3 :/* NAA */ /* TODO: NAA validity judgement too complicated, * so just ingore it here.
@@ -221,8 +217,6 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename) serial_out =bl_create_scsi_string (dev_id->len, dev_id->data);break ; -default : -break ; }if (current_id ==3 )break ;
utils/blkmapd/device-process.c +10 -18
@@ -82,7 +82,7 @@ static int decode_blk_signature(uint32_t **pp, uint32_t *end,* for mapping, then thrown away. */ sig->si_comps[i].bs_string = (char *)p; -BL_LOG_ERR ("%s: si_comps[%d]: bs_length %d, bs_string %s\n" , +BL_LOG_INFO ("%s: si_comps[%d]: bs_length %d, bs_string %s\n" , __func__, i, sig->si_comps[i].bs_length, sig->si_comps[i].bs_string); p += ((tmp +3 ) >>2 );
@@ -126,7 +126,7 @@ read_cmp_blk_sig(const char *dev_name, struct bl_sig_comp *comp, goto error; } -BL_LOG_ERR +BL_LOG_INFO ("%s: %s sig: %s, bs_string: %s, bs_length: %d, bs_offset: %lld\n" , __func__, dev_name, sig, comp->bs_string, comp->bs_length, (long long )bs_offset);
@@ -155,7 +155,7 @@ static int verify_sig(struct bl_disk *disk, struct bl_sig *sig) bs_offset = comp->bs_offset;if (bs_offset <0 ) bs_offset += (((int64_t ) disk->size) <<9 ); -BL_LOG_ERR ("%s: bs_offset: %lld\n" , +BL_LOG_INFO ("%s: bs_offset: %lld\n" , __func__, (long long ) bs_offset); ret =read_cmp_blk_sig (disk->valid_path->full_path, comp, bs_offset);
@@ -180,7 +180,7 @@ static int map_sig_to_device(struct bl_sig *sig, struct bl_volume *vol)struct bl_disk *lolDisk = disk;while (lolDisk) { -BL_LOG_ERR ("%s: visible_disk_list: %s\n" , __func__, +BL_LOG_INFO ("%s: visible_disk_list: %s\n" , __func__, lolDisk->valid_path->full_path); lolDisk = lolDisk->next; }
@@ -324,16 +324,14 @@ uint64_t process_deviceinfo(const char *dev_addr_buf,uint32_t *p, *end;struct bl_volume *vols =NULL , **arrays =NULL , **arrays_ptr =NULL ;uint64_t dev =0 ; -int tried =0 ; - restart: p = (uint32_t *) dev_addr_buf; end = (uint32_t *) ((char *)p + dev_addr_len);/* Decode block volume */ BLK_READBUF (p, end,4 );READ32 (num_vols);if (num_vols <=0 ) { -BL_LOG_WARNING ("Error: number of vols: %d\n" , num_vols); +BL_LOG_ERR ("Error: number of vols: %d\n" , num_vols); goto out_err; }
@@ -363,15 +361,6 @@ uint64_t process_deviceinfo(const char *dev_addr_buf,for (i =0 ; i < num_vols; i++) { vols[i].bv_vols = arrays_ptr; status =decode_blk_volume (&p, end, vols, i, &count); -if (status == -ENXIO && (tried <=5 )) { -sleep (1 ); -BL_LOG_DEBUG ("%s: discover again!\n" , __func__); -bl_discover_devices (); - tried++; -free (vols); -free (arrays); - goto restart; - }if (status) goto out_err; arrays_ptr += count;
@@ -383,8 +372,11 @@ uint64_t process_deviceinfo(const char *dev_addr_buf, } dev =dm_device_create (vols, num_vols); - *major =MAJOR (dev); - *minor =MINOR (dev); +if (dev) { + *major =MAJOR (dev); + *minor =MINOR (dev); + } + out_err:if (vols)free (vols);
utils/blkmapd/dm-device.c +1 -0
@@ -379,6 +379,7 @@ uint64_t dm_device_create(struct bl_volume *vols, int num_vols)struct bl_dm_table *bl_table_head =NULL ;unsigned int len;char *dev_name =NULL ; +/* Create pseudo device here */ while (number < num_vols) { node = &vols[number];
Signature · 1 line
1.7.1
All merged and pushed to git://linux-nfs.org/~bhalevy/pnfs-nfs-utils.git
at tag pnfs-utils-1-2-4-rc1
Thanks!
Benny
Quoted 24 lines · Jim Rees
Cumulative patches for blkmapd.
Jim Rees (6):
blkmapd: get rid of config file and instead examine all block devices
blkmapd: don't rescan periodically
blkmapd: don't useatomicio()where it's not needed
ignore passive devices before checking serial numbers
add "-d" option to just do discovery then exit
Various bug fixes and cleanups.utils/blkmapd/Makefile.am | 3 - utils/blkmapd/atomicio.c | 54 -------- utils/blkmapd/cfg.c | 248 -------------------------------------- utils/blkmapd/cfg.h | 47 ------- utils/blkmapd/device-discovery.c | 216 +++++++++++++++------------------ utils/blkmapd/device-discovery.h | 5 +- utils/blkmapd/device-inq.c | 43 +++---- utils/blkmapd/device-process.c | 30 ++--- utils/blkmapd/dm-device.c | 1 + 9 files changed, 129 insertions(+), 518 deletions(-) delete mode 100644 utils/blkmapd/atomicio.c delete mode 100644 utils/blkmapd/cfg.c delete mode 100644 utils/blkmapd/cfg.h