~ubuntu-branches/ubuntu/trusty/dlm/trusty

« back to all changes in this revision

Viewing changes to dlm_controld/lib.c

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-07-23 15:50:10 UTC
  • Revision ID: package-import@ubuntu.com-20130723155010-khpwf6vc04wjho2a
Tags: upstream-4.0.1
ImportĀ upstreamĀ versionĀ 4.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2004-2012 Red Hat, Inc.
 
3
 *
 
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.
 
7
 */
 
8
 
 
9
#include <stdio.h>
 
10
#include <stdlib.h>
 
11
#include <unistd.h>
 
12
#include <stdint.h>
 
13
#include <errno.h>
 
14
#include <time.h>
 
15
#include <sys/types.h>
 
16
#include <sys/socket.h>
 
17
#include <sys/un.h>
 
18
 
 
19
#include <linux/dlmconstants.h>
 
20
#include "dlm_controld.h"
 
21
#include "libdlmcontrol.h"
 
22
 
 
23
static int do_read(int fd, void *buf, size_t count)
 
24
{
 
25
        int rv, off = 0;
 
26
 
 
27
        while (off < count) {
 
28
                rv = read(fd, (char *)buf + off, count - off);
 
29
                if (rv == 0)
 
30
                        return -1;
 
31
                if (rv == -1 && errno == EINTR)
 
32
                        continue;
 
33
                if (rv == -1)
 
34
                        return -1;
 
35
                off += rv;
 
36
        }
 
37
        return 0;
 
38
}
 
39
 
 
40
static int do_write(int fd, void *buf, size_t count)
 
41
{
 
42
        int rv, off = 0;
 
43
 
 
44
 retry:
 
45
        rv = write(fd, (char *)buf + off, count);
 
46
        if (rv == -1 && errno == EINTR)
 
47
                goto retry;
 
48
        if (rv < 0) {
 
49
                return rv;
 
50
        }
 
51
 
 
52
        if (rv != count) {
 
53
                count -= rv;
 
54
                off += rv;
 
55
                goto retry;
 
56
        }
 
57
        return 0;
 
58
}
 
59
 
 
60
static int do_connect(const char *sock_path)
 
61
{
 
62
        struct sockaddr_un sun;
 
63
        socklen_t addrlen;
 
64
        int rv, fd;
 
65
 
 
66
        fd = socket(PF_UNIX, SOCK_STREAM, 0);
 
67
        if (fd < 0)
 
68
                goto out;
 
69
 
 
70
        memset(&sun, 0, sizeof(sun));
 
71
        sun.sun_family = AF_UNIX;
 
72
        strcpy(&sun.sun_path[1], sock_path);
 
73
        addrlen = sizeof(sa_family_t) + strlen(sun.sun_path+1) + 1;
 
74
 
 
75
        rv = connect(fd, (struct sockaddr *) &sun, addrlen);
 
76
        if (rv < 0) {
 
77
                close(fd);
 
78
                fd = rv;
 
79
        }
 
80
 out:
 
81
        return fd;
 
82
}
 
83
 
 
84
static void init_header(struct dlmc_header *h, int cmd, char *name,
 
85
                        int extra_len)
 
86
{
 
87
        memset(h, 0, sizeof(struct dlmc_header));
 
88
 
 
89
        h->magic = DLMC_MAGIC;
 
90
        h->version = DLMC_VERSION;
 
91
        h->len = sizeof(struct dlmc_header) + extra_len;
 
92
        h->command = cmd;
 
93
 
 
94
        if (name)
 
95
                strncpy(h->name, name, DLM_LOCKSPACE_LEN);
 
96
}
 
97
 
 
98
static char copy_buf[DLMC_DUMP_SIZE];
 
99
 
 
100
static int do_dump(int cmd, char *name, char *buf)
 
