1*7c604eeaShaad /* $NetBSD: no_locking.c,v 1.1.1.2 2009/12/02 00:26:24 haad Exp $ */
256a34939Shaad
356a34939Shaad /*
456a34939Shaad * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
556a34939Shaad * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
656a34939Shaad *
756a34939Shaad * This file is part of LVM2.
856a34939Shaad *
956a34939Shaad * This copyrighted material is made available to anyone wishing to use,
1056a34939Shaad * modify, copy, or redistribute it subject to the terms and conditions
1156a34939Shaad * of the GNU Lesser General Public License v.2.1.
1256a34939Shaad *
1356a34939Shaad * You should have received a copy of the GNU Lesser General Public License
1456a34939Shaad * along with this program; if not, write to the Free Software Foundation,
1556a34939Shaad * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1656a34939Shaad */
1756a34939Shaad
1856a34939Shaad #include "lib.h"
1956a34939Shaad #include "locking.h"
2056a34939Shaad #include "locking_types.h"
2156a34939Shaad #include "lvm-string.h"
2256a34939Shaad #include "activate.h"
2356a34939Shaad
2456a34939Shaad #include <signal.h>
2556a34939Shaad
2656a34939Shaad /*
2756a34939Shaad * No locking
2856a34939Shaad */
2956a34939Shaad
_no_fin_locking(void)3056a34939Shaad static void _no_fin_locking(void)
3156a34939Shaad {
3256a34939Shaad return;
3356a34939Shaad }
3456a34939Shaad
_no_reset_locking(void)3556a34939Shaad static void _no_reset_locking(void)
3656a34939Shaad {
3756a34939Shaad return;
3856a34939Shaad }
3956a34939Shaad
_no_lock_resource(struct cmd_context * cmd,const char * resource,uint32_t flags)4056a34939Shaad static int _no_lock_resource(struct cmd_context *cmd, const char *resource,
4156a34939Shaad uint32_t flags)
4256a34939Shaad {
4356a34939Shaad switch (flags & LCK_SCOPE_MASK) {
4456a34939Shaad case LCK_VG:
4556a34939Shaad break;
4656a34939Shaad case LCK_LV:
4756a34939Shaad switch (flags & LCK_TYPE_MASK) {
4856a34939Shaad case LCK_NULL:
4956a34939Shaad return lv_deactivate(cmd, resource);
5056a34939Shaad case LCK_UNLOCK:
5156a34939Shaad return lv_resume_if_active(cmd, resource);
5256a34939Shaad case LCK_READ:
5356a34939Shaad return lv_activate_with_filter(cmd, resource, 0);
5456a34939Shaad case LCK_WRITE:
5556a34939Shaad return lv_suspend_if_active(cmd, resource);
5656a34939Shaad case LCK_EXCL:
5756a34939Shaad return lv_activate_with_filter(cmd, resource, 1);
5856a34939Shaad default:
5956a34939Shaad break;
6056a34939Shaad }
6156a34939Shaad break;
6256a34939Shaad default:
6356a34939Shaad log_error("Unrecognised lock scope: %d",
6456a34939Shaad flags & LCK_SCOPE_MASK);
6556a34939Shaad return 0;
6656a34939Shaad }
6756a34939Shaad
6856a34939Shaad return 1;
6956a34939Shaad }
7056a34939Shaad
_readonly_lock_resource(struct cmd_context * cmd,const char * resource,uint32_t flags)71*7c604eeaShaad static int _readonly_lock_resource(struct cmd_context *cmd,
72*7c604eeaShaad const char *resource,
73*7c604eeaShaad uint32_t flags)
74*7c604eeaShaad {
75*7c604eeaShaad if ((flags & LCK_TYPE_MASK) == LCK_WRITE &&
76*7c604eeaShaad (flags & LCK_SCOPE_MASK) == LCK_VG &&
77*7c604eeaShaad !(flags & LCK_CACHE) &&
78*7c604eeaShaad strcmp(resource, VG_GLOBAL)) {
79*7c604eeaShaad log_error("Write locks are prohibited with --ignorelockingfailure.");
80*7c604eeaShaad return 0;
81*7c604eeaShaad }
82*7c604eeaShaad
83*7c604eeaShaad return _no_lock_resource(cmd, resource, flags);
84*7c604eeaShaad }
85*7c604eeaShaad
init_no_locking(struct locking_type * locking,struct cmd_context * cmd __attribute ((unused)))8656a34939Shaad int init_no_locking(struct locking_type *locking, struct cmd_context *cmd __attribute((unused)))
8756a34939Shaad {
8856a34939Shaad locking->lock_resource = _no_lock_resource;
8956a34939Shaad locking->reset_locking = _no_reset_locking;
9056a34939Shaad locking->fin_locking = _no_fin_locking;
9156a34939Shaad locking->flags = LCK_CLUSTERED;
9256a34939Shaad
9356a34939Shaad return 1;
9456a34939Shaad }
95*7c604eeaShaad
init_readonly_locking(struct locking_type * locking,struct cmd_context * cmd __attribute ((unused)))96*7c604eeaShaad int init_readonly_locking(struct locking_type *locking, struct cmd_context *cmd __attribute((unused)))
97*7c604eeaShaad {
98*7c604eeaShaad locking->lock_resource = _readonly_lock_resource;
99*7c604eeaShaad locking->reset_locking = _no_reset_locking;
100*7c604eeaShaad locking->fin_locking = _no_fin_locking;
101*7c604eeaShaad locking->flags = 0;
102*7c604eeaShaad
103*7c604eeaShaad return 1;
104*7c604eeaShaad }
105