~wb-munzinger/+junk/ocfs2-tools

« back to all changes in this revision

Viewing changes to libocfs2/dlm.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2009-07-06 07:26:30 UTC
  • mfrom: (1.1.7 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090706072630-59335sl51k3rvu74
Tags: 1.4.2-1
* New upstream release (Closes: #535471).
* Drop patch for limits.h, included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 * This program is free software; you can redistribute it and/or
11
11
 * modify it under the terms of the GNU General Public
12
12
 * License, version 2,  as published by the Free Software Foundation.
13
 
 * 
 
13
 *
14
14
 * This program is distributed in the hope that it will be useful,
15
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
17
 * General Public License for more details.
18
 
 * 
 
18
 *
19
19
 * You should have received a copy of the GNU General Public
20
20
 * License along with this program; if not, write to the
21
21
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25
25
 
26
26
#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
27
27
#define _LARGEFILE64_SOURCE
28
 
                                                                                                                                                         
29
 
#include "ocfs2.h"
 
28
 
 
29
#include "ocfs2/ocfs2.h"
30
30
 
31
31
#define DEFAULT_DLMFS_PATH      "/dlm/"
32
32
 
101
101
        return ret;
102
102
}
103
103
 
104
 
errcode_t ocfs2_initialize_dlm(ocfs2_filesys *fs)
 
104
errcode_t ocfs2_fill_cluster_desc(ocfs2_filesys *fs,
 
105
                                  struct o2cb_cluster_desc *desc)
 
106
{
 
107
        errcode_t ret = 0;
 
108
        struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
 
109
 
 
110
        if (!ocfs2_userspace_stack(sb)) {
 
111
                desc->c_stack = NULL;
 
112
                desc->c_cluster = NULL;
 
113
                return 0;
 
114
        }
 
115
 
 
116
        ret = ocfs2_malloc0(OCFS2_STACK_LABEL_LEN + 1, &desc->c_stack);
 
117
        if (ret)
 
118
                return ret;
 
119
 
 
120
        ret = ocfs2_malloc0(OCFS2_CLUSTER_NAME_LEN + 1, &desc->c_cluster);
 
121
        if (ret) {
 
122
                ocfs2_free(&desc->c_stack);
 
123
                return ret;
 
124
        }
 
125
 
 
126
        memcpy(desc->c_stack, sb->s_cluster_info.ci_stack,
 
127
               OCFS2_STACK_LABEL_LEN);
 
128
        memcpy(desc->c_cluster, sb->s_cluster_info.ci_cluster,
 
129
               OCFS2_CLUSTER_NAME_LEN);
 
130
 
 
131
        return 0;
 
132
}
 
133
 
 
134
errcode_t ocfs2_set_cluster_desc(ocfs2_filesys *fs,
 
135
                                 struct o2cb_cluster_desc *desc)
 
136
{
 
137
        errcode_t ret;
 
138
        struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
 
139
 
 
140
        if (desc->c_stack) {
 
141
                if (!desc->c_stack[0] || !desc->c_cluster ||
 
142
                    !desc->c_cluster[0]) {
 
143
                        ret = OCFS2_ET_INVALID_ARGUMENT;
 
144
                        goto out;
 
145
                }
 
146
 
 
147
                if (!ocfs2_uses_extended_slot_map(sb)) {
 
148
                        sb->s_feature_incompat |=
 
149
                                OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP;
 
150
                        ret = ocfs2_format_slot_map(fs);
 
151
                        if (ret)
 
152
                                goto out;
 
153
                }
 
154
                sb->s_feature_incompat |=
 
155
                        OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK;
 
156
                memcpy(sb->s_cluster_info.ci_stack, desc->c_stack,
 
157
                       OCFS2_STACK_LABEL_LEN);
 
158
                memcpy(sb->s_cluster_info.ci_cluster, desc->c_cluster,
 
159
                       OCFS2_CLUSTER_NAME_LEN);
 
160
        } else {
 
161
                sb->s_feature_incompat &=
 
162
                        ~OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK;
 
163
        }
 
164
 
 
165
        ret = ocfs2_write_super(fs);
 
166
 
 
167
out:
 
168
        return ret;
 
169
}
 
170
 
 
171
errcode_t ocfs2_initialize_dlm(ocfs2_filesys *fs, const char *service)
105
172
{
106
173
        struct o2dlm_ctxt *dlm_ctxt = NULL;
107
174
        errcode_t ret = 0;
108
 
 
109
 
        ret = ocfs2_start_heartbeat(fs);
110
 
        if (ret)
111
 
                goto bail;
112
 
 
113
 
        ret = o2dlm_initialize(DEFAULT_DLMFS_PATH, fs->uuid_str, &dlm_ctxt);
 
175
        struct o2cb_cluster_desc cluster;
 
176
        struct o2cb_region_desc desc;
 
177
        char *stack_path;
 
178
 
 
179
        ret = ocfs2_fill_cluster_desc(fs, &cluster);
 
180
        if (ret)
 
181
                goto bail;
 
182
 
 
183
        ret = ocfs2_fill_heartbeat_desc(fs, &desc);
 
184
        if (ret)
 
185
                goto bail;
 
186
 
 
187
        desc.r_service = (char *)service;
 
188
        desc.r_persist = 0;
 
189
        ret = o2cb_begin_group_join(&cluster, &desc);
 
190
        if (ret)
 
191
                goto bail;
 
192
 
 
193
        /*
 
194
         * NULL c_stack means o2cb, means use DLMFS, means
 
195
         * pass DLMFS_PATH.  If we're using a userspace stack, pass NULL.
 
196
         */
 
197
        if (cluster.c_stack)
 
198
                stack_path = NULL;
 
199
        else
 
200
                stack_path = DEFAULT_DLMFS_PATH;
 
201
        ret = o2dlm_initialize(stack_path, fs->uuid_str, &dlm_ctxt);
114
202
        if (ret) {
115
203
                /* What to do with an error code? */
116
 
                ocfs2_stop_heartbeat(fs);
 
204
 
 
205
                /* Ignore the result of complete_group_join, as we want
 
206
                 * to propagate our o2dlm_initialize() error */
 
207
                o2cb_complete_group_join(&cluster, &desc, ret);
117
208
                goto bail;
118
209
        }
119
210
 
120
 
        fs->fs_dlm_ctxt = dlm_ctxt;
 
211
        ret = o2cb_complete_group_join(&cluster, &desc, 0);
 
212
 
 
213
        if (!ret)
 
214
                fs->fs_dlm_ctxt = dlm_ctxt;
 
215
        else
 
216
                o2dlm_destroy(dlm_ctxt);
121
217
 
122
218
bail:
123
219
        return ret;
124
220
}
125
221
 
126
 
errcode_t ocfs2_shutdown_dlm(ocfs2_filesys *fs)
 
222
errcode_t ocfs2_shutdown_dlm(ocfs2_filesys *fs, const char *service)
127
223
{
128
224
        errcode_t ret;
 
225
        struct o2cb_cluster_desc cluster;
 
226
        struct o2cb_region_desc desc;
129
227
 
130
228
        ret = o2dlm_destroy(fs->fs_dlm_ctxt);
131
229
        if (ret)
133
231
 
134
232
        fs->fs_dlm_ctxt = NULL;
135
233
 
136
 
        ret = ocfs2_stop_heartbeat(fs);
 
234
        ret = ocfs2_fill_cluster_desc(fs, &cluster);
 
235
        if (ret)
 
236
                goto bail;
 
237
 
 
238
        ret = ocfs2_fill_heartbeat_desc(fs, &desc);
 
239
        if (ret)
 
240
                goto bail;
 
241
 
 
242
        desc.r_service = (char *)service;
 
243
        desc.r_persist = 0;
 
244
        ret = o2cb_group_leave(&cluster, &desc);
137
245
 
138
246
bail:
139
247
        return ret;
145
253
        errcode_t ret;
146
254
 
147
255
        ocfs2_encode_lockres(OCFS2_LOCK_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO,
148
 
                             0, lock_name);
 
256
                             0, 0, lock_name);
149
257
 
150
258
        ret = o2dlm_lock(fs->fs_dlm_ctxt, lock_name,
151
259
                         O2DLM_TRYLOCK, O2DLM_LEVEL_EXMODE);
159
267
        errcode_t ret;
160
268
 
161
269
        ocfs2_encode_lockres(OCFS2_LOCK_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO,
162
 
                             0, lock_name);
 
270
                             0, 0, lock_name);
