src/client_msg.h | 1
src/client_resource.c | 21 ++++++++++
src/direct.c | 10 ++--
src/direct_lib.c | 19 +++++++++
src/diskio.c | 100 ++++++++++++++++++++++++++++++++-----------------
src/diskio.h | 1
src/host_id.c | 12 +++--
src/main.c | 29 ++++++++++++++
src/paxos_lease.c | 36 +++++++++++++++++
src/sanlock_direct.h | 16 +++++++
src/sanlock_resource.h | 4 +
src/sanlock_rv.h | 1
tests/devcount.c | 55 ++++++++++++++++++++------
13 files changed, 246 insertions(+), 59 deletions(-)
New commits:
commit 053486def93b2bbc00104e6a457412dd242fb4ac
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jun 1 14:46:15 2011 -0500
sanlock: add checksum to dblocks
and verify dblock checksum before using the values
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index e9adcfb..25ddf37 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -34,6 +34,8 @@ struct request_record {
uint8_t force_mode;
};
+#define DBLOCK_CHECKSUM_LEN 48 /* ends before checksum field */
+
struct paxos_dblock {
uint64_t mbal;
uint64_t bal;
@@ -41,6 +43,7 @@ struct paxos_dblock {
uint64_t inp2; /* host_id generation */
uint64_t inp3; /* host_id's timestamp */
uint64_t lver;
+ uint32_t checksum;
};
static uint32_t roundup_power_of_two(uint32_t val)
@@ -201,6 +204,29 @@ static int read_request(struct task *task,
}
#endif
+static uint32_t dblock_checksum(struct paxos_dblock *pd)
+{
+ return crc32c((uint32_t)~1, (char *)pd, DBLOCK_CHECKSUM_LEN);
+}
+
+static int verify_dblock(struct token *token, struct paxos_dblock *pd)
+{
+ uint32_t sum;
+
+ if (!pd->checksum && !pd->mbal && !pd->bal &&
!pd->inp && !pd->lver)
+ return SANLK_OK;
+
+ sum = dblock_checksum(pd);
+
+ if (pd->checksum != sum) {
+ log_errot(token, "verify_dblock wrong checksum %x %x",
+ pd->checksum, sum);
+ return SANLK_DBLOCK_CHECKSUM;
+ }
+
+ return SANLK_OK;
+}
+
/*
* It's possible that we pick a bk_max from another host which has our own
* inp values in it, and we can end up commiting our own inp values, copied
@@ -301,6 +327,7 @@ static int run_ballot(struct task *task, struct token *token, int
num_hosts,
memset(&dblock, 0, sizeof(struct paxos_dblock));
dblock.mbal = our_mbal;
dblock.lver = next_lver;
+ dblock.checksum = dblock_checksum(&dblock);
memset(&bk_max, 0, sizeof(struct paxos_dblock));
@@ -340,6 +367,10 @@ static int run_ballot(struct task *task, struct token *token, int
num_hosts,
for (q = 0; q < num_hosts; q++) {
bk = (struct paxos_dblock *)(iobuf[d] + ((2 + q)*sector_size));
+ rv = verify_dblock(token, bk);
+ if (rv < 0)
+ continue;
+
if (bk->lver < dblock.lver)
continue;
@@ -417,6 +448,7 @@ static int run_ballot(struct task *task, struct token *token, int
num_hosts,
dblock.inp3 = time(NULL);
}
dblock.bal = dblock.mbal;
+ dblock.checksum = dblock_checksum(&dblock);
if (bk_max.inp) {
/* not a problem, but interesting to see, so use log_error */
@@ -480,6 +512,10 @@ static int run_ballot(struct task *task, struct token *token, int
num_hosts,
for (q = 0; q < num_hosts; q++) {
bk = (struct paxos_dblock *)(iobuf[d] + ((2 + q)*sector_size));
+ rv = verify_dblock(token, bk);
+ if (rv < 0)
+ continue;
+
if (bk->lver < dblock.lver)
continue;
diff --git a/src/sanlock_rv.h b/src/sanlock_rv.h
index c027828..6b0510f 100644
--- a/src/sanlock_rv.h
+++ b/src/sanlock_rv.h
@@ -20,6 +20,7 @@
#define SANLK_DBLOCK_WRITE -211
#define SANLK_DBLOCK_LVER -212
#define SANLK_DBLOCK_MBAL -213
+#define SANLK_DBLOCK_CHECKSUM -214
/* verify_leader, leader_read, leader_write (paxos or delta) */
commit 74fdc2def01fa3b805b158d5f53b73f3edd439f4
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jun 1 13:35:38 2011 -0500
sanlock: add sanlock_direct_sector_size api
gets and returns the sector size (i.e. 512, 4096)
that sanlock would use for a given a path (disk or file)
diff --git a/src/direct.c b/src/direct.c
index 8823355..594285f 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -202,8 +202,8 @@ static int do_delta_action(int action,
memcpy(&sd, &ls->host_id_disk, sizeof(struct sanlk_disk));
sd.fd = -1;
- rv = open_disks(&sd, 1);
- if (rv != 1)
+ rv = open_disk(&sd);
+ if (rv < 0)
return -ENODEV;
switch (action) {
@@ -417,8 +417,8 @@ int direct_dump(struct task *task, char *dump_path)
struct sync_disk sd;
char sname[NAME_ID_SIZE+1];
char rname[NAME_ID_SIZE+1];
- int num_opened, rv;
uint64_t sector_nr;
+ int rv;
memset(&sd, 0, sizeof(struct sync_disk));
@@ -432,8 +432,8 @@ int direct_dump(struct task *task, char *dump_path)
strncpy(sd.path, dump_path, SANLK_PATH_LEN);
sd.fd = -1;
- num_opened = open_disks(&sd, 1);
- if (num_opened != 1)
+ rv = open_disk(&sd);
+ if (rv < 0)
return -ENODEV;
data = malloc(sd.sector_size);
diff --git a/src/direct_lib.c b/src/direct_lib.c
index 3f2bac1..6ccd339 100644
--- a/src/direct_lib.c
+++ b/src/direct_lib.c
@@ -16,6 +16,7 @@
#include "sanlock_internal.h"
#include "sanlock_direct.h"
+#include "diskio.h"
#include "direct.h"
#include "task.h"
@@ -103,3 +104,21 @@ int sanlock_direct_init(struct sanlk_lockspace *ls,
return rv;
}
+int sanlock_direct_sector_size(struct sanlk_disk *disk_in)
+{
+ struct sync_disk disk;
+ int rv;
+
+ memset(&disk, 0, sizeof(disk));
+
+ memcpy(disk.path, disk_in->path, SANLK_PATH_LEN);
+
+ rv = open_disk(&disk);
+ if (rv < 0)
+ return rv;
+
+ close(disk.fd);
+
+ return disk.sector_size;
+}
+
diff --git a/src/diskio.c b/src/diskio.c
index ccf7a4d..843559b 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -73,15 +73,18 @@ void close_disks(struct sync_disk *disks, int num_disks)
int d;
for (d = 0; d < num_disks; d++) {
- if (disks[d].fd == -1) {
- log_error("close fd -1");
+ if (disks[d].fd == -1)
continue;
- }
close(disks[d].fd);
disks[d].fd = -1;
}
}
+/*
+ * set fd in each disk
+ * returns number of opened disks
+ */
+
int open_disks_fd(struct sync_disk *disks, int num_disks)
{
struct sync_disk *disk;
@@ -93,7 +96,7 @@ int open_disks_fd(struct sync_disk *disks, int num_disks)
if (disk->fd != -1) {
log_error("open fd %d exists %s", disk->fd, disk->path);
- return 0;
+ goto fail;
}
fd = open(disk->path, O_RDWR | O_DIRECT | O_SYNC, 0);
@@ -106,60 +109,90 @@ int open_disks_fd(struct sync_disk *disks, int num_disks)
num_opens++;
}
return num_opens;
+
+ fail:
+ close_disks(disks, num_disks);
+ return 0;
}
-/* return number of opened disks */
+/*
+ * set fd and sector_size
+ * returns 0 for success or -EXXX
+ */
+
+int open_disk(struct sync_disk *disk)
+{
+ struct stat st;
+ int fd, rv;
+
+ fd = open(disk->path, O_RDWR | O_DIRECT | O_SYNC, 0);
+ if (fd < 0) {
+ rv = -errno;
+ log_error("open error %d %s", rv, disk->path);
+ goto fail;
+ }
+
+ if (fstat(fd, &st) < 0) {
+ rv = -errno;
+ log_error("fstat error %d %s", rv, disk->path);
+ close(fd);
+ goto fail;
+ }
+
+ if (S_ISREG(st.st_mode)) {
+ disk->sector_size = 512;
+ } else {
+ rv = set_disk_properties(disk);
+ if (rv < 0) {
+ close(fd);
+ goto fail;
+ }
+ }
+
+ disk->fd = fd;
+ return 0;
+
+ fail:
+ if (rv >= 0)
+ rv = -1;
+ return rv;
+}
+
+/*
+ * set fd and sector_size in each disk
+ * verify all sector_size's match
+ * verify sector_size is ok for previously set offset
+ * returns number of opened disks
+ */
int open_disks(struct sync_disk *disks, int num_disks)
{
struct sync_disk *disk;
int num_opens = 0;
- int d, fd, rv;
+ int d, rv;
uint32_t ss = 0;
- uint64_t orig_offset;
- struct stat st;
for (d = 0; d < num_disks; d++) {
disk = &disks[d];
if (disk->fd != -1) {
log_error("open fd %d exists %s", disk->fd, disk->path);
- return 0;
- }
-
- fd = open(disk->path, O_RDWR | O_DIRECT | O_SYNC, 0);
- if (fd < 0) {
- log_error("open error %d %s", fd, disk->path);
- continue;
- }
-
- if (fstat(fd, &st) < 0) {
- log_error("fstat error %d %s", fd, disk->path);
- close(fd);
- continue;
+ rv = -ENOTEMPTY;
+ goto fail;
}
- if (S_ISREG(st.st_mode)) {
- disk->sector_size = 512;
- } else {
- rv = set_disk_properties(disk);
- if (rv < 0) {
- close(fd);
- continue;
- }
- }
+ rv = open_disk(disk);
+ if (rv < 0)
+ goto fail;
if (!ss) {
ss = disk->sector_size;
} else if (ss != disk->sector_size) {
log_error("inconsistent sector sizes %u %u %s",
ss, disk->sector_size, disk->path);
- close(fd);
goto fail;
}
- orig_offset = disk->offset;
-
if (disk->offset % disk->sector_size) {
log_error("invalid offset %llu sector size %u %s",
(unsigned long long)disk->offset,
@@ -167,7 +200,6 @@ int open_disks(struct sync_disk *disks, int num_disks)
goto fail;
}
- disk->fd = fd;
num_opens++;
}
return num_opens;
diff --git a/src/diskio.h b/src/diskio.h
index c6b2762..dd32958 100644
--- a/src/diskio.h
+++ b/src/diskio.h
@@ -10,6 +10,7 @@
#define __DISKIO_H__
void close_disks(struct sync_disk *disks, int num_disks);
+int open_disk(struct sync_disk *disks);
int open_disks(struct sync_disk *disks, int num_disks);
int open_disks_fd(struct sync_disk *disks, int num_disks);
diff --git a/src/host_id.c b/src/host_id.c
index 0318536..a523242 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -160,8 +160,9 @@ static void *host_id_thread(void *arg_in)
struct leader_record leader;
uint64_t our_host_id, our_host_id_generation;
time_t last_attempt, last_success;
- int rv, result, delta_length, gap, opened;
+ int rv, result, delta_length, gap;
int delta_result = 0;
+ int opened = 0;
int stop = 0;
sp = (struct space *)arg_in;
@@ -174,12 +175,13 @@ static void *host_id_thread(void *arg_in)
last_attempt = time(NULL);
- opened = open_disks(&sp->host_id_disk, 1);
- if (opened != 1) {
- log_erros(sp, "open_disk failed %s", sp->host_id_disk.path);
+ rv = open_disk(&sp->host_id_disk);
+ if (rv < 0) {
+ log_erros(sp, "open_disk %s error %d", sp->host_id_disk.path, rv);
result = -ENODEV;
goto set_status;
}
+ opened = 1;
result = delta_lease_acquire(&task, sp, &sp->host_id_disk, space_name,
our_host_id, our_host_id, &leader);
@@ -297,7 +299,7 @@ static void *host_id_thread(void *arg_in)
our_host_id, &leader, &leader);
if (opened)
- close_disks(&sp->host_id_disk, 1);
+ close(sp->host_id_disk.fd);
close_task_aio(&task);
return NULL;
diff --git a/src/sanlock_direct.h b/src/sanlock_direct.h
index 1bd9c54..435e1bd 100644
--- a/src/sanlock_direct.h
+++ b/src/sanlock_direct.h
@@ -9,6 +9,10 @@
#ifndef __SANLOCK_DIRECT_H__
#define __SANLOCK_DIRECT_H__
+/*
+ * Use io_timeout_sec = 0 for default value
+ */
+
int sanlock_direct_read_id(struct sanlk_lockspace *ls,
uint64_t *timestamp,
uint64_t *owner_id,
@@ -24,10 +28,20 @@ int sanlock_direct_live_id(struct sanlk_lockspace *ls,
int use_aio,
int io_timeout_sec);
-/* Use max_hosts = 0 for default max_hosts value */
+/*
+ * Use max_hosts = 0 for default max_hosts value
+ *
+ * Provide either lockspace or resource, not both
+ */
int sanlock_direct_init(struct sanlk_lockspace *ls,
struct sanlk_resource *res,
int max_hosts, int num_hosts, int use_aio);
+/*
+ * Returns sector size in bytes, -1 on error
+ */
+
+int sanlock_direct_sector_size(struct sanlk_disk *disk);
+
#endif
diff --git a/tests/devcount.c b/tests/devcount.c
index 04a35c4..817927c 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -21,6 +21,9 @@
#include "sanlock_resource.h"
#include "sanlock_direct.h"
+#define ONEMB 1048576
+#define LEASE_SIZE ONEMB
+
FILE *turn_file;
char count_path[PATH_MAX];
@@ -513,7 +516,7 @@ static int do_relock(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -697,7 +700,7 @@ static int do_lock(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -781,7 +784,7 @@ static int do_wrap(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -1032,7 +1035,7 @@ static int do_migrate(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -1215,7 +1218,7 @@ int do_expire(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -1342,7 +1345,7 @@ int do_expire(int argc, char *argv[])
/*
* devcount init <lock_disk> <count_disk>
* sanlock direct init -n 8 -s devcount:0:<lock_disk>:0
- * sanlock direct init -n 8 -r
devcount:resource<count_disk>:<lock_disk>:1024000
+ * sanlock direct init -n 8 -r
devcount:resource<count_disk>:<lock_disk>:LEASE_SIZE
* dd if=/dev/zero of=<count_disk> bs=512 count=24
*/
@@ -1351,10 +1354,11 @@ int do_expire(int argc, char *argv[])
int do_init(int argc, char *argv[])
{
char resbuf[sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk)];
+ struct sanlk_disk disk;
struct sanlk_resource *res;
struct sanlk_lockspace ls;
char command[4096];
- int rv;
+ int rv, ss;
if (argc < 4)
return -1;
@@ -1374,21 +1378,37 @@ int do_init(int argc, char *argv[])
system(command);
- /* initialize first resource lease area at offset 1024000 */
+ /* initialize first resource lease area at offset LEASE_SIZE */
memset(command, 0, sizeof(command));
snprintf(command, sizeof(command),
- "sanlock direct init -n %d -r devcount:resource%s:%s:1024000",
+ "sanlock direct init -n %d -r devcount:resource%s:%s:%d",
INIT_NUM_HOSTS,
argv[3],
- argv[2]);
+ argv[2],
+ LEASE_SIZE);
printf("%s\n", command);
system(command);
#else
+ memset(&disk, 0, sizeof(disk));
+ strcpy(disk.path, argv[2]);
+
+ ss = sanlock_direct_sector_size(&disk);
+ if (ss < 0) {
+ printf("sanlock_direct_sector_size %s error %d\n",
+ disk.path, ss);
+ return -1;
+ }
+
+ if (ss != 512) {
+ printf("unsupported sector size %d\n", ss);
+ return -1;
+ }
+
memset(&ls, 0, sizeof(ls));
strcpy(ls.name, "devcount");
strcpy(ls.host_id_disk.path, argv[2]);
@@ -1405,7 +1425,7 @@ int do_init(int argc, char *argv[])
sprintf(res->name, "resource%s", argv[3]);
res->num_disks = 1;
strcpy(res->disks[0].path, argv[2]);
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
rv = sanlock_direct_init(NULL, res, 0, INIT_NUM_HOSTS, 0);
if (rv < 0) {
@@ -1459,15 +1479,15 @@ int main(int argc, char *argv[])
out:
/*
* sanlock direct init -n 8 -s devcount:0:/dev/bull/leases:0
- * sanlock direct init -n 8 -r
devcount:resource/dev/bull/count:/dev/bull/leases:1024000
+ * sanlock direct init -n 8 -r
devcount:resource/dev/bull/count:/dev/bull/leases:LEASE_SIZE
*
* host_id leases exists at <lock_disk> offset 0
- * first resource lease exists at <lock_disk> offset 1024000
+ * first resource lease exists at <lock_disk> offset LEASE_SIZE
*/
printf("devcount init <lock_disk> <count_disk>\n");
printf(" sanlock direct init -n 8 -s devcount:0:<lock_disk>:0\n");
- printf(" sanlock direct init -n 8 -r
devcount:resource<count_disk>:<lock_disk>:1024000\n");
+ printf(" sanlock direct init -n 8 -r
devcount:resource<count_disk>:<lock_disk>:LEASE_SIZE\n");
printf(" dd if=/dev/zero of=<count_disk> bs=512 count=24\n");
printf("\n");
printf("devcount rw <count_disk> <sec1> <sec2>
<hostid>\n");
commit 09583fc87bbe7d5158da5416f318351eef8be180
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jun 1 11:09:54 2011 -0500
sanlock: add sanlock_restrict api
can be called on a connection to prevent sanlock from
accepting any further commands on that connection (but
it will still watch for the connection close)
diff --git a/src/client_msg.h b/src/client_msg.h
index 828acf5..dcb943a 100644
--- a/src/client_msg.h
+++ b/src/client_msg.h
@@ -21,6 +21,7 @@ enum {
SM_CMD_ACQUIRE = 7,
SM_CMD_RELEASE = 8,
SM_CMD_INQUIRE = 9,
+ SM_CMD_RESTRICT = 10,
};
#define SANLK_STATE_MAXSTR 4096
diff --git a/src/client_resource.c b/src/client_resource.c
index 5a807e1..ef334b9 100644
--- a/src/client_resource.c
+++ b/src/client_resource.c
@@ -48,6 +48,27 @@ int sanlock_register(void)
return sock;
}
+int sanlock_restrict(int sock, uint32_t flags)
+{
+ struct sm_header h;
+ int rv;
+
+ rv = send_header(sock, SM_CMD_RESTRICT, flags, 0, 0, -1);
+ if (rv < 0)
+ return rv;
+
+ memset(&h, 0, sizeof(h));
+
+ rv = recv(sock, &h, sizeof(h), MSG_WAITALL);
+ if (rv != sizeof(h)) {
+ rv = -1;
+ goto out;
+ }
+ rv = (int)h.data;
+ out:
+ return rv;
+}
+
int sanlock_acquire(int sock, int pid, uint32_t flags, int res_count,
struct sanlk_resource *res_args[],
struct sanlk_options *opt_in)
diff --git a/src/main.c b/src/main.c
index cc6d405..13b32a4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -62,6 +62,7 @@ struct client {
int suspend;
int need_free;
int killing;
+ uint32_t cmd_flags;
char owner_name[SANLK_NAME_LEN+1];
pthread_mutex_t mutex;
void *workfn;
@@ -180,6 +181,7 @@ static void _client_free(int ci)
cl->suspend = 0;
cl->need_free = 0;
cl->killing = 0;
+ cl->cmd_flags = 0;
memset(cl->owner_name, 0, sizeof(cl->owner_name));
cl->workfn = NULL;
cl->deadfn = NULL;
@@ -1750,6 +1752,22 @@ static void cmd_log_dump(int fd, struct sm_header *h_recv)
write_log_dump(fd);
}
+static void cmd_restrict(int ci, int fd, struct sm_header *h_recv)
+{
+ struct sm_header h;
+
+ log_debug("cmd_restrict ci %d fd %d pid %d flags %x",
+ ci, fd, client[ci].pid, h_recv->cmd_flags);
+
+ client[ci].cmd_flags = h_recv->cmd_flags;
+
+ memcpy(&h, h_recv, sizeof(struct sm_header));
+ h.length = sizeof(h);
+ h.data = 0;
+ h.data2 = 0;
+ send(fd, &h, sizeof(h), MSG_NOSIGNAL);
+}
+
static void process_cmd_thread_lockspace(int ci_in, struct sm_header *h_recv)
{
struct cmd_args *ca;
@@ -1936,6 +1954,11 @@ static void process_cmd_daemon(int ci, struct sm_header *h_recv)
client[ci].deadfn = client_pid_dead;
auto_close = 0;
break;
+ case SM_CMD_RESTRICT:
+ strcpy(client[ci].owner_name, "restrict");
+ cmd_restrict(ci, fd, h_recv);
+ auto_close = 0;
+ break;
case SM_CMD_SHUTDOWN:
strcpy(client[ci].owner_name, "shutdown");
external_shutdown = 1;
@@ -1978,11 +2001,17 @@ static void process_connection(int ci)
ci, rv, h.magic, SM_MAGIC);
goto dead;
}
+ if (client[ci].cmd_flags & SANLK_RESTRICT_ALL) {
+ log_error("ci %d fd %d pid %d cmd %d restrict all",
+ ci, client[ci].fd, client[ci].pid, h.cmd);
+ goto dead;
+ }
client[ci].cmd_last = h.cmd;
switch (h.cmd) {
case SM_CMD_REGISTER:
+ case SM_CMD_RESTRICT:
case SM_CMD_SHUTDOWN:
case SM_CMD_STATUS:
case SM_CMD_LOG_DUMP:
diff --git a/src/sanlock_resource.h b/src/sanlock_resource.h
index f41f3e3..11f9ace 100644
--- a/src/sanlock_resource.h
+++ b/src/sanlock_resource.h
@@ -21,6 +21,10 @@
int sanlock_register(void);
+#define SANLK_RESTRICT_ALL 0x1
+
+int sanlock_restrict(int sock, uint32_t flags);
+
int sanlock_acquire(int sock, int pid, uint32_t flags, int res_count,
struct sanlk_resource *res_args[],
struct sanlk_options *opt_in);
diff --git a/tests/devcount.c b/tests/devcount.c
index f7d049e..04a35c4 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -558,6 +558,13 @@ static int do_relock(int argc, char *argv[])
log_debug("%s c %d sanlock_acquire done",
count_path, child_pid);
+ rv = sanlock_restrict(sock, SANLK_RESTRICT_ALL);
+ if (rv < 0) {
+ log_error("%s c %d sanlock_restrict error %d",
+ count_path, child_pid, sock);
+ exit(-1);
+ }
+
/* make child's stderr go to parent c2p[0] */
close(2);
dup(c2p[1]);