101
{
 
102
        struct dlmc_header h;
 
103
        int fd, rv, len;
 
104
 
 
105
        memset(copy_buf, 0, DLMC_DUMP_SIZE);
 
106
 
 
107
        init_header(&h, cmd, name, 0);
 
108
 
 
109
        fd = do_connect(DLMC_QUERY_SOCK_PATH);
 
110
        if (fd < 0) {
 
111
                rv = fd;
 
112
                goto out;
 
113
        }
 
114
 
 
115
        rv = do_write(fd, &h, sizeof(h));
 
116
        if (rv < 0)
 
117
                goto out_close;
 
118
 
 
119
        memset(&h, 0, sizeof(h));
 
120
 
 
121
        rv = do_read(fd, &h, sizeof(h));
 
122
        if (rv < 0)
 
123
                goto out_close;
 
124
 
 
125
        len = h.len - sizeof(h);
 
126
 
 
127
        if (len <= 0 || len > DLMC_DUMP_SIZE)
 
128
                goto out_close;
 
129
 
 
130
        rv = do_read(fd, copy_buf, len);
 
131
        if (rv < 0)
 
132
                goto out_close;
 
133
 
 
134
        memcpy(buf, copy_buf, len);
 
135
 out_close:
 
136
        close(fd);
 
137
 out:
 
138
        return rv;
 
139
}
 
140
 
 
141
int dlmc_dump_debug(char *buf)
 
142
{
 
143
        return do_dump(DLMC_CMD_DUMP_DEBUG, NULL, buf);
 
144
}
 
145
 
 
146
int dlmc_dump_config(char *buf)
 
147
{
 
148
        return do_dump(DLMC_CMD_DUMP_CONFIG, NULL, buf);
 
149
}
 
150
 
 
151
int dlmc_dump_log_plock(char *buf)
 
152
{
 
153
        return do_dump(DLMC_CMD_DUMP_LOG_PLOCK, NULL, buf);
 
154
}
 
155
 
 
156
int dlmc_dump_plocks(char *name, char *buf)
 
157
{
 
158
        return do_dump(DLMC_CMD_DUMP_PLOCKS, name, buf);
 
159
}
 
160
 
 
161
static int nodeid_compare(const void *va, const void *vb)
 
162
{
 
163
        const int *a = va;
 
164
        const int *b = vb;
 
165
 
 
166
        return *a - *b;
 
167
}
 
168
 
 
169
static void print_str(char *str, int len)
 
170
{
 
171
        char *p;
 
172
        int i;
 
173
 
 
174
        p = &str[0];
 
175
        for (i = 0; i < len-1; i++) {
 
176
                if (str[i] == ' ') {
 
177
                        str[i] = '\0';
 
178
                        printf("    %s\n", p);
 
179
                        p = &str[i+1];
 
180
                }
 
181
        }
 
182
 
 
183
        if (p)
 
184
                printf("    %s\n", p);
 
185
}
 
186
 
 
187
static unsigned int kv(char *str, const char *k)
 
188
{
 
189
        char valstr[64];
 
190
        char *p;
 
191
        int i;
 
192
 
 
193
        p = strstr(str, k);
 
194
        if (!p)
 
195
                return 0;
 
196
 
 
197
        p = strstr(p, "=") + 1;
 
198
        if (!p)
 
199
                return 0;
 
200
 
 
201
        memset(valstr, 0, 64);
 
202
 
 
203
        for (i = 0; i < 64; i++) {
 
204
                if (*p == ' ')
 
205
                        break;
 
206
                if (*p == '\0')
 
207
                        break;
 
208
                if (*p == '\n')
 
209
                        break;
 
210
                valstr[i] = *p;
 
211
                p++;
 
212
        }
 
213
 
 
214
        return (unsigned int)strtoul(valstr, NULL, 0);
 
215
}
 
216
 
 
217
static char *ks(char *str, const char *k)
 
218
{
 
219
        static char valstr[64];
 
220
        char *p;
 
221
        int i;
 
222
 
 
223
        p = strstr(str, k);
 
224
        if (!p)
 
225
                return 0;
 
226
 
 
227
        p = strstr(p, "=") + 1;
 
228
        if (!p)
 
229
                return 0;
 
230
 
 
231
        memset(valstr, 0, 64);
 
232
 
 
233
        for (i = 0; i < 64; i++) {
 
234
                if (*p == ' ')
 
235
                        break;
 
236
                if (*p == '\0')
 
237
                        break;
 
238
                if (*p == '\n')
 
239
                        break;
 
240
                valstr[i] = *p;
 
241
                p++;
 
242
        }
 
243
 
 
244
        return valstr;
 
245
}
 
