2
* Copyright 2010-2011 Red Hat, Inc.
4
* This copyrighted material is made available to anyone wishing to use,
5
* modify, copy, or redistribute it subject to the terms and conditions
6
* of the GNU General Public License v2 or (at your option) any later version.
18
#include "sanlock_internal.h"
19
#include "sanlock_direct.h"
24
void log_level(uint32_t space_id GNUC_UNUSED, uint32_t token_id GNUC_UNUSED,
25
char *name GNUC_UNUSED,
26
int level GNUC_UNUSED, const char *fmt GNUC_UNUSED, ...);
28
void log_level(uint32_t space_id GNUC_UNUSED, uint32_t token_id GNUC_UNUSED,
29
char *name GNUC_UNUSED,
30
int level GNUC_UNUSED, const char *fmt GNUC_UNUSED, ...)
34
int lockspace_disk(char *space_name GNUC_UNUSED, struct sync_disk *disk GNUC_UNUSED);
36
int lockspace_disk(char *space_name GNUC_UNUSED, struct sync_disk *disk GNUC_UNUSED)
41
int host_info(char *space_name, uint64_t host_id, struct host_status *hs_out);
43
int host_info(char *space_name GNUC_UNUSED, uint64_t host_id GNUC_UNUSED, struct host_status *hs_out GNUC_UNUSED)
48
/* copied from host_id.c */
50
int test_id_bit(int host_id, char *bitmap);
52
int test_id_bit(int host_id, char *bitmap)
54
char *byte = bitmap + ((host_id - 1) / 8);
55
unsigned int bit = (host_id - 1) % 8;
60
return (*byte & mask);
63
int get_rand(int a, int b);
65
int get_rand(int a, int b)
67
return a + (int) (((float)(b - a + 1)) * random() / (RAND_MAX+1.0));
70
static void setup_task_lib(struct task *task, int use_aio, int io_timeout_sec)
72
memset(task, 0, sizeof(struct task));
74
io_timeout_sec = DEFAULT_IO_TIMEOUT;
75
setup_task_timeouts(task, io_timeout_sec);
76
setup_task_aio(task, use_aio, LIB_AIO_CB_SIZE);
77
sprintf(task->name, "%s", "lib");
81
int sanlock_direct_read_id(struct sanlk_lockspace *ls,
84
uint64_t *owner_generation,
91
setup_task_lib(&task, use_aio, io_timeout_sec);
93
rv = direct_read_id(&task, ls, timestamp, owner_id, owner_generation);
95
close_task_aio(&task);
100
int sanlock_direct_live_id(struct sanlk_lockspace *ls,
103
uint64_t *owner_generation,
111
setup_task_lib(&task, use_aio, io_timeout_sec);
113
rv = direct_live_id(&task, ls, timestamp, owner_id, owner_generation, live);
115
close_task_aio(&task);
120
int sanlock_direct_init(struct sanlk_lockspace *ls,
121
struct sanlk_resource *res,
122
int max_hosts, int num_hosts, int use_aio)
127
setup_task_lib(&task, use_aio, DEFAULT_IO_TIMEOUT);
129
rv = direct_init(&task, ls, res, max_hosts, num_hosts);
131
close_task_aio(&task);
136
int sanlock_direct_align(struct sanlk_disk *disk_in)
138
struct sync_disk disk;
141
memset(&disk, 0, sizeof(disk));
143
memcpy(disk.path, disk_in->path, SANLK_PATH_LEN);
145
rv = open_disk(&disk);
149
align_size = direct_align(&disk);