src/direct.c | 13 +++++++++++--
src/main.c | 2 +-
src/sanlock.8 | 2 +-
3 files changed, 13 insertions(+), 4 deletions(-)
New commits:
commit 8a7764f0103da41f317ff8257a9bb0548607ad46
Author: Nir Soffer <nirsof(a)gmail.com>
Date: Sat Oct 15 05:09:09 2016 +0300
Add size option to sanlock direct dump
Previously "sanlock direct dump" would stop when the first unused space
was found in a lockspace or resource area. For example:
$ sanlock direct init -r lockspace:A:leases:0
$ sanlock direct init -r lockspace:B:leases:3145728
$ sanlock direct dump leases
offset lockspace resource timestamp own gen lver
00000000 lockspace A 0000000000 0000 0000 0
This patch adds optional size option. If specified, dump will search up
to size bytes:
$ sanlock direct dump leases:0:10485760
offset lockspace resource timestamp own gen lver
00000000 lockspace A 0000000000 0000 0000 0
03145728 lockspace B 0000000000 0000 0000 0
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
diff --git a/src/direct.c b/src/direct.c
index 8fd6e10..09ba417 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -407,16 +407,23 @@ int direct_dump(struct task *task, char *dump_path, int force_mode)
char sname[NAME_ID_SIZE+1];
char rname[NAME_ID_SIZE+1];
uint64_t sector_nr;
+ uint64_t dump_size = 0;
+ uint64_t end_sector_nr;
int sector_count, datalen, align_size;
int i, rv, b;
memset(&sd, 0, sizeof(struct sync_disk));
+ /* /path[:<offset>[:<size>]] */
colon = strstr(dump_path, ":");
if (colon) {
off_str = colon + 1;
*colon = '\0';
sd.offset = atoll(off_str);
+
+ colon = strstr(off_str, ":");
+ if (colon)
+ dump_size = atoll(colon + 1);
}
strncpy(sd.path, dump_path, SANLK_PATH_LEN);
@@ -455,8 +462,9 @@ int direct_dump(struct task *task, char *dump_path, int force_mode)
printf("\n");
sector_nr = 0;
+ end_sector_nr = dump_size / sd.sector_size;
- while (1) {
+ while (end_sector_nr == 0 || sector_nr < end_sector_nr) {
memset(sname, 0, sizeof(rname));
memset(rname, 0, sizeof(rname));
memset(data, 0, sd.sector_size);
@@ -551,7 +559,8 @@ int direct_dump(struct task *task, char *dump_path, int force_mode)
printf("%04u %04llu SH\n", i+1, (unsigned long long)mb.generation);
}
} else {
- break;
+ if (end_sector_nr == 0)
+ break;
}
sector_nr += sector_count;
diff --git a/src/main.c b/src/main.c
index ebc1e06..83db458 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1851,7 +1851,7 @@ static void print_usage(void)
printf("sanlock direct <action> [-a 0|1] [-o 0|1]\n");
printf("sanlock direct init -s LOCKSPACE | -r RESOURCE\n");
printf("sanlock direct read_leader -s LOCKSPACE | -r RESOURCE\n");
- printf("sanlock direct dump <path>[:<offset>]\n");
+ printf("sanlock direct dump <path>[:<offset>[:<size>]]\n");
printf("\n");
printf("LOCKSPACE = <lockspace_name>:<host_id>:<path>:<offset>\n");
printf(" <lockspace_name> name of lockspace\n");
diff --git a/src/sanlock.8 b/src/sanlock.8
index 73e48ff..dad85a8 100644
--- a/src/sanlock.8
+++ b/src/sanlock.8
@@ -754,7 +754,7 @@ the single sector of a delta lease, or the first sector of a paxos lease.
./"
.BI "sanlock direct dump" " path" \
-\fR[\fP\fB:\fP\fIoffset\fP\fR]\fP
+\fR[\fP\fB:\fP\fIoffset\fP\fR[\fP\fB:\fP\fIsize\fP\fR]]\fP
Read disk sectors and print leader records for delta or paxos leases. Add
-f 1 to print the request record values for paxos leases, and host_ids set