From 19762321b47db34de9b239f2cfbcc5133cf4e1d4 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Oct 08 2012 16:27:02 +0000 Subject: fence_sanlock: variable alignment - make lease size depend on disk sector size - clarify fence_sanlock read_leader behavior Signed-off-by: David Teigland --- diff --git a/fence_sanlock/fence_sanlock.in b/fence_sanlock/fence_sanlock.in index a6f9178..f43acc2 100755 --- a/fence_sanlock/fence_sanlock.in +++ b/fence_sanlock/fence_sanlock.in @@ -165,35 +165,24 @@ EOF return 0 } -get_leader_info() { +read_leader() { + # verify storage has been initialized + leader=$(sanlock direct read_leader -r fence:h$host_id:$path:$offset 2>&1) [ "$?" != 0 ] && { - echo "Unable to read $path" + echo "Error: unable to read $path" return 1 } - timestamp="$(echo "$leader" | grep ^timestamp | awk '{print $NF}')" - - [ -z "$timestamp" ] && { - echo "Unable to determine timestamp" - return 1 - } - - return 0 -} - -verify_path() { - # verify storage has been initialized - - get_leader_info || return 1 - magic="$(echo "$leader" | grep magic | awk '{print $NF}')" + [ -z "$magic" ] && { - echo "Unable to determine $path sanlock magic" + echo "Error: no sanlock magic number at $path:$offset" return 1 } + [ "$magic" != "0x6152010" ] && { - echo "Error: $path magic $magic does not match sanlock magic 0x6152010" + echo "Error: invalid sanlock magic number $magic at $path:$offset" return 1 } @@ -201,7 +190,7 @@ verify_path() { } action_on() { - verify_path || return 1 + read_leader || return 1 [ -z "$(pidof fence_sanlockd)" ] && { daemonerr="$(fence_sanlockd -p $path -i $host_id 2>&1)" @@ -245,11 +234,12 @@ action_on() { } action_off() { - verify_path || return 1 + read_leader || return 1 owner_id="$(echo "$leader" | grep owner_id | awk '{print $NF}')" owner_gen="$(echo "$leader" | grep owner_gen | awk '{print $NF}')" ver="$(echo "$leader" | grep lver | awk '{print $NF}')" + timestamp="$(echo "$leader" | grep ^timestamp | awk '{print $NF}')" # lease is released, so host is off [ "$timestamp" = 0 ] && { @@ -308,7 +298,7 @@ action_off() { # reacquired cleanly by the victim host (same host_id, new # generation), we can quit with success - get_leader_info || return 1 + read_leader || return 1 tmp_id="$(echo "$leader" | grep owner_id | awk '{print $NF}')" tmp_gen="$(echo "$leader" | grep owner_gen | awk '{print $NF}')" @@ -328,7 +318,9 @@ action_off() { } action_status() { - verify_path || return 1 + read_leader || return 1 + + timestamp="$(echo "$leader" | grep ^timestamp | awk '{print $NF}')" # lease is released, so host is "off" [ "$timestamp" = 0 ] && { @@ -351,7 +343,7 @@ sanlock_init() { echo -n "Initializing $max_hosts sanlock host leases on $path: " for host_id in $(seq 1 $max_hosts); do - offset=$((host_id * 1048576)) + offset=$((host_id * $align)) sanlock direct init -r fence:h$host_id:$path:$offset \ > /dev/null 2>/dev/null || \ { echo "error $? for host $host_id" && return 1; } @@ -365,16 +357,22 @@ sanlock_init() { # check actions and options compatibility # all actions beside metadata needs storage + [ "$action" != "metadata" ] && { [ -z "$path" ] && { echo "storage path argument required" exit 1 } + # all actions beside sanlock_init needs host_id [ "$action" != "sanlock_init" ] && [ -z "$host_id" ] && { echo "host_id argument required" exit 1 } + + # FIXME: add direct align command to sanlock + # align="&(sanlock direct align $path)" + align=1048576 } # verify host_id parameter @@ -383,7 +381,7 @@ sanlock_init() { echo "host_id must be between 1 and $max_hosts" exit 1 fi - offset=$((host_id * 1048576)) + offset=$((host_id * $align)) } case "$action" in diff --git a/fence_sanlock/fence_sanlockd.c b/fence_sanlock/fence_sanlockd.c index ea7ffdc..e491ded 100644 --- a/fence_sanlock/fence_sanlockd.c +++ b/fence_sanlock/fence_sanlockd.c @@ -28,11 +28,11 @@ #include "sanlock.h" #include "sanlock_admin.h" #include "sanlock_resource.h" +#include "sanlock_direct.h" #include "wdmd.h" /* * TODO: - * handle 4k disk blocks using sanlock_align() * variable i/o timeouts? * * shutdown: how/when does SIGTERM happen? @@ -67,6 +67,7 @@ static int our_host_id; static char path[PATH_MAX]; static struct sanlk_lockspace ls; static struct sanlk_resource *r; +static struct sanlk_disk disk; static char rdbuf[sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk)]; static char lockfile_path[PATH_MAX]; @@ -280,6 +281,7 @@ int main(int argc, char *argv[]) int cont = 1; int optchar; int sock, con, rv, i; + int align; while (cont) { optchar = getopt(argc, argv, "Dp:i:hV"); @@ -369,6 +371,15 @@ int main(int argc, char *argv[]) goto out_refcount; } + memset(&disk, 0, sizeof(disk)); + sprintf(disk.path, "%s", path); + + align = sanlock_direct_align(&disk); + if (align < 0) { + log_error("direct_align error %d", align); + goto out_refcount; + } + memset(&ls, 0, sizeof(ls)); sprintf(ls.host_id_disk.path, "%s", path); strcpy(ls.name, "fence"); @@ -389,7 +400,7 @@ int main(int argc, char *argv[]) strcpy(r->lockspace_name, "fence"); sprintf(r->name, "h%d", our_host_id); sprintf(r->disks[0].path, "%s", path); - r->disks[0].offset = our_host_id * 1048576; + r->disks[0].offset = our_host_id * align; r->num_disks = 1; log_debug("acquire begin");