246
 
 
247
static void print_daemon(struct dlmc_state *st, char *str, char *bin, uint32_t flags)
 
248
{
 
249
        unsigned int cluster_ringid, daemon_ringid;
 
250
        unsigned int fipu;
 
251
 
 
252
        if (flags & DLMC_STATUS_VERBOSE) {
 
253
                printf("our_nodeid %d\n", st->nodeid);
 
254
                print_str(str, st->str_len);
 
255
                return;
 
256
        }
 
257
 
 
258
        cluster_ringid = kv(str, "cluster_ringid");
 
259
        daemon_ringid = kv(str, "daemon_ringid");
 
260
 
 
261
        printf("cluster nodeid %d quorate %u ring seq %u %u\n",
 
262
                st->nodeid,
 
263
                kv(str, "quorate"),
 
264
                cluster_ringid, daemon_ringid);
 
265
 
 
266
        fipu = kv(str, "fence_in_progress_unknown");
 
267
 
 
268
        printf("daemon now %u fence_pid %u %s\n",
 
269
                kv(str, "monotime"),
 
270
                kv(str, "fence_pid"),
 
271
                fipu ? "fence_init" : "");
 
272
}
 
273
 
 
274
static void format_daemon_node(struct dlmc_state *st, char *str, char *bin, uint32_t flags,
 
275
                               char *node_line, char *fence_line)
 
276
{
 
277
        unsigned int delay_fencing, result_wait, killed;
 
278
        char letter;
 
279
 
 
280
        if (st->type == DLMC_STATE_STARTUP_NODE)
 
281
                letter = 'U';
 
282
        else if (kv(str, "member"))
 
283
                letter = 'M';
 
284
        else
 
285
                letter = 'X';
 
286
        
 
287
 
 
288
        snprintf(node_line, DLMC_STATE_MAXSTR - 1,
 
289
                "node %d %c add %u rem %u fail %u fence %u at %u %u\n",
 
290
                st->nodeid,
 
291
                letter,
 
292
                kv(str, "add_time"),
 
293
                kv(str, "rem_time"),
 
294
                kv(str, "fail_monotime"),
 
295
                kv(str, "fence_monotime"),
 
296
                kv(str, "actor_done"),
 
297
                kv(str, "fence_walltime"));
 
298
 
 
299
        if (!kv(str, "need_fencing"))
 
300
                return;
 
301
 
 
302
        delay_fencing = kv(str, "delay_fencing");
 
303
        result_wait = kv(str, "fence_result_wait");
 
304
        killed = kv(str, "killed");
 
305
 
 
306
        if (delay_fencing)
 
307
                snprintf(fence_line, DLMC_STATE_MAXSTR - 1,
 
308
                        "fence %d %s delay actor %u fail %u fence %u now %u%s%s\n",
 
309
                        st->nodeid,
 
310
                        ks(str, "left_reason"),
 
311
                        kv(str, "actor_last"),
 
312
                        kv(str, "fail_walltime"),
 
313
                        kv(str, "fence_walltime"),
 
314
                        (unsigned int)time(NULL),
 
315
                        result_wait ? " result_wait" : "",
 
316
                        killed ? " killed" : "");
 
317
        else
 
318
                snprintf(fence_line, DLMC_STATE_MAXSTR - 1,
 
319
                        "fence %d %s pid %d actor %u fail %u fence %u now %u%s%s\n",
 
320
                        st->nodeid,
 
321
                        ks(str, "left_reason"),
 
322
                        kv(str, "fence_pid"),
 
323
                        kv(str, "actor_last"),
 
324
                        kv(str, "fail_walltime"),
 
325
                        kv(str, "fence_walltime"),
 
326
                        (unsigned int)time(NULL),
 
327
                        result_wait ? " result_wait" : "",
 
328
                        killed ? " killed" : "");
 
329
}
 
330
 
 
331
#define MAX_SORT 64
 
332
 
 
333
int dlmc_print_status(uint32_t flags)
 
