Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / lib / locking / no_locking.c
blobdc84724ea414bed5d97deb87158db8080ac0ec02
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "lib.h"
19 #include "locking.h"
20 #include "locking_types.h"
21 #include "lvm-string.h"
22 #include "activate.h"
24 #include <signal.h>
27 * No locking
30 static void _no_fin_locking(void)
32 return;
35 static void _no_reset_locking(void)
37 return;
40 static int _no_lock_resource(struct cmd_context *cmd, const char *resource,
41 uint32_t flags)
43 switch (flags & LCK_SCOPE_MASK) {
44 case LCK_VG:
45 break;
46 case LCK_LV:
47 switch (flags & LCK_TYPE_MASK) {
48 case LCK_NULL:
49 return lv_deactivate(cmd, resource);
50 case LCK_UNLOCK:
51 return lv_resume_if_active(cmd, resource);
52 case LCK_READ:
53 return lv_activate_with_filter(cmd, resource, 0);
54 case LCK_WRITE:
55 return lv_suspend_if_active(cmd, resource);
56 case LCK_EXCL:
57 return lv_activate_with_filter(cmd, resource, 1);
58 default:
59 break;
61 break;
62 default:
63 log_error("Unrecognised lock scope: %d",
64 flags & LCK_SCOPE_MASK);
65 return 0;
68 return 1;
71 static int _readonly_lock_resource(struct cmd_context *cmd,
72 const char *resource,
73 uint32_t flags)
75 if ((flags & LCK_TYPE_MASK) == LCK_WRITE &&
76 (flags & LCK_SCOPE_MASK) == LCK_VG &&
77 !(flags & LCK_CACHE) &&
78 strcmp(resource, VG_GLOBAL)) {
79 log_error("Write locks are prohibited with --ignorelockingfailure.");
80 return 0;
83 return _no_lock_resource(cmd, resource, flags);
86 int init_no_locking(struct locking_type *locking, struct cmd_context *cmd __attribute((unused)))
88 locking->lock_resource = _no_lock_resource;
89 locking->reset_locking = _no_reset_locking;
90 locking->fin_locking = _no_fin_locking;
91 locking->flags = LCK_CLUSTERED;
93 return 1;
96 int init_readonly_locking(struct locking_type *locking, struct cmd_context *cmd __attribute((unused)))
98 locking->lock_resource = _readonly_lock_resource;
99 locking->reset_locking = _no_reset_locking;
100 locking->fin_locking = _no_fin_locking;
101 locking->flags = 0;
103 return 1;