163
271
 
164
272
        ret = o2dlm_unlock(fs->fs_dlm_ctxt, lock_name);
165
 
        
 
273
 
166
274
        return ret;
167
275
}
168
 
        
 
276
 
169
277
errcode_t ocfs2_meta_lock(ocfs2_filesys *fs,
170
278
                          ocfs2_cached_inode *ci,
171
279
                          enum o2dlm_lock_level level,
175
283
        errcode_t ret;
176
284
 
177
285
        ocfs2_encode_lockres(OCFS2_LOCK_TYPE_META, ci->ci_blkno,
178
 
                             ci->ci_inode->i_generation, lock_name);
 
286
                             ci->ci_inode->i_generation, 0, lock_name);
179
287
 
180
288
        ret = o2dlm_lock(fs->fs_dlm_ctxt, lock_name, flags, level);
181
289
 
189
297
        errcode_t ret;
190
298
 
191
299
        ocfs2_encode_lockres(OCFS2_LOCK_TYPE_META, ci->ci_blkno,
192
 
                             ci->ci_inode->i_generation, lock_name);
 
300
                             ci->ci_inode->i_generation, 0, lock_name);
193
301
 
194
302
        ret = o2dlm_unlock(fs->fs_dlm_ctxt, lock_name);
195
303
 
203
311
#include <stdlib.h>
204
312
#include <libgen.h>
205
313
 
 
314
#define DEBUG_SERVICE "debug"
 
315
 
206
316
static void print_usage(void)
207
317
{
208
318
        fprintf(stderr, "Usage: dlm <filename>\n");
237
347
                goto out;
238
348
        }
239
349
 
240
 
        ret = ocfs2_initialize_dlm(fs);
 
350
        ret = ocfs2_initialize_dlm(fs, DEBUG_SERVICE);
241
351
        if (ret) {
242
352
                com_err(progname, ret, "while initializing dlm");
243
353
                goto out;
263
373
 
264
374
out:
265
375
        if (fs->fs_dlm_ctxt) {
266
 
                ret = ocfs2_shutdown_dlm(fs);
 
376
                ret = ocfs2_shutdown_dlm(fs, DEBUG_SERVICE);
267
377
                if (ret)
268
378
                        com_err(progname, ret, "while shutting down dlm");
269
379
        }