334
{
 
335
        struct dlmc_header h;
 
336
        struct dlmc_state state;
 
337
        struct dlmc_state *st;
 
338
        char maxstr[DLMC_STATE_MAXSTR];
 
339
        char maxbin[DLMC_STATE_MAXBIN];
 
340
        char *str, *bin;
 
341
        int all_count, node_count, fence_count;
 
342
        int all_ids[MAX_SORT], node_ids[MAX_SORT], fence_ids[MAX_SORT];
 
343
        char *node_lines[MAX_SORT], *fence_lines[MAX_SORT];
 
344
        char *node_line, *fence_line;
 
345
        int fd, rv, off;
 
346
        int i, j;
 
347
 
 
348
        init_header(&h, DLMC_CMD_DUMP_STATUS, NULL, 0);
 
349
 
 
350
        fd = do_connect(DLMC_QUERY_SOCK_PATH);
 
351
        if (fd < 0) {
 
352
                printf("cannot connect to dlm_controld\n");
 
353
                rv = fd;
 
354
                goto out;
 
355
        }
 
356
 
 
357
        rv = do_write(fd, &h, sizeof(h));
 
358
        if (rv < 0) {
 
359
                printf("cannot send to dlm_controld\n");
 
360
                goto out_close;
 
361
        }
 
362
 
 
363
        st = &state;
 
364
        str = maxstr;
 
365
        bin = maxbin;
 
366
        off = 0;
 
367
 
 
368
        all_count = 0;
 
369
        node_count = 0;
 
370
        fence_count = 0;
 
371
        memset(&all_ids, 0, sizeof(all_ids));
 
372
        memset(&node_ids, 0, sizeof(node_ids));
 
373
        memset(&fence_ids, 0, sizeof(fence_ids));
 
374
        memset(node_lines, 0, sizeof(node_lines));
 
375
        memset(fence_lines, 0, sizeof(fence_lines));
 
376
 
 
377
        while (1) {
 
378
                memset(&state, 0, sizeof(state));
 
379
                memset(maxstr, 0, sizeof(maxstr));
 
380
                memset(maxbin, 0, sizeof(maxbin));
 
381
 
 
382
                rv = recv(fd, st, sizeof(struct dlmc_state), MSG_WAITALL);
 
383
                if (!rv)
 
384
                        break;
 
385
                if (rv != sizeof(struct dlmc_state))
 
386
                        break;
 
387
 
 
388
                if (st->str_len) {
 
389
                        rv = recv(fd, str, st->str_len, MSG_WAITALL);
 
390
                        if (rv != st->str_len)
 
391
                                break;
 
392
                }
 
393
 
 
394
                if (st->bin_len) {
 
395
                        rv = recv(fd, bin, st->bin_len, MSG_WAITALL);
 
396
                        if (rv != st->bin_len)
 
397
                                break;
 
398
                }
 
399
 
 
400
                switch (st->type) {
 
401
                case DLMC_STATE_DAEMON:
 
402
                        print_daemon(st, str, bin, flags);
 
403
                        break;
 
404
 
 
405
                case DLMC_STATE_DAEMON_NODE:
 
406
                case DLMC_STATE_STARTUP_NODE:
 
407
 
 
408
                        if (flags & DLMC_STATUS_VERBOSE) {
 
409
                                printf("nodeid %d\n", st->nodeid);
 
410
                                print_str(str, st->str_len);
 
411
                        } else {
 
412
                                node_line = malloc(DLMC_STATE_MAXSTR);
 
413
                                if (!node_line)
 
414
                                        break;
 
415
                                fence_line = malloc(DLMC_STATE_MAXSTR);
 
416
                                if (!fence_line) {
 
417
                                        free(node_line);
 
418
                                        break;
 
419
                                }
 
420
                                memset(node_line, 0, DLMC_STATE_MAXSTR);
 
421
                                memset(fence_line, 0, DLMC_STATE_MAXSTR);
 
422
 
 
423
                                format_daemon_node(st, str, bin, flags,
 
424
                                                   node_line, fence_line);
 
425
 
 
426
                                all_ids[all_count++] = st->nodeid;
 
427
 
 
428
                                node_ids[node_count] = st->nodeid;
 
429
                                node_lines[node_count++] = node_line;
 
430
                                node_count++;
 
431
 
 
432
                                if (!fence_line[0]) {
 
433
                                        free(fence_line);
 
434
                                } else {
 
435
                                        fence_ids[fence_count] = st->nodeid;
 
436
                                        fence_lines[fence_count] = fence_line;
 
437
                                        fence_count++;
 
438
                                }
 
439
                        }
 
440
                        break;
 
441
 
 
442
                default:
 
443
                        break;
 
444
                }
 
445
 
 
446
                if (rv < 0)
 
447
                        break;
 
448
        }
 
449
 
 
450
        if (all_count)
 
451
                qsort(all_ids, all_count, sizeof(int), nodeid_compare);
 
452
 
 
453
        if (all_count && fence_count) {
 
454
                for (i = 0; i < all_count; i++) {
 
455
                        for (j = 0; j < fence_count; j++) {
 
456
                                if (all_ids[i] != fence_ids[j])
 
457
                                        continue;
 
458
                                printf("%s", fence_lines[j]);
 
459
                                free(fence_lines[j]);
 
460
                                break;
 
461
                        }
 
462
                }
 
463
        }
 
464
 
 
465
        if (all_count && node_count) {
 
466
                for (i = 0; i < all_count; i++) {
 
467
                        for (j = 0; j < node_count; j++) {
 
468
                                if (all_ids[i] != node_ids[j])
 
469
                                        continue;
 
470
                                printf("%s", node_lines[j]);
 
471
                                free(node_lines[j]);
 
472
                                break;
 
473
                        }
 
474
                }
 
475
        }
 
476
 
 
477
 out_close:
 
478
        close(fd);
 
479
 out:
 
480
        return rv;
 
481
}
 
