2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * This file handles locking and seaching resources
22 * Kern Sibbald, January MM
23 * Split from parse_conf.c April MMV
29 /* Each daemon has a slightly different set of
30 * resources, so it will define the following
33 extern int32_t r_first;
34 extern int32_t r_last;
35 extern RES_TABLE resources[];
36 extern RES_HEAD **res_head;
38 brwlock_t res_lock; /* resource lock */
39 static int res_locked = 0; /* resource chain lock count -- for debug */
42 /* #define TRACE_RES */
44 void b_LockRes(const char *file, int line)
48 Pmsg4(000, "LockRes locked=%d w_active=%d at %s:%d\n",
49 res_locked, res_lock.w_active, file, line);
51 Pmsg2(000, "LockRes writerid=%d myid=%d\n", res_lock.writer_id,
55 if ((errstat=rwl_writelock(&res_lock)) != 0) {
56 Emsg3(M_ABORT, 0, _("rwl_writelock failure at %s:%d: ERR=%s\n"),
57 file, line, strerror(errstat));
62 void b_UnlockRes(const char *file, int line)
65 if ((errstat=rwl_writeunlock(&res_lock)) != 0) {
66 Emsg3(M_ABORT, 0, _("rwl_writeunlock failure at %s:%d:. ERR=%s\n"),
67 file, line, strerror(errstat));
71 Pmsg4(000, "UnLockRes locked=%d wactive=%d at %s:%d\n",
72 res_locked, res_lock.w_active, file, line);
77 * Compare two resource names
79 int res_compare(void *item1, void *item2)
81 RES *res1 = (RES *)item1;
82 RES *res2 = (RES *)item2;
83 return strcmp(res1->name, res2->name);
87 * Return resource of type rcode that matches name
90 GetResWithName(int rcode, const char *name)
93 int rindex = rcode - r_first;
97 reshead = res_head[rindex];
98 item.name = (char *)name;
99 res = (RES *)reshead->res_list->search(&item, res_compare);
106 * Return next resource of type rcode. On first
107 * call second arg (res) is NULL, on subsequent
108 * calls, it is called with previous value.
111 GetNextRes(int rcode, RES *res)
114 int rindex = rcode - r_first;
117 nres = (RES *)res_head[rindex]->first;
119 nres = res->res_next;
125 * Return next resource of type rcode. On first
126 * call second arg (res) is NULL, on subsequent
127 * calls, it is called with previous value.
130 GetNextRes(RES_HEAD **rhead, int rcode, RES *res)
133 int rindex = rcode - r_first;
136 nres = (RES *)rhead[rindex]->first;
138 nres = res->res_next;