cluster: RHEL56 - fence_egenera: insecure temporary file
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: c64fc3e1d5e8f9d92463c5bd500045e3cdf467db
Parent: 4b3e4e9e0a98a35216f717eb369fbad479596503
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Sun Dec 20 13:54:19 2009 +0100
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Fri Dec 10 11:12:11 2010 -0500
fence_egenera: insecure temporary file
This is a modification of commit
1441b5d066bc362b44573bee69d793403067ef2e
Log directory changed to /var/log since users often
use /var/log/cluster as a log file on RHEL5 for
debugging.
Resolves: rhbz#659090
Signed-off-by: Lon Hohberger <lhh(a)redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto(a)redhat.com>
---
fence/agents/egenera/Makefile | 7 +++++++
fence/agents/egenera/fence_egenera.pl | 6 +++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/fence/agents/egenera/Makefile b/fence/agents/egenera/Makefile
index 7158702..2a55978 100644
--- a/fence/agents/egenera/Makefile
+++ b/fence/agents/egenera/Makefile
@@ -14,6 +14,11 @@
SOURCE= fence_egenera.pl
TARGET= fence_egenera
+# Use /var/log/fence_egenera.log since we can't guarantee that
+# /var/log/cluster is not a user's log file BZ#659090
+LOGDIR= /var/log
+
+
top_srcdir=../..
include ${top_srcdir}/make/defines.mk
@@ -26,6 +31,7 @@ fence_egenera: fence_egenera.pl
${top_srcdir}/scripts/define2var ${top_srcdir}/config/copyright.cf perl REDHAT_COPYRIGHT >> $(TARGET)
echo "\$$BUILD_DATE=\"(built `date`)\";" >> $(TARGET)
awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(SOURCE) >> $(TARGET)
+ sed -ie 's#@''LOGDIR@#${LOGDIR}#g' $(TARGET)
chmod +x $(TARGET)
install: all
@@ -33,6 +39,7 @@ install: all
install -d ${sbindir}; \
fi
install -m755 ${TARGET} ${sbindir}
+ install -d ${DESTDIR}/${LOGDIR}
clean:
rm -f $(TARGET)
diff --git a/fence/agents/egenera/fence_egenera.pl b/fence/agents/egenera/fence_egenera.pl
index 441223a..e863c90 100755
--- a/fence/agents/egenera/fence_egenera.pl
+++ b/fence/agents/egenera/fence_egenera.pl
@@ -311,9 +311,9 @@ sub pserver_boot
sub pserver_shutdown
{
my $rtrn=1;
- local *egen_log;
- open(egen_log,">>/tmp/eglog");
- print egen_log "Attempting shutdown at ".`date`."\n";
+ local *egen_log;
+ open(egen_log,">>/@LOGDIR(a)/fence_egenera.log");
+ print egen_log "Attempting shutdown at ".`date`."\n";
for (my $trys=0; $trys<20; $trys++)
{
last if (pserver_status != 0);
13 years, 5 months
cluster: RHEL4 - dlm-kernel: close-purge option
by David Teigland
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 77602315f5d8803d9d00b2379ab1ceb9da16df93
Parent: e6ce10a475c1d9967a62e79546d23d5fedf936c1
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Oct 28 14:06:43 2010 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Dec 10 09:04:37 2010 -0600
dlm-kernel: close-purge option
When enabled, the dlm does not try to cancel/unlock any
locks that a process holds when it exits. Instead it
uses a newly implemented "purge" routine that walks through
all resources/locks, forcibly deleting any locks held by
the given pid.
bz 645531
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
dlm-kernel/src/config.c | 8 ++-
dlm-kernel/src/config.h | 1 +
dlm-kernel/src/device.c | 104 +++++++++++++++++++++++++++++-
dlm-kernel/src/dlm_internal.h | 1 +
dlm-kernel/src/lockqueue.c | 39 +++++++++++
dlm-kernel/src/lockqueue.h | 1 +
dlm-kernel/src/midcomms.c | 7 ++
dlm-kernel/src/rsb.c | 142 +++++++++++++++++++++++++++++++++++++++++
dlm-kernel/src/rsb.h | 1 +
9 files changed, 302 insertions(+), 2 deletions(-)
diff --git a/dlm-kernel/src/config.c b/dlm-kernel/src/config.c
index 3ce052c..a0554b1 100644
--- a/dlm-kernel/src/config.c
+++ b/dlm-kernel/src/config.c
@@ -30,6 +30,7 @@
#define DEFAULT_DEADLOCKTIME 10
#define DEFAULT_RECOVER_TIMER 5
#define DEFAULT_USER_GRANT_NOW 1
+#define DEFAULT_CLOSE_PURGE 0
struct config_info dlm_config = {
.tcp_port = DEFAULT_TCP_PORT,
@@ -42,7 +43,8 @@ struct config_info dlm_config = {
.conn_increment = DEFAULT_CONN_INCREMENT,
.deadlocktime = DEFAULT_DEADLOCKTIME,
.recover_timer = DEFAULT_RECOVER_TIMER,
- .user_grant_now = DEFAULT_USER_GRANT_NOW
+ .user_grant_now = DEFAULT_USER_GRANT_NOW,
+ .close_purge = DEFAULT_CLOSE_PURGE
};
@@ -93,6 +95,10 @@ static struct config_proc_info {
{
.name = "user_grant_now",
.value = &dlm_config.user_grant_now,
+ },
+ {
+ .name = "close_purge",
+ .value = &dlm_config.close_purge,
}
};
static struct proc_dir_entry *dlm_dir;
diff --git a/dlm-kernel/src/config.h b/dlm-kernel/src/config.h
index e0dab07..d8c92f0 100644
--- a/dlm-kernel/src/config.h
+++ b/dlm-kernel/src/config.h
@@ -26,6 +26,7 @@ struct config_info {
int deadlocktime;
int recover_timer;
int user_grant_now;
+ int close_purge;
};
extern struct config_info dlm_config;
diff --git a/dlm-kernel/src/device.c b/dlm-kernel/src/device.c
index 44e1379..018ca03 100644
--- a/dlm-kernel/src/device.c
+++ b/dlm-kernel/src/device.c
@@ -39,6 +39,9 @@
#include "device.h"
#include "config.h"
#include "lockspace.h"
+#include "rsb.h"
+#include "lockqueue.h"
+#include "nodes.h"
extern struct dlm_lkb *dlm_get_lkb(struct dlm_ls *, int);
static struct file_operations _dlm_fops;
@@ -120,6 +123,7 @@ struct file_info {
struct user_ls *fi_ls;
atomic_t fi_refcnt; /* Number of users */
unsigned long fi_flags; /* Bit 1 means the device is open */
+ int fi_pid;
};
@@ -430,6 +434,7 @@ static int dlm_open(struct inode *inode, struct file *file)
atomic_set(&f->fi_refcnt, 1);
f->fi_flags = 0;
set_bit(1, &f->fi_flags);
+ f->fi_pid = 0;
file->private_data = f;
@@ -455,8 +460,94 @@ static int check_version(struct dlm_write_request *req)
return 0;
}
+static int dlm_close_purge(struct inode *inode, struct file *file)
+{
+ struct file_info *f = file->private_data;
+ struct lock_info *old_li, *safe;
+ sigset_t tmpsig;
+ sigset_t allsigs;
+ struct user_ls *lsinfo;
+ struct dlm_ls *ls;
+ int lkb_count = 0, li_count = 0;
+ int pid = f->fi_pid;
+ int ournodeid = our_nodeid();
+
+ lsinfo = find_lockspace(iminor(inode));
+ if (!lsinfo)
+ return -ENOENT;
+
+ if (pid != current->pid) {
+ printk("close_purge by different pid %d first %d\n",
+ current->pid, pid);
+ }
+
+ /* Mark this closed so that ASTs will not be delivered any more */
+ clear_bit(1, &f->fi_flags);
+
+ /* Block signals while we are doing this */
+ sigfillset(&allsigs);
+ sigprocmask(SIG_BLOCK, &allsigs, &tmpsig);
+
+ list_for_each_entry_safe(old_li, safe, &f->fi_lkb_list, li_ownerqueue) {
+ struct dlm_lkb *lkb;
+
+ lkb = dlm_get_lkb(f->fi_ls->ls_lockspace, old_li->li_lksb.sb_lkid);
+ if (lkb) {
+ lkb->lkb_astparam = (long)NULL;
+ lkb_count++;
+ }
+
+ list_del(&old_li->li_ownerqueue);
+ kfree(old_li);
+ put_file_info(f);
+ li_count++;
+ }
+
+ printk("dlm_close_purge our_nodeid %d pid %d lkb_count %d li_count %d\n",
+ ournodeid, pid, lkb_count, li_count);
+
+ ls = find_lockspace_by_local_id(lsinfo->ls_lockspace);
+ if (!ls) {
+ printk("dlm_purge: no lockspace found\n");
+ goto out;
+ }
+
+ send_purge_all(ls, ournodeid, pid);
+ dlm_purge(ls, ournodeid, pid, -1);
+
+ /* must happen prior to dlm_release_lockspace() */
+ put_lockspace(ls);
+ out:
+ /*
+ * If this is the last reference to the lockspace
+ * then free the struct. If it's an AUTOFREE lockspace
+ * then free the whole thing.
+ */
+ down(&user_ls_lock);
+ if (atomic_dec_and_test(&lsinfo->ls_refcnt)) {
+
+ if (lsinfo->ls_lockspace) {
+ if (test_bit(LS_FLAG_AUTOFREE, &lsinfo->ls_flags)) {
+ unregister_lockspace(lsinfo, 1);
+ }
+ }
+ else {
+ kfree(lsinfo->ls_miscinfo.name);
+ kfree(lsinfo);
+ }
+ }
+ up(&user_ls_lock);
+ put_file_info(f);
+
+ /* Restore signals */
+ sigprocmask(SIG_SETMASK, &tmpsig, NULL);
+ recalc_sigpending();
+
+ return 0;
+}
+
/* Close on lockspace device */
-static int dlm_close(struct inode *inode, struct file *file)
+static int dlm_close_unlock(struct inode *inode, struct file *file)
{
struct file_info *f = file->private_data;
struct lock_info li;
@@ -608,6 +699,14 @@ static int dlm_close(struct inode *inode, struct file *file)
return 0;
}
+static int dlm_close(struct inode *inode, struct file *file)
+{
+ if (dlm_config.close_purge)
+ return dlm_close_purge(inode, file);
+ else
+ return dlm_close_unlock(inode, file);
+}
+
/*
* ioctls to create/remove lockspaces, and check how many
* outstanding ASTs there are against a particular LS.
@@ -933,6 +1032,9 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, struct dlm_lock_param
if ((kparams->flags & DLM_LKF_PERSISTENT) && kparams->parent)
return -EINVAL;
+ if (dlm_config.close_purge && !fi->fi_pid)
+ fi->fi_pid = current->pid;
+
/* For conversions, the lock will already have a lock_info
block squirelled away in astparam */
if (kparams->flags & DLM_LKF_CONVERT) {
diff --git a/dlm-kernel/src/dlm_internal.h b/dlm-kernel/src/dlm_internal.h
index ed54db3..3ed07ac 100644
--- a/dlm-kernel/src/dlm_internal.h
+++ b/dlm-kernel/src/dlm_internal.h
@@ -590,6 +590,7 @@ struct dlm_query_reply {
#define GDLM_REMCMD_SENDBAST 7
#define GDLM_REMCMD_SENDCAST 8
#define GDLM_REMCMD_REM_RESDATA 9
+#define GDLM_REMCMD_PURGE 10
#define GDLM_REMCMD_RECOVERMESSAGE 20
#define GDLM_REMCMD_RECOVERREPLY 21
#define GDLM_REMCMD_QUERY 30
diff --git a/dlm-kernel/src/lockqueue.c b/dlm-kernel/src/lockqueue.c
index d203e16..9e3db73 100644
--- a/dlm-kernel/src/lockqueue.c
+++ b/dlm-kernel/src/lockqueue.c
@@ -710,6 +710,41 @@ void remote_remove_direntry(struct dlm_ls *ls, int nodeid, char *name,
midcomms_send_buffer(&req->rr_header, e);
}
+static int send_purge(struct dlm_ls *ls, int to_nodeid, int pid)
+{
+ struct writequeue_entry *e;
+ struct dlm_request *req;
+
+ printk("dlm: send_purge to nodeid %d pid %d\n", to_nodeid, pid);
+
+ e = lowcomms_get_buffer(to_nodeid,
+ sizeof(struct dlm_request),
+ ls->ls_allocation,
+ (char **) &req);
+ if (!e) {
+ printk("send_purge get_buffer error\n");
+ return -1;
+ }
+ memset(req, 0, sizeof(struct dlm_request));
+
+ req->rr_header.rh_cmd = GDLM_REMCMD_PURGE;
+ req->rr_header.rh_length = sizeof(struct dlm_request);
+ req->rr_header.rh_lockspace = ls->ls_global_id;
+ req->rr_pid = pid;
+ midcomms_send_buffer(&req->rr_header, e);
+ return 0;
+}
+
+void send_purge_all(struct dlm_ls *ls, int ournodeid, int pid)
+{
+ struct dlm_csb *csb;
+
+ list_for_each_entry(csb, &ls->ls_nodes, list) {
+ if (csb->node->nodeid != ournodeid)
+ send_purge(ls, csb->node->nodeid, pid);
+ }
+}
+
/*
* Send remote cluster request to directory or master node before the request
* is put on the lock queue. Runs in the context of the locking caller.
@@ -912,6 +947,10 @@ int process_cluster_request(int nodeid, struct dlm_header *req, int recovery)
send_reply = 1;
break;
+ case GDLM_REMCMD_PURGE:
+ dlm_purge(lspace, our_nodeid(), freq->rr_pid, nodeid);
+ break;
+
case GDLM_REMCMD_REM_RESDATA:
namelen = freq->rr_header.rh_length - sizeof(*freq) + 1;
diff --git a/dlm-kernel/src/lockqueue.h b/dlm-kernel/src/lockqueue.h
index 26bfe19..91d8502 100644
--- a/dlm-kernel/src/lockqueue.h
+++ b/dlm-kernel/src/lockqueue.h
@@ -25,5 +25,6 @@ int reply_in_requestqueue(struct dlm_ls * ls, int lkid);
void remote_remove_direntry(struct dlm_ls * ls, int nodeid, char *name,
int namelen);
void allocate_and_copy_lvb(struct dlm_ls * ls, char **lvbptr, char *src);
+void send_purge_all(struct dlm_ls *ls, int ournodeid, int pid);
#endif /* __LOCKQUEUE_DOT_H__ */
diff --git a/dlm-kernel/src/midcomms.c b/dlm-kernel/src/midcomms.c
index aaeefee..992dc61 100644
--- a/dlm-kernel/src/midcomms.c
+++ b/dlm-kernel/src/midcomms.c
@@ -65,6 +65,9 @@ static void host_to_network(void *msg)
switch (req->rr_header.rh_cmd) {
+ case GDLM_REMCMD_PURGE:
+ req->rr_pid = cpu_to_le32(req->rr_pid);
+ break;
case GDLM_REMCMD_LOCKREQUEST:
case GDLM_REMCMD_CONVREQUEST:
req->rr_range_start = cpu_to_le64(req->rr_range_start);
@@ -149,6 +152,10 @@ static void network_to_host(void *msg)
switch (req->rr_header.rh_cmd) {
+ case GDLM_REMCMD_PURGE:
+ req->rr_pid = le32_to_cpu(req->rr_pid);
+ break;
+
case GDLM_REMCMD_LOCKREQUEST:
case GDLM_REMCMD_CONVREQUEST:
req->rr_range_start = le64_to_cpu(req->rr_range_start);
diff --git a/dlm-kernel/src/rsb.c b/dlm-kernel/src/rsb.c
index edcdc6e..68fbff7 100644
--- a/dlm-kernel/src/rsb.c
+++ b/dlm-kernel/src/rsb.c
@@ -19,6 +19,148 @@
#include "dir.h"
#include "util.h"
#include "rsb.h"
+#include "ast.h"
+#include "lkb.h"
+
+static int purge_queue(struct dlm_ls *ls, struct dlm_rsb *r,
+ struct list_head *queue, int pid,
+ int pid_is_local, int rsb_is_master)
+{
+ struct dlm_lkb *lkb, *lkb2;
+ int purge, total = 0;
+
+ list_for_each_entry_safe(lkb, lkb2, queue, lkb_statequeue) {
+
+ /* the one general rule can be factored out of checks below */
+
+ if (lkb->lkb_ownpid != pid)
+ continue;
+
+ purge = 0;
+
+ /* local copy lkb on locally mastered rsb */
+
+ if (pid_is_local && rsb_is_master && lkb->lkb_nodeid == 0)
+ purge = 1;
+
+ /* process copy lkb on remotely mastered rsb */
+
+ if (pid_is_local && !rsb_is_master && lkb->lkb_nodeid != 0)
+ purge = 1;
+
+ /* master copy lkb on locally mastered rsb */
+
+ if (!pid_is_local && rsb_is_master && lkb->lkb_nodeid > 0)
+ purge = 1;
+
+ if (!purge)
+ continue;
+
+ printk("dlm: purge lkid %x pid %d nodeid %d ast %x lqs %d sts %d gr %d rq %d pil %d rim %d r_nodeid %d r_name %s\n",
+ lkb->lkb_id,
+ lkb->lkb_ownpid,
+ lkb->lkb_nodeid,
+ lkb->lkb_astflags,
+ lkb->lkb_lockqueue_state,
+ lkb->lkb_status,
+ lkb->lkb_grmode,
+ lkb->lkb_rqmode,
+ pid_is_local,
+ rsb_is_master,
+ r->res_nodeid,
+ r->res_name);
+
+ if (!lkb->lkb_status) {
+ printk("dlm: purge lkid %x zero status\n", lkb->lkb_id);
+ continue;
+ }
+
+ if (lkb->lkb_astflags)
+ remove_from_astqueue(lkb);
+
+ if (lkb->lkb_lockqueue_state)
+ remove_from_lockqueue(lkb);
+
+ if (lkb->lkb_duetime)
+ remove_from_deadlockqueue(lkb);
+
+ list_del(&lkb->lkb_statequeue);
+ lkb->lkb_status = 0;
+ release_lkb(ls, lkb);
+ release_rsb(r);
+ total++;
+ }
+
+ return total;
+}
+
+/*
+ * if from_nodeid is -1, the pid is local,
+ * - if an rsb has a remote master we need to send_purge to it so the
+ * master copy lkb can be removed, in addition to the process copy
+ * removed here directly.
+ * - if an rsb is mastered locally, we remove the local copy lkb's
+ * here directly
+ *
+ * if from_nodeid is > 0, the pid is remote, so we are are looking for
+ * master copy lkb's with lkb_nodeid equal to from_nodeid and matching pid
+ */
+
+void dlm_purge(struct dlm_ls *ls, int ournodeid, int pid, int from_nodeid)
+{
+ struct dlm_rsb *r, *r2;
+ int pid_is_local, rsb_is_master;
+ int purged, total_purged = 0;
+
+ printk("dlm: purge our_nodeid %d pid %d from_nodeid %d\n",
+ ournodeid, pid, from_nodeid);
+
+ if (from_nodeid == -1) {
+ /*
+ * pid is local, we're looking for either:
+ * . local copy lkbs on locally mastered rsbs
+ * . process copy lkbs on remotely mastered rsbs
+ * (and send purge to the rsb master)
+ */
+ pid_is_local = 1;
+ } else {
+ /*
+ * pid is remote, we're just looking for master copy
+ * lkbs on locally mastered rsbs
+ */
+ pid_is_local = 0;
+ }
+
+ down_write(&ls->ls_root_lock);
+
+ list_for_each_entry_safe(r, r2, &ls->ls_rootres, res_rootlist) {
+ hold_rsb(r);
+ down_write(&r->res_lock);
+
+ rsb_is_master = (r->res_nodeid == 0) ? 1 : 0;
+
+ purged = 0;
+
+ purged += purge_queue(ls, r, &r->res_waitqueue, pid,
+ pid_is_local, rsb_is_master);
+ purged += purge_queue(ls, r, &r->res_convertqueue, pid,
+ pid_is_local, rsb_is_master);
+ purged += purge_queue(ls, r, &r->res_grantqueue, pid,
+ pid_is_local, rsb_is_master);
+
+ total_purged += purged;
+
+ if (rsb_is_master && purged)
+ grant_pending_locks(r);
+
+ up_write(&r->res_lock);
+ release_rsb_locked(r);
+ }
+
+ up_write(&ls->ls_root_lock);
+
+ printk("dlm: purged %d pid %d\n", total_purged, pid);
+}
static struct dlm_rsb *search_hashchain(struct list_head *head,
struct dlm_rsb *parent,
diff --git a/dlm-kernel/src/rsb.h b/dlm-kernel/src/rsb.h
index 87e1cd7..d1d1a2f 100644
--- a/dlm-kernel/src/rsb.h
+++ b/dlm-kernel/src/rsb.h
@@ -30,5 +30,6 @@ int lkb_dequeue(struct dlm_lkb *lkb);
int res_lkb_dequeue(struct dlm_lkb *lkb);
int lkb_swqueue(struct dlm_rsb *r, struct dlm_lkb *lkb, int type);
int res_lkb_swqueue(struct dlm_rsb *r, struct dlm_lkb *lkb, int type);
+void dlm_purge(struct dlm_ls *ls, int ournodeid, int pid, int from_nodeid);
#endif /* __RSB_DOT_H__ */
13 years, 5 months
cluster: RHEL6 - mkfs.gfs2 should support discard request generation
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: ab93700c01af315656c63a5c5bd7387a347a390d
Parent: 59f2ee2e05bff5f040ebb8641732ebb47e61944f
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Thu Dec 9 15:17:10 2010 -0600
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Thu Dec 9 15:18:23 2010 -0600
mkfs.gfs2 should support discard request generation
This patch allows mkfs.gfs2 to issue discard ioctls to the underlying
devices. All the file system blocks are discarded before the file system
is formatted, as was done for other file systems.
rhbz#656956
---
gfs2/man/mkfs.gfs2.8 | 5 +++++
gfs2/mkfs/main_grow.c | 18 ++++++++++++++++++
gfs2/mkfs/main_mkfs.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/gfs2/man/mkfs.gfs2.8 b/gfs2/man/mkfs.gfs2.8
index 279c12f..63348f8 100644
--- a/gfs2/man/mkfs.gfs2.8
+++ b/gfs2/man/mkfs.gfs2.8
@@ -39,6 +39,11 @@ The number of journals for gfs2_mkfs to create. You need at least one
journal per machine that will mount the filesystem. If this option is
not specified, one journal will be created.
.TP
+\fB-K\fP
+Keep, do not attempt to discard blocks at mkfs time (discarding blocks
+initially is useful on solid state devices and sparse / thin-provisioned
+storage).
+.TP
\fB-O\fP
This option prevents gfs2_mkfs from asking for confirmation before writing
the filesystem.
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index e442a25..efe3bfb 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -34,6 +34,19 @@ static unsigned int rgsize = 0;
extern int create_new_inode(struct gfs2_sbd *sdp);
extern int rename2system(struct gfs2_sbd *sdp, char *new_dir, char *new_name);
+#ifndef BLKDISCARD
+#define BLKDISCARD _IO(0x12,119)
+#endif
+
+static int discard_blocks(int fd, uint64_t start, uint64_t len)
+{
+ __uint64_t range[2] = { start, len };
+
+ if (ioctl(fd, BLKDISCARD, &range) < 0)
+ return errno;
+ return 0;
+}
+
/**
* usage - Print out the usage message
*
@@ -157,6 +170,7 @@ static void initialize_new_portion(struct gfs2_sbd *sdp, int *old_rg_count)
{
uint64_t rgrp = 0;
osi_list_t *head = &sdp->rglist;
+ struct rgrp_list *rl;
*old_rg_count = 0;
/* Delete the old RGs from the rglist */
@@ -165,6 +179,10 @@ static void initialize_new_portion(struct gfs2_sbd *sdp, int *old_rg_count)
(*old_rg_count)++;
osi_list_del(head->next);
}
+ /* Issue a discard ioctl for the new portion */
+ rl = osi_list_entry(&sdp->rglist.next, struct rgrp_list, list);
+ discard_blocks(sdp->device_fd, rl->start * sdp->bsize,
+ (sdp->device.length - rl->start) * sdp->bsize);
/* Build the remaining resource groups */
build_rgrps(sdp, !test);
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 6af8c3a..4197dac 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -16,6 +16,7 @@
#include <signal.h>
#include <sys/time.h>
#include <libintl.h>
+#include <sys/ioctl.h>
#define _(String) gettext(String)
@@ -23,6 +24,8 @@
#include "libgfs2.h"
#include "gfs2_mkfs.h"
+int discard = 1;
+
/**
* This function is for libgfs2's sake.
*/
@@ -53,6 +56,7 @@ print_usage(const char *prog_name)
" -h Print this help, then exit\n"
" -J <MB> Size of journals\n"
" -j <num> Number of journals\n"
+ " -K Don't try to discard unused blocks\n"
" -O Don't ask for confirmation\n"
" -p <name> Name of the locking protocol\n"
" -q Don't print anything\n"
@@ -62,6 +66,30 @@ print_usage(const char *prog_name)
" -V Print program version information, then exit\n"), prog_name);
}
+#ifndef BLKDISCARD
+#define BLKDISCARD _IO(0x12,119)
+#endif
+
+static int discard_blocks(struct gfs2_sbd *sdp)
+{
+ __uint64_t range[2];
+
+ range[0] = 0;
+ range[1] = sdp->device.length * sdp->bsize;
+ if (sdp->debug)
+ printf("Issuing discard ioctl: range: %llu - %llu...",
+ (unsigned long long)range[0],
+ (unsigned long long)range[1]);
+ if (ioctl(sdp->device_fd, BLKDISCARD, &range) < 0) {
+ if (sdp->debug)
+ printf("error = %d\n", errno);
+ return errno;
+ }
+ if (sdp->debug)
+ printf("Successful.\n");
+ return 0;
+}
+
/**
* decode_arguments - decode command line arguments and fill in the struct gfs2_sbd
* @argc:
@@ -108,6 +136,10 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
sdp->md.journals = atoi(optarg);
break;
+ case 'K':
+ discard = 0;
+ break;
+
case 'O':
sdp->override = TRUE;
break;
@@ -618,6 +650,9 @@ void main_mkfs(int argc, char *argv[])
exit(-1);
}
+ if (discard)
+ discard_blocks(sdp);
+
/* Compute the resource group layouts */
compute_rgrp_layout(sdp, rgsize_specified);
13 years, 5 months
gfs2-utils: master - mkfs.gfs2 should support discard request generation
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: b2287ab25756f2e7c384af92a9dfebc8ffab2b83
Parent: 4e70727853794c5c6dbf93c98ee5a4e5015be868
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Thu Dec 9 15:08:52 2010 -0600
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Thu Dec 9 15:08:52 2010 -0600
mkfs.gfs2 should support discard request generation
This patch allows mkfs.gfs2 to issue discard ioctls to the underlying
devices. All the file system blocks are discarded before the file system
is formatted, as was done for other file systems.
rhbz#656956
---
gfs2/man/mkfs.gfs2.8 | 5 +++++
gfs2/mkfs/main_grow.c | 18 ++++++++++++++++++
gfs2/mkfs/main_mkfs.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/gfs2/man/mkfs.gfs2.8 b/gfs2/man/mkfs.gfs2.8
index 279c12f..63348f8 100644
--- a/gfs2/man/mkfs.gfs2.8
+++ b/gfs2/man/mkfs.gfs2.8
@@ -39,6 +39,11 @@ The number of journals for gfs2_mkfs to create. You need at least one
journal per machine that will mount the filesystem. If this option is
not specified, one journal will be created.
.TP
+\fB-K\fP
+Keep, do not attempt to discard blocks at mkfs time (discarding blocks
+initially is useful on solid state devices and sparse / thin-provisioned
+storage).
+.TP
\fB-O\fP
This option prevents gfs2_mkfs from asking for confirmation before writing
the filesystem.
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 21f7f7a..e76affc 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -36,6 +36,19 @@ static unsigned int rgsize = 0;
extern int create_new_inode(struct gfs2_sbd *sdp);
extern int rename2system(struct gfs2_sbd *sdp, char *new_dir, char *new_name);
+#ifndef BLKDISCARD
+#define BLKDISCARD _IO(0x12,119)
+#endif
+
+static int discard_blocks(int fd, uint64_t start, uint64_t len)
+{
+ __uint64_t range[2] = { start, len };
+
+ if (ioctl(fd, BLKDISCARD, &range) < 0)
+ return errno;
+ return 0;
+}
+
/**
* usage - Print out the usage message
*
@@ -158,6 +171,7 @@ static void initialize_new_portion(struct gfs2_sbd *sdp, int *old_rg_count)
{
uint64_t rgrp = 0;
osi_list_t *head = &sdp->rglist;
+ struct rgrp_list *rl;
*old_rg_count = 0;
/* Delete the old RGs from the rglist */
@@ -166,6 +180,10 @@ static void initialize_new_portion(struct gfs2_sbd *sdp, int *old_rg_count)
(*old_rg_count)++;
osi_list_del(head->next);
}
+ /* Issue a discard ioctl for the new portion */
+ rl = osi_list_entry(&sdp->rglist.next, struct rgrp_list, list);
+ discard_blocks(sdp->device_fd, rl->start * sdp->bsize,
+ (sdp->device.length - rl->start) * sdp->bsize);
/* Build the remaining resource groups */
build_rgrps(sdp, !test);
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 719893b..3cec996 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -18,6 +18,7 @@
#include <signal.h>
#include <sys/time.h>
#include <libintl.h>
+#include <sys/ioctl.h>
#define _(String) gettext(String)
@@ -25,6 +26,8 @@
#include "libgfs2.h"
#include "gfs2_mkfs.h"
+int discard = 1;
+
/**
* This function is for libgfs2's sake.
*/
@@ -55,6 +58,7 @@ print_usage(const char *prog_name)
" -h Print this help, then exit\n"
" -J <MB> Size of journals\n"
" -j <num> Number of journals\n"
+ " -K Don't try to discard unused blocks\n"
" -O Don't ask for confirmation\n"
" -p <name> Name of the locking protocol\n"
" -q Don't print anything\n"
@@ -64,6 +68,30 @@ print_usage(const char *prog_name)
" -V Print program version information, then exit\n"), prog_name);
}
+#ifndef BLKDISCARD
+#define BLKDISCARD _IO(0x12,119)
+#endif
+
+static int discard_blocks(struct gfs2_sbd *sdp)
+{
+ __uint64_t range[2];
+
+ range[0] = 0;
+ range[1] = sdp->device.length * sdp->bsize;
+ if (sdp->debug)
+ printf("Issuing discard ioctl: range: %llu - %llu...",
+ (unsigned long long)range[0],
+ (unsigned long long)range[1]);
+ if (ioctl(sdp->device_fd, BLKDISCARD, &range) < 0) {
+ if (sdp->debug)
+ printf("error = %d\n", errno);
+ return errno;
+ }
+ if (sdp->debug)
+ printf("Successful.\n");
+ return 0;
+}
+
/**
* decode_arguments - decode command line arguments and fill in the struct gfs2_sbd
* @argc:
@@ -110,6 +138,10 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
sdp->md.journals = atoi(optarg);
break;
+ case 'K':
+ discard = 0;
+ break;
+
case 'O':
sdp->override = TRUE;
break;
@@ -620,6 +652,9 @@ void main_mkfs(int argc, char *argv[])
exit(-1);
}
+ if (discard)
+ discard_blocks(sdp);
+
/* Compute the resource group layouts */
compute_rgrp_layout(sdp, rgsize_specified);
13 years, 5 months
cluster: STABLE31 - rgmanager: Make clufindhostname -i predictable
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: b057008da82f0caeb539e33575eb1f0a07da192c
Parent: 26b040e22d1989d9ae09eed076a8d69ec0d47451
Author: Lon Hohberger <lhh(a)redhat.com>
AuthorDate: Thu Dec 9 16:01:27 2010 -0500
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Thu Dec 9 16:03:06 2010 -0500
rgmanager: Make clufindhostname -i predictable
Resolves: rhbz#592613
Signed-off-by: Lon Hohberger <lhh(a)redhat.com>
---
rgmanager/src/utils/clufindhostname.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/rgmanager/src/utils/clufindhostname.c b/rgmanager/src/utils/clufindhostname.c
index 42e1691..f8bf7fd 100644
--- a/rgmanager/src/utils/clufindhostname.c
+++ b/rgmanager/src/utils/clufindhostname.c
@@ -24,7 +24,7 @@ main(int argc, char **argv)
void *ptr;
struct in_addr addr4;
struct in6_addr addr6;
- int opt, size, family;
+ int opt, size, family, ret;
char *sep;
if (argc != 3) {
@@ -47,8 +47,10 @@ main(int argc, char **argv)
size = sizeof(addr6);
}
- if (inet_pton(family, optarg, ptr) < 0) {
- perror("inet_pton");
+ ret = inet_pton(family, optarg, ptr);
+ if (ret <= 0) {
+ if (ret < 0)
+ perror("inet_pton");
exit(2);
}
13 years, 5 months
cluster: RHEL56 - resource-agents: Fix migrateuriopt setting
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 4b3e4e9e0a98a35216f717eb369fbad479596503
Parent: c80b1f7e9a8152f4a9c6fb187b8d22fe69311b38
Author: Lon Hohberger <lhh(a)redhat.com>
AuthorDate: Thu Dec 2 14:40:18 2010 -0500
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Tue Dec 7 10:37:48 2010 -0500
resource-agents: Fix migrateuriopt setting
When a user was specifically setting migration_uri (for example,
to get around ssh banners causing migration to fail),
vm.sh was leaving the migrateuriopt variable unset when using
QEMU/KVM. This caused the printf() during command line generation
to be incorrect.
This means the generated command line looked like this:
virsh migrate --live vm1 \
qemu+ssh://node1.example.com/system?command=/bin/quiet_ssh.sh
node1.example.com
Instead of:
virsh migrate --live vm1 \
qemu+ssh://node1.example.com/system?command=/bin/quiet_ssh.sh
tcp:node1.example.com
^^^^
Resolves: rhbz#659477
Signed-off-by: Lon Hohberger <lhh(a)redhat.com>
Reviewed-by: Ryan O'Hara <rohara(a)redhat.com>
---
rgmanager/src/resources/vm.sh | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/rgmanager/src/resources/vm.sh b/rgmanager/src/resources/vm.sh
index a7a458b..7310da3 100755
--- a/rgmanager/src/resources/vm.sh
+++ b/rgmanager/src/resources/vm.sh
@@ -812,7 +812,6 @@ validate_all()
# Virsh makes it easier to do this. Really.
if [ "$OCF_RESKEY_hypervisor" = "qemu" ]; then
export OCF_RESKEY_migration_uri="qemu+ssh://%s/system"
- export migrateuriopt="tcp:%s"
fi
# I just need to believe in it more.
@@ -828,6 +827,10 @@ validate_all()
return $OCF_ERR_ARGS
fi
+ if [ "$OCF_RESKEY_hypervisor" = "qemu" ]; then
+ export migrateuriopt="tcp:%s"
+ fi
+
#virsh list --all | awk '{print $2}' | grep -q "^$OCF_RESKEY_name\$"
return $?
}
13 years, 5 months
cluster: RHEL56 - Revert "resource-agents: Fix migrateuriopt setting"
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: c80b1f7e9a8152f4a9c6fb187b8d22fe69311b38
Parent: 648055167f28418094f5ce7f6ebe304af1444fef
Author: Lon Hohberger <lhh(a)redhat.com>
AuthorDate: Tue Dec 7 10:35:32 2010 -0500
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Tue Dec 7 10:37:37 2010 -0500
Revert "resource-agents: Fix migrateuriopt setting"
This reverts commit 648055167f28418094f5ce7f6ebe304af1444fef.
Was missing bugzilla # in changelog.
---
rgmanager/src/resources/vm.sh | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/rgmanager/src/resources/vm.sh b/rgmanager/src/resources/vm.sh
index 7310da3..a7a458b 100755
--- a/rgmanager/src/resources/vm.sh
+++ b/rgmanager/src/resources/vm.sh
@@ -812,6 +812,7 @@ validate_all()
# Virsh makes it easier to do this. Really.
if [ "$OCF_RESKEY_hypervisor" = "qemu" ]; then
export OCF_RESKEY_migration_uri="qemu+ssh://%s/system"
+ export migrateuriopt="tcp:%s"
fi
# I just need to believe in it more.
@@ -827,10 +828,6 @@ validate_all()
return $OCF_ERR_ARGS
fi
- if [ "$OCF_RESKEY_hypervisor" = "qemu" ]; then
- export migrateuriopt="tcp:%s"
- fi
-
#virsh list --all | awk '{print $2}' | grep -q "^$OCF_RESKEY_name\$"
return $?
}
13 years, 5 months
cluster: RHEL56 - resource-agents: Fix migrateuriopt setting
by Lon Hohberger
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 648055167f28418094f5ce7f6ebe304af1444fef
Parent: bc2134319c63bebb7389a5077a6eac5b7fc60df6
Author: Lon Hohberger <lhh(a)redhat.com>
AuthorDate: Thu Dec 2 14:40:18 2010 -0500
Committer: Lon Hohberger <lhh(a)redhat.com>
CommitterDate: Tue Dec 7 10:29:28 2010 -0500
resource-agents: Fix migrateuriopt setting
When a user was specifically setting migration_uri (for example,
to get around ssh banners causing migration to fail),
vm.sh was leaving the migrateuriopt variable unset when using
QEMU/KVM. This caused the printf() during command line generation
to be incorrect.
This means the generated command line looked like this:
virsh migrate --live vm1 \
qemu+ssh://node1.example.com/system?command=/bin/quiet_ssh.sh
node1.example.com
Instead of:
virsh migrate --live vm1 \
qemu+ssh://node1.example.com/system?command=/bin/quiet_ssh.sh
tcp:node1.example.com
^^^^
Signed-off-by: Lon Hohberger <lhh(a)redhat.com>
---
rgmanager/src/resources/vm.sh | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/rgmanager/src/resources/vm.sh b/rgmanager/src/resources/vm.sh
index a7a458b..7310da3 100755
--- a/rgmanager/src/resources/vm.sh
+++ b/rgmanager/src/resources/vm.sh
@@ -812,7 +812,6 @@ validate_all()
# Virsh makes it easier to do this. Really.
if [ "$OCF_RESKEY_hypervisor" = "qemu" ]; then
export OCF_RESKEY_migration_uri="qemu+ssh://%s/system"
- export migrateuriopt="tcp:%s"
fi
# I just need to believe in it more.
@@ -828,6 +827,10 @@ validate_all()
return $OCF_ERR_ARGS
fi
+ if [ "$OCF_RESKEY_hypervisor" = "qemu" ]; then
+ export migrateuriopt="tcp:%s"
+ fi
+
#virsh list --all | awk '{print $2}' | grep -q "^$OCF_RESKEY_name\$"
return $?
}
13 years, 5 months
cluster: RHEL56 - fence_scsi_test: document 'clear' action in man page.
by rohara
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: bc2134319c63bebb7389a5077a6eac5b7fc60df6
Parent: 623431556dc74bfa2f2f75c41ad5947a62b1e12a
Author: Ryan O'Hara <rohara(a)redhat.com>
AuthorDate: Tue Dec 7 09:04:38 2010 -0600
Committer: Ryan O'Hara <rohara(a)redhat.com>
CommitterDate: Tue Dec 7 09:04:38 2010 -0600
fence_scsi_test: document 'clear' action in man page.
This patch documents the 'clear' action. Also added comments
to man page that state the need to use at least two nodes to
use fence_scsi_test.
Signed-off-by: Ryan O'Hara <rohara(a)redhat.com>
---
fence/man/fence_scsi_test.8 | 42 +++++++++++++++++++++++++++++++-----------
1 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/fence/man/fence_scsi_test.8 b/fence/man/fence_scsi_test.8
index 3252dca..57c3713 100644
--- a/fence/man/fence_scsi_test.8
+++ b/fence/man/fence_scsi_test.8
@@ -11,7 +11,7 @@ fence_scsi_test - Test for SCSI persistent reservation fencing
.SH SYNOPSIS
.B
-fence_scsi_test -o <on|off> -k <key>
+fence_scsi_test -o <action> [options]
[\fIOPTIONS\fR]
.SH DESCRIPTION
@@ -27,21 +27,39 @@ well as removing them. The "on" action is used to create reservations,
just as you would do when a node comes online. The "off" action is
used to remove registrations, which is equivalent to fencing. It is
important to test both the "on" and "off" actions when testing for
-fence_scsi compatibility.
+fence_scsi compatibility. Note that at least two nodes will be
+required to test both the "on" and "off" actions.
Because this script is capable of creating, modifying, and removing
existing reservations and registrations, it should not be used on any
systems that are actively using SCSI persistent reservations.
-.SH OPTIONS
+.SH ACTIONS
.TP
-\fB-o, --action=[on|off]\fR
-The action to perform. This value can be "on" or "off". For "on", the
-script will attempt to register a key (see -k option) with the
-device(s) (see -d option) and create a reservation if none exists. The
-"off" action will attempt to remove a key from the device(s). This
-option is required.
+\fB-o, --action=[on|off|clear]\fR
+The action to perform. This value can be "on", "off" or "clear".
+
+For "on", the script will attempt to register a key (see -k option)
+with the device(s) (see -d option) and create a reservation if none
+exists. This action requires a key to be specified with the -k option.
+Since registrations are created via the "register-and-ignore"
+subcommand, any existing registrations for the local node will be
+overwritten.
+
+The "off" action will attempt to remove a key from the device(s). This
+action requires a key to be specified with the -k option. Since the
+registration key is removed via the "preempt-and-abort" subcommand,
+this action should not be used to remove a node's own key. The "off"
+action is intended to remove another node's key. Note that the node
+attempting to revoke a registration key from the device(s) must also
+be registered with the device(s).
+The "clear" action will remove all registrations and reservations from
+the device(s). The key (-k option) is ignored for this action, but the
+node attempting to clear the device(s) must be registered with the
+device(s). Do not use this action on a operational cluster.
+
+.SH OPTIONS
.TP
\fB-k, --key=VALUE\fR
The key to use for the current action. The key must be a hexadecimal
@@ -54,7 +72,9 @@ removed from the device(s).
\fB-d, --devices=LIST\fR
List of devices to use for current action. This can be a single device
or a comma-separated list of devices. Each device should be given as
-the full path (eg. /dev/sdc).
+the full path (eg. /dev/sdc). For all actions, if no devices are
+specified, fence_scsi_test will automatically use all devices found in
+cluster volumes.
.TP
\fB-h, --help\fR
@@ -65,4 +85,4 @@ Print out a help message describing available options, then exit.
Verbose output.
.SH SEE ALSO
-fence_scsi(8), fence(8), fence_node(8), sg_persist(8), lvs(8), lvm.conf(5)
+fence_scsi(8), fence(8), fence_node(8), sg_persist(8), vgs(8), lvm.conf(5)
13 years, 5 months
cluster: RHEL56 - fence_scsi_test: add 'clear' action
by rohara
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 623431556dc74bfa2f2f75c41ad5947a62b1e12a
Parent: 34230e1b3ded31a0f8b40ae23f7439cb34ba58fd
Author: Ryan O'Hara <rohara(a)redhat.com>
AuthorDate: Mon Dec 6 18:26:42 2010 -0600
Committer: Ryan O'Hara <rohara(a)redhat.com>
CommitterDate: Mon Dec 6 18:26:42 2010 -0600
fence_scsi_test: add 'clear' action
Added new 'clear' action that will remove all registrations and
reservations on device(s). This action requires that the node be
registered with the devices to be cleared. See sg_persit(3) for
more information, specifically the -C option.
Resolves: rhbz#603838
Signed-off-by: Ryan O'Hara <rohara(a)redhat.com>
---
fence/agents/scsi/fence_scsi_test.pl | 87 ++++++++++++++++++++++++---------
1 files changed, 63 insertions(+), 24 deletions(-)
diff --git a/fence/agents/scsi/fence_scsi_test.pl b/fence/agents/scsi/fence_scsi_test.pl
index 25db6ba..5c2302c 100755
--- a/fence/agents/scsi/fence_scsi_test.pl
+++ b/fence/agents/scsi/fence_scsi_test.pl
@@ -68,6 +68,26 @@ sub do_action_off ($$$)
return ($err);
}
+sub do_action_clear ($$)
+{
+ my ($dev, $rk) = @_;
+
+ return (0) unless get_keys_register ($dev);
+
+ my $cmd = "sg_persist -n -o -C -K $rk -d $dev";
+ my @out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
+
+ if (defined $options{'v'}) {
+ $self = (caller(0))[3];
+ print " $self (dev=$dev rk=$rk)\n";
+ print " cmd=$cmd\n";
+ print " err=$err\n";
+ }
+
+ return ($err);
+}
+
sub do_verify_on (\@$$)
{
my @devices = @{(shift)};
@@ -119,6 +139,25 @@ sub do_verify_off ($$$)
return ($err);
}
+sub do_verify_clear ($$)
+{
+ my ($dev, $host_key) = @_;
+ my $err = 0;
+
+ if (defined $options{'v'}) {
+ $self = (caller(0))[3];
+ print " $self (dev=$dev host_key=$host_key)\n";
+ }
+
+ @keys = get_keys_register ($dev);
+
+ if (scalar (@keys) != 0) {
+ $err++;
+ }
+
+ return ($err);
+}
+
sub do_key_write ($)
{
my $key = shift;
@@ -259,24 +298,6 @@ sub do_preempt_abort ($$$)
return ($err);
}
-sub do_clear ($$)
-{
- my ($dev, $rk) = @_;
-
- my $cmd = "sg_persist -n -o -C -K $rk -d $dev";
- my @out = qx { $cmd 2> /dev/null };
- my $err = ($?>>8);
-
- if (defined $options{'v'}) {
- $self = (caller(0))[3];
- print " $self (dev=$dev rk=$rk)\n";
- print " cmd=$cmd\n";
- print " err=$err\n";
- }
-
- return ($err);
-}
-
sub do_reset ($)
{
my ($dev) = @_;
@@ -575,15 +596,17 @@ sub print_results ($)
sub print_usage
{
print "\n";
- print "Usage: fence_scsi_test -o <on|off> -k <key> [options]\n";
+ print "Usage: fence_scsi_test -o <action> [options]\n";
print "\n";
print "Actions:\n";
print "\n";
print " on Register <key> with the devices.\n";
- print " off Remove <key> form the devices.\n";
+ print " off Remove <key> from the devices.\n";
+ print " clear Remove all registrations from the devices.\n";
print "\n";
print "Options:\n";
print "\n";
+ print " -k, --key=VALUE Key to use with current action.\n";
print " -d, --devices=LIST Devices used for the current action.\n";
print " -h, --help Display this help and exit.\n";
print " -v, --verbose Verbose mode.\n";
@@ -622,10 +645,12 @@ if (defined $options{'t'}) {
}
}
-if ($options{'k'} =~ /^[[:xdigit:]]+$/) {
- $node_key = lc ($options{'k'});
-} else {
- print_usage ();
+if ($options{'o'} !~ /^clear$/i) {
+ if ($options{'k'} =~ /^[[:xdigit:]]+$/) {
+ $node_key = lc ($options{'k'});
+ } else {
+ print_usage ();
+ }
}
for ($options{'o'}) {
@@ -637,6 +662,10 @@ for ($options{'o'}) {
do_key_read (\$host_key);
last;
};
+ ($_ =~ /^clear/i) && do {
+ do_key_read (\$host_key);
+ last;
+ };
print_usage ();
}
@@ -690,5 +719,15 @@ for ($options{'o'}) {
print "\n" if (!defined $options{'v'});
last;
};
+ ($_ =~ /^clear$/i) && do {
+ print "\n" if (!defined $options{'v'});
+ foreach (@devices) {
+ $results{$_}[0] = do_action_clear ($devices_name{$_}, $host_key);
+ $results{$_}[1] = do_verify_clear ($devices_name{$_}, $host_key);
+ print_results ($_);
+ }
+ print "\n" if (!defined $options{'v'});
+ last;
+ };
print_usage ();
}
13 years, 5 months