482
 
 
483
int dlmc_node_info(char *name, int nodeid, struct dlmc_node *node)
 
484
{
 
485
        struct dlmc_header h, *rh;
 
486
        char reply[sizeof(struct dlmc_header) + sizeof(struct dlmc_node)];
 
487
        int fd, rv;
 
488
 
 
489
        init_header(&h, DLMC_CMD_NODE_INFO, name, 0);
 
490
        h.data = nodeid;
 
491
 
 
492
        memset(reply, 0, sizeof(reply));
 
493
 
 
494
        fd = do_connect(DLMC_QUERY_SOCK_PATH);
 
495
        if (fd < 0) {
 
496
                rv = fd;
 
497
                goto out;
 
498
        }
 
499
 
 
500
        rv = do_write(fd, &h, sizeof(h));
 
501
        if (rv < 0)
 
502
                goto out_close;
 
503
 
 
504
        rv = do_read(fd, reply, sizeof(reply));
 
505
        if (rv < 0)
 
506
                goto out_close;
 
507
 
 
508
        rh = (struct dlmc_header *)reply;
 
509
        rv = rh->data;
 
510
        if (rv < 0)
 
511
                goto out_close;
 
512
 
 
513
        memcpy(node, (char *)reply + sizeof(struct dlmc_header),
 
514
               sizeof(struct dlmc_node));
 
515
 out_close:
 
516
        close(fd);
 
517
 out:
 
518
        return rv;
 
519
}
 
520
 
 
521
int dlmc_lockspace_info(char *name, struct dlmc_lockspace *lockspace)
 
522
{
 
523
        struct dlmc_header h, *rh;
 
524
        char reply[sizeof(struct dlmc_header) + sizeof(struct dlmc_lockspace)];
 
525
        int fd, rv;
 
526
 
 
527
        init_header(&h, DLMC_CMD_LOCKSPACE_INFO, name, 0);
 
528
 
 
529
        memset(reply, 0, sizeof(reply));
 
530
 
 
531
        fd = do_connect(DLMC_QUERY_SOCK_PATH);
 
532
        if (fd < 0) {
 
533
                rv = fd;
 
534
                goto out;
 
535
        }
 
536
 
 
537
        rv = do_write(fd, &h, sizeof(h));
 
538
        if (rv < 0)
 
539
                goto out_close;
 
540
 
 
541
        rv = do_read(fd, reply, sizeof(reply));
 
542
        if (rv < 0)
 
543
                goto out_close;
 
544
 
 
545
        rh = (struct dlmc_header *)reply;
 
546
        rv = rh->data;
 
547
        if (rv < 0)
 
548
                goto out_close;
 
549
 
 
550
        memcpy(lockspace, (char *)reply + sizeof(struct dlmc_header),
 
551
               sizeof(struct dlmc_lockspace));
 
552
 out_close:
 
553
        close(fd);
 
554
 out:
 
555
        return rv;
 
556
}
 
