1/*	$NetBSD: no_locking.c,v 1.1.1.2 2009/12/02 00:26:24 haad Exp $	*/
2
3/*
4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
6 *
7 * This file is part of LVM2.
8 *
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.
12 *
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
16 */
17
18#include "lib.h"
19#include "locking.h"
20#include "locking_types.h"
21#include "lvm-string.h"
22#include "activate.h"
23
24#include <signal.h>
25
26/*
27 * No locking
28 */
29
30static void _no_fin_locking(void)
31{
32	return;
33}
34
35static void _no_reset_locking(void)
36{
37	return;
38}
39
40static int _no_lock_resource(struct cmd_context *cmd, const char *resource,
41			     uint32_t flags)
42{
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;
60		}
61		break;
62	default:
63		log_error("Unrecognised lock scope: %d",
64			  flags & LCK_SCOPE_MASK);
65		return 0;
66	}
67
68	return 1;
69}
70
71static int _readonly_lock_resource(struct cmd_context *cmd,
72				   const char *resource,
73				   uint32_t flags)
74{
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;
81	}
82
83	return _no_lock_resource(cmd, resource, flags);
84}
85
86int init_no_locking(struct locking_type *locking, struct cmd_context *cmd __attribute((unused)))
87{
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;
92
93	return 1;
94}
95
96int init_readonly_locking(struct locking_type *locking, struct cmd_context *cmd __attribute((unused)))
97{
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;
102
103	return 1;
104}
105