LVM2 ./WHATS_NEW daemons/clvmd/clvm.h daemons/ ...
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: ccaulfield at sourceware.org 2010-04-20 14:07:39
Modified files:
. : WHATS_NEW
daemons/clvmd : clvm.h clvmd-command.c clvmd.c lvm-functions.c
lvm-functions.h refresh_clvmd.c refresh_clvmd.h
man : clvmd.8.in
scripts : clvmd_init_red_hat.in
Log message:
Add -S command to clvmd, so it can restart itself and still preserve exlusive LV locks.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1530&r2=1.1531
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvm.h.diff?cvsroot=lvm2&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvmd-command.c.diff?cvsroot=lvm2&r1=1.31&r2=1.32
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvmd.c.diff?cvsroot=lvm2&r1=1.69&r2=1.70
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/lvm-functions.c.diff?cvsroot=lvm2&r1=1.88&r2=1.89
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/lvm-functions.h.diff?cvsroot=lvm2&r1=1.12&r2=1.13
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/refresh_clvmd.c.diff?cvsroot=lvm2&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/refresh_clvmd.h.diff?cvsroot=lvm2&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/man/clvmd.8.in.diff?cvsroot=lvm2&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/scripts/clvmd_init_red_hat.in.diff?cvsroot=lvm2&r1=1.5&r2=1.6
WHATS_NEW +1 -0
@@ -1,5 +1,6 @@ Version 2.02.64 - ================================= + Add -S command to clvmd to restart the daemon preserving exclusive locks. Increment lvm2app version from 1 to 2. Change lvm2app memory alloc/free for pv/vg/lv properties. Change daemon lock filename from lvm2_monitor to lvm2-monitor for consistency.
daemons/clvmd/clvm.h +1 -0
@@ -69,4 +69,5 @@#define CLVMD_CMD_GET_CLUSTERNAME 41#define CLVMD_CMD_SET_DEBUG 42#define CLVMD_CMD_VG_BACKUP 43 +#define CLVMD_CMD_RESTART 44#endif
daemons/clvmd/clvmd-command.c +53 -0
74 lines not on this page · raw message
daemons/clvmd/clvmd.c +33 -6
@@ -92,6 +92,11 @@unsigned short xid; }; +struct lvm_startup_params { +int using_gulm; +char **argv; +}; +debug_t debug;static pthread_t lvm_thread;static pthread_mutex_t lvm_thread_mutex;
@@ -163,6 +168,7 @@fprintf (file," -d Set debug level\n" );fprintf (file," If starting clvmd then don't fork, run in the foreground\n" );fprintf (file," -R Tell all running clvmds in the cluster to reload their device cache\n" ); +fprintf (file," -S Restart clvmd, preserving exclusive locks\n" );fprintf (file," -C Sets debug level (from -d) on all clvmd instances clusterwide\n" );fprintf (file," -t<secs> Command timeout (default 60 seconds)\n" );fprintf (file," -T<secs> Startup timeout (default none)\n" );
@@ -268,6 +274,9 @@case CLVMD_CMD_LOCK_QUERY : command ="LOCK_QUERY" ;break ; +case CLVMD_CMD_RESTART : + command ="RESTART" ; +break ;default : command ="unknown" ;break ;
@@ -283,6 +292,7 @@int local_sock;struct local_client *newfd;struct utsname nodeinfo; +struct lvm_startup_params lvm_params;signed char opt;int cmd_timeout =DEFAULT_CMD_TIMEOUT ;int start_timeout =0 ;
@@ -295,7 +305,7 @@/* Deal with command-line arguments */ opterr =0 ; optind =0 ; -while ((opt =getopt (argc, argv,"?vVhd::t:RT:CI:" )) !=EOF ) { +while ((opt =getopt (argc, argv,"?vVhd::t:RST:CI:E:" )) !=EOF ) {switch (opt) {case 'h' :usage (argv[0 ], stdout);
@@ -306,7 +316,10 @@exit (0 );case 'R' : -return refresh_clvmd ()==1 ?0 :1 ; +return refresh_clvmd (1 )==1 ?0 :1 ; + +case 'S' : +return restart_clvmd (clusterwide_opt)==1 ?0 :1 ;case 'C' : clusterwide_opt =1 ;
@@ -489,8 +502,10 @@/* Don't let anyone else to do work until we are started */ pthread_mutex_lock (&lvm_start_mutex); + lvm_params.using_gulm = using_gulm; + lvm_params.argv = argv;pthread_create (&lvm_thread,NULL , (lvm_pthread_fn_t *)lvm_thread_fn, - (void *)(long )using_gulm); + (void *)&lvm_params);/* Tell the rest of the cluster our version number */ /* CMAN can do this immediately, gulm needs to wait until
@@ -551,6 +566,10 @@close (client_fd);return 1 ; } + +if (fcntl (client_fd,F_SETFD ,1 )) +DEBUGLOG ("setting CLOEXEC on client fd failed: %s\n" ,strerror (errno)); + newfd->fd = client_fd; newfd->type =LOCAL_SOCK ; newfd->xid =0 ;
@@ -1182,6 +1201,12 @@ }DEBUGLOG ("creating pipe, [%d, %d]\n" , comms_pipe[0 ], comms_pipe[1 ]); + +if (fcntl (comms_pipe[0 ],F_SETFD ,1 )) +DEBUGLOG ("setting CLOEXEC on pipe[0] failed: %s\n" ,strerror (errno)); +if (fcntl (comms_pipe[1 ],F_SETFD ,1 )) +DEBUGLOG ("setting CLOEXEC on pipe[1] failed: %s\n" ,strerror (errno)); + newfd->fd = comms_pipe[0 ]; newfd->removeme =0 ; newfd->type =THREAD_PIPE ;
@@ -1830,7 +1855,7 @@ {struct dm_list *cmdl, *tmp;sigset_t ss; -int using_gulm = (int )(long )arg; +struct lvm_startup_params *lvm_params = arg;DEBUGLOG ("LVM thread function started\n" );
@@ -1841,7 +1866,7 @@pthread_sigmask (SIG_BLOCK , &ss,NULL );/* Initialise the interface to liblvm */ -init_lvm (using_gulm); +init_lvm (lvm_params->using_gulm, lvm_params->argv);/* Allow others to get moving */ pthread_mutex_unlock (&lvm_start_mutex);
@@ -1956,8 +1981,10 @@log_error ("Can't create local socket: %m" );return -1 ; } +/* Set Close-on-exec & non-blocking */ -fcntl (local_socket,F_SETFD ,1 ); +if (fcntl (local_socket,F_SETFD ,1 )) +DEBUGLOG ("setting CLOEXEC on local_socket failed: %s\n" ,strerror (errno));fcntl (local_socket,F_SETFL ,fcntl (local_socket,F_GETFL ,0 ) |O_NONBLOCK );memset (&sockaddr,0 ,sizeof (sockaddr));
daemons/clvmd/lvm-functions.c +60 -6
108 lines not on this page · raw message
daemons/clvmd/lvm-functions.h +3 -3
@@ -1,6 +1,6 @@/* * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved. -* Copyright (C) 2004 Red Hat, Inc. All rights reserved. +* Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. *
@@ -27,7 +27,7 @@ char *resource);extern int do_check_lvm1 (const char *vgname);extern int do_refresh_cache (void ); -extern int init_lvm (int using_gulm); +extern int init_lvm (int using_gulm,char **argv);extern void destroy_lvm (void );extern void init_lvhash (void );extern void destroy_lvhash (void );
@@ -37,5 +37,5 @@extern char *get_last_lvm_error (void );extern void do_lock_vg (unsigned char command,unsigned char lock_flags,char *resource); - +extern struct dm_hash_node *get_next_excl_lock (struct dm_hash_node *v,char **name);#endif
daemons/clvmd/refresh_clvmd.c +17 -9
@@ -1,6 +1,6 @@/* * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved. -* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. +* Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. *
@@ -14,7 +14,7 @@*/ /* -* Tell all clvmds in a cluster to refresh their toolcontext +* Send a command to a running clvmd from the command-line */ #define _GNU_SOURCE
@@ -83,7 +83,7 @@ }/* Send a request and return the status */ -static int _send_request (const char *inbuf,int inlen,char **retbuf) +static int _send_request (const char *inbuf,int inlen,char **retbuf,int no_response) {char outbuf[PIPE_BUF ];struct clvm_header *outheader = (struct clvm_header *) outbuf;
@@ -100,6 +100,8 @@fprintf (stderr,"Error writing data to clvmd: %s" ,strerror (errno));return 0 ; } +if (no_response) +return 1 ;/* Get the response */ reread:
@@ -184,7 +186,7 @@* Send a message to a(or all) node(s) in the cluster and wait for replies */ static int _cluster_request (char cmd,const char *node,void *data,int len, -lvm_response_t ** response,int *num) +lvm_response_t ** response,int *num,int no_response) {char outbuf[sizeof (struct clvm_header ) + len +strlen (node) +1 ];char *inptr;
@@ -207,8 +209,8 @@memcpy (head->node +strlen (head->node) +1 , data, len); status =_send_request (outbuf,sizeof (struct clvm_header ) + -strlen (head->node) + len, &retbuf); -if (!status) +strlen (head->node) + len, &retbuf, no_response); +if (!status || no_response) goto out;/* Count the number of responses we got */
@@ -287,7 +289,7 @@return 1 ; } -int refresh_clvmd () +int refresh_clvmd (int all_nodes) {int num_responses;char args[1 ];// No args really.
@@ -296,7 +298,7 @@int status;int i; - status =_cluster_request (CLVMD_CMD_REFRESH ,"*" , args,0 , &response, &num_responses); + status =_cluster_request (CLVMD_CMD_REFRESH , all_nodes?"*" :"." , args,0 , &response, &num_responses,0 );/* If any nodes were down then display them and return an error */ for (i =0 ; i < num_responses; i++) {
@@ -323,6 +325,12 @@return status; } +int restart_clvmd (int all_nodes) +{ +int dummy; +return _cluster_request (CLVMD_CMD_RESTART , all_nodes?"*" :"." ,NULL ,0 ,NULL , &dummy,1 ); +} +int debug_clvmd (int level,int clusterwide) {int num_responses;
@@ -339,7 +347,7 @@else nodes ="." ; - status =_cluster_request (CLVMD_CMD_SET_DEBUG , nodes, args,1 , &response, &num_responses); + status =_cluster_request (CLVMD_CMD_SET_DEBUG , nodes, args,1 , &response, &num_responses,0 );/* If any nodes were down then display them and return an error */ for (i =0 ; i < num_responses; i++) {
daemons/clvmd/refresh_clvmd.h +2 -1
@@ -13,6 +13,7 @@*/ -int refresh_clvmd (void ); +int refresh_clvmd (int all_nodes); +int restart_clvmd (int all_nodes);int debug_clvmd (int level,int clusterwide);
man/clvmd.8.in +7 -0
@@ -5,6 +5,7 @@ .B clvmd [\-d [<value>]] [\-C] [\-h] [\-R] +[\-S] [\-t <timeout>] [\-T <start timeout>] [\-V]
@@ -74,6 +75,12 @@ re-read the lvm configuration file. This command should be run whenever the devices on a cluster system are changed. .TP +.I \-S +Tells the running clvmd to exit and restart. This is a preferred option +to killing and restarting clvmd as it will preserve exclusive LV locks. +If a full stop & restart is done instead, exclusive LV locks will be +re-acquired as shared. +.TP .I \-I Selects the cluster manager to use for locking and internal communications, the available managers will be listed as part of the 'clvmd -h' output.
scripts/clvmd_init_red_hat.in +11 -1
@@ -146,7 +146,17 @@ # another start. Even if start is protected by rh_status_q, # that would avoid spawning another daemon, it would try to # reactivate the VGs. - stop && start + + # Try to get clvmd to restart itself. This will preserve + # exclusive LV locks + action "Restarting $DAEMON: " $DAEMON -S || return $? + + # If that fails then do a normal stop & restart + if [ $? != 0 ]; then + stop && start + else + touch $LOCK_FILE + fi } # See how we were called.