557
 
 
558
int dlmc_lockspaces(int max, int *count, struct dlmc_lockspace *lss)
 
559
{
 
560
        struct dlmc_header h, *rh;
 
561
        char *reply;
 
562
        int reply_len;
 
563
        int fd, rv, result, ls_count;
 
564
 
 
565
        init_header(&h, DLMC_CMD_LOCKSPACES, NULL, 0);
 
566
        h.data = max;
 
567
 
 
568
        reply_len = sizeof(struct dlmc_header) +
 
569
                    (max * sizeof(struct dlmc_lockspace));
 
570
        reply = malloc(reply_len);
 
571
        if (!reply) {
 
572
                rv = -1;
 
573
                goto out;
 
574
        }
 
575
        memset(reply, 0, reply_len);
 
576
 
 
577
        fd = do_connect(DLMC_QUERY_SOCK_PATH);
 
578
        if (fd < 0) {
 
579
                rv = fd;
 
580
                goto out;
 
581
        }
 
582
 
 
583
        rv = do_write(fd, &h, sizeof(h));
 
584
        if (rv < 0)
 
585
                goto out_close;
 
586
 
 
587
        /* won't usually get back the full reply_len */
 
588
        do_read(fd, reply, reply_len);
 
589
 
 
590
        rh = (struct dlmc_header *)reply;
 
591
        result = rh->data;
 
592
        if (result < 0 && result != -E2BIG) {
 
593
                rv = result;
 
594
                goto out_close;
 
595
        }
 
596
 
 
597
        if (result == -E2BIG) {
 
598
                *count = -E2BIG;
 
599
                ls_count = max;
 
600
        } else {
 
601
                *count = result;
 
602
                ls_count = result;
 
603
        }
 
604
        rv = 0;
 
605
 
 
606
        memcpy(lss, (char *)reply + sizeof(struct dlmc_header),
 
607
               ls_count * sizeof(struct dlmc_lockspace));
 
608
 out_close:
 
609
        close(fd);
 
610
 out:
 
611
        return rv;
 
612
}
 
613
 
 
614
int dlmc_lockspace_nodes(char *name, int type, int max, int *count,
 
615
                         struct dlmc_node *nodes)
 
616
{
 
617
        struct dlmc_header h, *rh;
 
618
        char *reply;
 
619
        int reply_len;
 
620
        int fd, rv, result, node_count;
 
621
 
 
622
        init_header(&h, DLMC_CMD_LOCKSPACE_NODES, name, 0);
 
623
        h.option = type;
 
624
        h.data = max;
 
625
 
 
626
        reply_len = sizeof(struct dlmc_header) +
 
627
                    (max * sizeof(struct dlmc_node));
 
628
        reply = malloc(reply_len);
 
629
        if (!reply) {
 
630
                rv = -1;
 
631
                goto out;
 
632
        }
 
633
        memset(reply, 0, reply_len);
 
634
 
 
635
        fd = do_connect(DLMC_QUERY_SOCK_PATH);
 
636
        if (fd < 0) {
 
637
                rv = fd;
 
638
                goto out;
 
639
        }
 
640
 
 
641
        rv = do_write(fd, &h, sizeof(h));
 
642
        if (rv < 0)
 
643
                goto out_close;
 
644
 
 
645
        /* won't usually get back the full reply_len */
 
646
        do_read(fd, reply, reply_len);
 
647
 
 
648
        rh = (struct dlmc_header *)reply;
 
649
        result = rh->data;
 
650
        if (result < 0 && result != -E2BIG) {
 
651
                rv = result;
 
652
                goto out_close;
 
653
        }
 
654
 
 
655
        if (result == -E2BIG) {
 
656
                *count = -E2BIG;
 
657
                node_count = max;
 
658
        } else {
 
659
                *count = result;
 
660
                node_count = result;
 
661
        }
 
662
        rv = 0;
 
663
 
 
664
        memcpy(nodes, (char *)reply + sizeof(struct dlmc_header),
 
665
               node_count * sizeof(struct dlmc_node));
 
666
 out_close:
 
667
        close(fd);
 
668
 out:
 
669
        return rv;
 
670
}
 
671
 
 
672
int dlmc_fs_connect(void)
 
673
{
 
674
        return do_connect(DLMC_SOCK_PATH);
 
675
}
 
676
 
 
677
void dlmc_fs_disconnect(int fd)
 
678
{
 
679
        close(fd);
 
680
}
 
681
 
 
682
int dlmc_fs_register(int fd, char *name)
 
683
{
 
684
        struct dlmc_header h;
 
685
 
 
686
        init_header(&h, DLMC_CMD_FS_REGISTER, name, 0);
 
687
 
 
688
        return do_write(fd, &h, sizeof(h));
 
689
}
 
690
 
 
691
int dlmc_fs_unregister(int fd, char *name)
 
692
{
 
693
        struct dlmc_header h;
 
694
 
 
695
        init_header(&h, DLMC_CMD_FS_UNREGISTER, name, 0);
 
696
 
 
697
        return do_write(fd, &h, sizeof(h));
 
698
}
 
699
 
 
700
int dlmc_fs_notified(int fd, char *name, int nodeid)
 
701
{
 
702
        struct dlmc_header h;
 
703
 
 
704
        init_header(&h, DLMC_CMD_FS_NOTIFIED, name, 0);
 
705
        h.data = nodeid;
 
706
 
 
707
        return do_write(fd, &h, sizeof(h));
 
708
}
 
709
 
 
710
int dlmc_fs_result(int fd, char *name, int *type, int *nodeid, int *result)
 
711
{
 
712
        struct dlmc_header h;
 
713
        int rv;
 
714
 
 
715
        rv = do_read(fd, &h, sizeof(h));
 
716
        if (rv < 0)
 
717
                goto out;
 
718
 
 
719
        strncpy(name, h.name, DLM_LOCKSPACE_LEN);
 
720
        *nodeid = h.option;
 
721
        *result = h.data;
 
722
 
 
723
        switch (h.command) {
 
724
        case DLMC_CMD_FS_REGISTER:
 
725
                *type = DLMC_RESULT_REGISTER;
 
726
                break;
 
727
        case DLMC_CMD_FS_NOTIFIED:
 
728
                *type = DLMC_RESULT_NOTIFIED;
 
729
                break;
 
730
        default:
 
731
                *type = 0;
 
732
        }
 
733
 out:
 
734
        return rv;
 
735
}
 
736
 
 
737
int dlmc_deadlock_check(char *name)
 
738
{
 
739
        struct dlmc_header h;
 
740
        int fd, rv;
 
741
 
 
742
        init_header(&h, DLMC_CMD_DEADLOCK_CHECK, name, 0);
 
743
 
 
744
        fd = do_connect(DLMC_SOCK_PATH);
 
745
        if (fd < 0) {
 
746
                rv = fd;
 
747
                goto out;
 
748
        }
 
749
 
 
750
        rv = do_write(fd, &h, sizeof(h));
 
751
        close(fd);
 
752
 out:
 
753
        return rv;
 
754
}
 
755
 
 
756
int dlmc_fence_ack(char *name)
 
757
{
 
758
        struct dlmc_header h;
 
759
        int fd, rv;
 
760
 
 
761
        init_header(&h, DLMC_CMD_FENCE_ACK, name, 0);
 
762
 
 
763
        fd = do_connect(DLMC_SOCK_PATH);
 
764
        if (fd < 0) {
 
765
                rv = fd;
 
766
                goto out;
 
767
        }
 
768
 
 
769
        rv = do_write(fd, &h, sizeof(h));
 
770
        close(fd);
 
771
 out:
 
772
        return rv;
 
773
}
 
774