1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/fs/obdfilter/filter.c
6 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
7 * Author: Peter Braam <braam@clusterfs.com>
8 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
12 * Lustre is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * Lustre is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Lustre; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * Invariant: Get O/R i_sem for lookup, if needed, before any journal ops
28 * (which need to get journal_lock, may block if journal full).
30 * Invariant: Call filter_start_transno() before any journal ops to avoid the
31 * same deadlock problem. We can (and want) to get rid of the
32 * transno sem in favour of the dir/inode i_sem to avoid single
33 * threaded operation on the OST.
36 #define DEBUG_SUBSYSTEM S_FILTER
38 #include <linux/config.h>
39 #include <linux/module.h>
41 #include <linux/dcache.h>
42 #include <linux/init.h>
43 #include <linux/version.h>
44 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
45 # include <linux/mount.h>
46 # include <linux/buffer_head.h>
49 #include <linux/obd_class.h>
50 #include <linux/obd_lov.h>
51 #include <linux/lustre_dlm.h>
52 #include <linux/lustre_fsfilt.h>
53 #include <linux/lprocfs_status.h>
54 #include <linux/lustre_log.h>
55 #include <linux/lustre_commit_confd.h>
56 #include <portals/list.h>
58 #include <linux/lustre_smfs.h>
59 #include "filter_internal.h"
61 static struct lvfs_callback_ops filter_lvfs_ops;
63 static int filter_destroy(struct obd_export *exp, struct obdo *oa,
64 struct lov_stripe_md *ea, struct obd_trans_info *);
66 static void filter_commit_cb(struct obd_device *obd, __u64 transno,
67 void *cb_data, int error)
69 obd_transno_commit_cb(obd, transno, error);
72 /* Assumes caller has already pushed us into the kernel context. */
73 int filter_finish_transno(struct obd_export *exp, struct obd_trans_info *oti,
76 struct filter_obd *filter = &exp->exp_obd->u.filter;
77 struct filter_export_data *fed = &exp->exp_filter_data;
78 struct filter_client_data *fcd = fed->fed_fcd;
81 int err, log_pri = D_HA;
83 /* Propagate error code. */
87 if (!exp->exp_obd->obd_replayable || oti == NULL)
90 /* we don't allocate new transnos for replayed requests */
91 if (oti->oti_transno == 0) {
92 spin_lock(&filter->fo_translock);
93 last_rcvd = le64_to_cpu(filter->fo_fsd->fsd_last_transno) + 1;
94 filter->fo_fsd->fsd_last_transno = cpu_to_le64(last_rcvd);
95 spin_unlock(&filter->fo_translock);
96 oti->oti_transno = last_rcvd;
98 spin_lock(&filter->fo_translock);
99 last_rcvd = oti->oti_transno;
100 if (last_rcvd > le64_to_cpu(filter->fo_fsd->fsd_last_transno))
101 filter->fo_fsd->fsd_last_transno =
102 cpu_to_le64(last_rcvd);
103 spin_unlock(&filter->fo_translock);
105 fcd->fcd_last_rcvd = cpu_to_le64(last_rcvd);
107 /* could get xid from oti, if it's ever needed */
108 fcd->fcd_last_xid = 0;
110 off = fed->fed_lr_off;
112 fsfilt_add_journal_cb(exp->exp_obd, filter->fo_sb, last_rcvd,
113 oti->oti_handle, filter_commit_cb, NULL);
115 err = fsfilt_write_record(exp->exp_obd, filter->fo_rcvd_filp, fcd,
116 sizeof(*fcd), &off, 0);
123 CDEBUG(log_pri, "wrote trans "LPU64" for client %s at #%d: err = %d\n",
124 last_rcvd, fcd->fcd_uuid, fed->fed_lr_idx, err);
129 void f_dput(struct dentry *dentry)
131 /* Can't go inside filter_ddelete because it can block */
132 CDEBUG(D_INODE, "putting %s: %p, count = %d\n",
133 dentry->d_name.name, dentry, atomic_read(&dentry->d_count) - 1);
134 LASSERT(atomic_read(&dentry->d_count) > 0);
139 /* Add client data to the FILTER. We use a bitmap to locate a free space
140 * in the last_rcvd file if cl_idx is -1 (i.e. a new client).
141 * Otherwise, we have just read the data from the last_rcvd file and
142 * we know its offset. */
143 static int filter_client_add(struct obd_device *obd, struct filter_obd *filter,
144 struct filter_export_data *fed, int cl_idx)
146 unsigned long *bitmap = filter->fo_last_rcvd_slots;
147 int new_client = (cl_idx == -1);
150 LASSERT(bitmap != NULL);
152 /* XXX if fcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
153 if (!strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid))
156 /* the bitmap operations can handle cl_idx > sizeof(long) * 8, so
157 * there's no need for extra complication here
160 cl_idx = find_first_zero_bit(bitmap, FILTER_LR_MAX_CLIENTS);
162 if (cl_idx >= FILTER_LR_MAX_CLIENTS) {
163 CERROR("no client slots - fix FILTER_LR_MAX_CLIENTS\n");
166 if (test_and_set_bit(cl_idx, bitmap)) {
167 CERROR("FILTER client %d: found bit is set in bitmap\n",
169 cl_idx = find_next_zero_bit(bitmap,
170 FILTER_LR_MAX_CLIENTS,
175 if (test_and_set_bit(cl_idx, bitmap)) {
176 CERROR("FILTER client %d: bit already set in bitmap!\n",
182 fed->fed_lr_idx = cl_idx;
183 fed->fed_lr_off = le32_to_cpu(filter->fo_fsd->fsd_client_start) +
184 cl_idx * le16_to_cpu(filter->fo_fsd->fsd_client_size);
186 CDEBUG(D_INFO, "client at index %d (%llu) with UUID '%s' added\n",
187 fed->fed_lr_idx, fed->fed_lr_off, fed->fed_fcd->fcd_uuid);
190 struct lvfs_run_ctxt saved;
191 loff_t off = fed->fed_lr_off;
195 CDEBUG(D_INFO, "writing client fcd at idx %u (%llu) (len %u)\n",
196 fed->fed_lr_idx,off,(unsigned int)sizeof(*fed->fed_fcd));
198 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
199 /* Transaction needed to fix bug 1403 */
200 handle = fsfilt_start(obd,
201 filter->fo_rcvd_filp->f_dentry->d_inode,
202 FSFILT_OP_SETATTR, NULL);
203 if (IS_ERR(handle)) {
204 err = PTR_ERR(handle);
205 CERROR("unable to start transaction: rc %d\n", err);
207 err = fsfilt_write_record(obd, filter->fo_rcvd_filp,
209 sizeof(*fed->fed_fcd),
211 fsfilt_commit(obd, filter->fo_sb,
212 filter->fo_rcvd_filp->f_dentry->d_inode,
215 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
218 CERROR("error writing %s client idx %u: rc %d\n",
219 LAST_RCVD, fed->fed_lr_idx, err);
226 static int filter_client_free(struct obd_export *exp, int flags)
228 struct filter_export_data *fed = &exp->exp_filter_data;
229 struct filter_obd *filter = &exp->exp_obd->u.filter;
230 struct obd_device *obd = exp->exp_obd;
231 struct filter_client_data zero_fcd;
232 struct lvfs_run_ctxt saved;
237 if (fed->fed_fcd == NULL)
240 if (flags & OBD_OPT_FAILOVER)
243 /* XXX if fcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
244 if (strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid ) == 0)
247 LASSERT(filter->fo_last_rcvd_slots != NULL);
249 off = fed->fed_lr_off;
251 CDEBUG(D_INFO, "freeing client at idx %u (%lld) with UUID '%s'\n",
252 fed->fed_lr_idx, fed->fed_lr_off, fed->fed_fcd->fcd_uuid);
254 /* Clear the bit _after_ zeroing out the client so we don't
255 race with filter_client_add and zero out new clients.*/
256 if (!test_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
257 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
262 memset(&zero_fcd, 0, sizeof zero_fcd);
263 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
264 rc = fsfilt_write_record(obd, filter->fo_rcvd_filp, &zero_fcd,
265 sizeof(zero_fcd), &off, 1);
266 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
268 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
269 "zeroing disconnecting client %s at idx %u (%llu) in %s rc %d\n",
270 fed->fed_fcd->fcd_uuid, fed->fed_lr_idx, fed->fed_lr_off,
273 if (!test_and_clear_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
274 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
280 OBD_FREE(fed->fed_fcd, sizeof(*fed->fed_fcd));
285 static int filter_free_server_data(struct filter_obd *filter)
287 OBD_FREE(filter->fo_fsd, sizeof(*filter->fo_fsd));
288 filter->fo_fsd = NULL;
289 OBD_FREE(filter->fo_last_rcvd_slots,
290 FILTER_LR_MAX_CLIENT_WORDS * sizeof(unsigned long));
291 filter->fo_last_rcvd_slots = NULL;
295 /* assumes caller is already in kernel ctxt */
296 int filter_update_server_data(struct obd_device *obd, struct file *filp,
297 struct filter_server_data *fsd, int force_sync)
303 CDEBUG(D_INODE, "server uuid : %s\n", fsd->fsd_uuid);
304 CDEBUG(D_INODE, "server last_rcvd : "LPU64"\n",
305 le64_to_cpu(fsd->fsd_last_transno));
306 CDEBUG(D_INODE, "server last_mount: "LPU64"\n",
307 le64_to_cpu(fsd->fsd_mount_count));
309 rc = fsfilt_write_record(obd, filp, fsd, sizeof(*fsd), &off,force_sync);
311 CERROR("error writing filter_server_data: rc = %d\n", rc);
316 int filter_update_last_objid(struct obd_device *obd, obd_gr group,
319 struct filter_obd *filter = &obd->u.filter;
325 if (filter->fo_last_objid_files[group] == NULL) {
326 CERROR("Object group "LPU64" not fully setup; not updating "
327 "last_objid\n", group);
331 CDEBUG(D_INODE, "server last_objid for group "LPU64": "LPU64"\n",
332 group, filter->fo_last_objids[group]);
334 tmp = cpu_to_le64(filter->fo_last_objids[group]);
335 rc = fsfilt_write_record(obd, filter->fo_last_objid_files[group],
336 &tmp, sizeof(tmp), &off, force_sync);
338 CERROR("error writing group "LPU64" last objid: rc = %d\n",
343 /* assumes caller has already in kernel ctxt */
344 static int filter_init_server_data(struct obd_device *obd, struct file * filp)
346 struct filter_obd *filter = &obd->u.filter;
347 struct filter_server_data *fsd;
348 struct filter_client_data *fcd = NULL;
349 struct inode *inode = filp->f_dentry->d_inode;
350 unsigned long last_rcvd_size = inode->i_size;
356 /* ensure padding in the struct is the correct size */
357 LASSERT (offsetof(struct filter_server_data, fsd_padding) +
358 sizeof(fsd->fsd_padding) == FILTER_LR_SERVER_SIZE);
359 LASSERT (offsetof(struct filter_client_data, fcd_padding) +
360 sizeof(fcd->fcd_padding) == FILTER_LR_CLIENT_SIZE);
362 OBD_ALLOC(fsd, sizeof(*fsd));
365 filter->fo_fsd = fsd;
367 OBD_ALLOC(filter->fo_last_rcvd_slots,
368 FILTER_LR_MAX_CLIENT_WORDS * sizeof(unsigned long));
369 if (filter->fo_last_rcvd_slots == NULL) {
370 OBD_FREE(fsd, sizeof(*fsd));
374 if (last_rcvd_size == 0) {
375 CWARN("%s: initializing new %s\n", obd->obd_name, LAST_RCVD);
377 memcpy(fsd->fsd_uuid, obd->obd_uuid.uuid,sizeof(fsd->fsd_uuid));
378 fsd->fsd_last_transno = 0;
379 mount_count = fsd->fsd_mount_count = 0;
380 fsd->fsd_server_size = cpu_to_le32(FILTER_LR_SERVER_SIZE);
381 fsd->fsd_client_start = cpu_to_le32(FILTER_LR_CLIENT_START);
382 fsd->fsd_client_size = cpu_to_le16(FILTER_LR_CLIENT_SIZE);
383 fsd->fsd_subdir_count = cpu_to_le16(FILTER_SUBDIR_COUNT);
384 filter->fo_subdir_count = FILTER_SUBDIR_COUNT;
386 rc = fsfilt_read_record(obd, filp, fsd, sizeof(*fsd), &off);
388 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
392 if (strcmp(fsd->fsd_uuid, obd->obd_uuid.uuid) != 0) {
393 CERROR("OBD UUID %s does not match last_rcvd UUID %s\n",
394 obd->obd_uuid.uuid, fsd->fsd_uuid);
395 GOTO(err_fsd, rc = -EINVAL);
397 mount_count = le64_to_cpu(fsd->fsd_mount_count);
398 filter->fo_subdir_count = le16_to_cpu(fsd->fsd_subdir_count);
401 if (fsd->fsd_feature_incompat & ~cpu_to_le32(FILTER_INCOMPAT_SUPP)) {
402 CERROR("unsupported feature %x\n",
403 le32_to_cpu(fsd->fsd_feature_incompat) &
404 ~FILTER_INCOMPAT_SUPP);
405 GOTO(err_fsd, rc = -EINVAL);
407 if (fsd->fsd_feature_rocompat & ~cpu_to_le32(FILTER_ROCOMPAT_SUPP)) {
408 CERROR("read-only feature %x\n",
409 le32_to_cpu(fsd->fsd_feature_rocompat) &
410 ~FILTER_ROCOMPAT_SUPP);
411 /* Do something like remount filesystem read-only */
412 GOTO(err_fsd, rc = -EINVAL);
415 CDEBUG(D_INODE, "%s: server last_rcvd : "LPU64"\n",
416 obd->obd_name, le64_to_cpu(fsd->fsd_last_transno));
417 CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
418 obd->obd_name, mount_count + 1);
419 CDEBUG(D_INODE, "%s: server data size: %u\n",
420 obd->obd_name, le32_to_cpu(fsd->fsd_server_size));
421 CDEBUG(D_INODE, "%s: per-client data start: %u\n",
422 obd->obd_name, le32_to_cpu(fsd->fsd_client_start));
423 CDEBUG(D_INODE, "%s: per-client data size: %u\n",
424 obd->obd_name, le32_to_cpu(fsd->fsd_client_size));
425 CDEBUG(D_INODE, "%s: server subdir_count: %u\n",
426 obd->obd_name, le16_to_cpu(fsd->fsd_subdir_count));
427 CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
428 last_rcvd_size <= le32_to_cpu(fsd->fsd_client_start) ? 0 :
429 (last_rcvd_size - le32_to_cpu(fsd->fsd_client_start)) /
430 le16_to_cpu(fsd->fsd_client_size));
432 if (!obd->obd_replayable) {
433 CWARN("%s: recovery support OFF\n", obd->obd_name);
437 for (cl_idx = 0, off = le32_to_cpu(fsd->fsd_client_start);
438 off < last_rcvd_size; cl_idx++) {
440 struct obd_export *exp;
441 struct filter_export_data *fed;
444 OBD_ALLOC(fcd, sizeof(*fcd));
446 GOTO(err_client, rc = -ENOMEM);
449 /* Don't assume off is incremented properly by
450 * fsfilt_read_record(), in case sizeof(*fcd)
451 * isn't the same as fsd->fsd_client_size. */
452 off = le32_to_cpu(fsd->fsd_client_start) +
453 cl_idx * le16_to_cpu(fsd->fsd_client_size);
454 rc = fsfilt_read_record(obd, filp, fcd, sizeof(*fcd), &off);
456 CERROR("error reading FILT %s idx %d off %llu: rc %d\n",
457 LAST_RCVD, cl_idx, off, rc);
458 break; /* read error shouldn't cause startup to fail */
461 if (fcd->fcd_uuid[0] == '\0') {
462 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
467 last_rcvd = le64_to_cpu(fcd->fcd_last_rcvd);
469 /* These exports are cleaned up by filter_disconnect(), so they
470 * need to be set up like real exports as filter_connect() does.
472 exp = class_new_export(obd);
473 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
474 " srv lr: "LPU64"\n", fcd->fcd_uuid, cl_idx,
475 last_rcvd, le64_to_cpu(fsd->fsd_last_transno));
477 GOTO(err_client, rc = -ENOMEM);
479 memcpy(&exp->exp_client_uuid.uuid, fcd->fcd_uuid,
480 sizeof exp->exp_client_uuid.uuid);
481 fed = &exp->exp_filter_data;
483 filter_client_add(obd, filter, fed, cl_idx);
484 /* create helper if export init gets more complex */
485 spin_lock_init(&fed->fed_lock);
488 exp->exp_replay_needed = 1;
489 obd->obd_recoverable_clients++;
490 obd->obd_max_recoverable_clients++;
491 class_export_put(exp);
493 CDEBUG(D_OTHER, "client at idx %d has last_rcvd = "LPU64"\n",
496 if (last_rcvd > le64_to_cpu(fsd->fsd_last_transno))
497 fsd->fsd_last_transno = cpu_to_le64(last_rcvd);
501 obd->obd_last_committed = le64_to_cpu(fsd->fsd_last_transno);
503 if (obd->obd_recoverable_clients) {
504 CWARN("RECOVERY: %d recoverable clients, last_rcvd "
505 LPU64"\n", obd->obd_recoverable_clients,
506 le64_to_cpu(fsd->fsd_last_transno));
507 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
508 obd->obd_recovering = 1;
512 OBD_FREE(fcd, sizeof(*fcd));
515 filter->fo_mount_count = mount_count + 1;
516 fsd->fsd_mount_count = cpu_to_le64(filter->fo_mount_count);
518 /* save it, so mount count and last_transno is current */
519 rc = filter_update_server_data(obd, filp, filter->fo_fsd, 1);
524 class_disconnect_exports(obd, 0);
526 filter_free_server_data(filter);
530 static int filter_cleanup_groups(struct obd_device *obd)
532 struct filter_obd *filter = &obd->u.filter;
533 struct dentry *dentry;
537 for (i = 0; i < filter->fo_group_count; i++) {
538 if (filter->fo_subdirs != NULL) {
539 for (k = 0; k < filter->fo_subdir_count; k++) {
540 dentry = filter->fo_subdirs[i].dentry[k];
544 filter->fo_subdirs[i].dentry[k] = NULL;
547 if (filter->fo_last_objid_files[i] != NULL) {
548 filp_close(filter->fo_last_objid_files[i], 0);
549 filter->fo_last_objid_files[i] = NULL;
551 if (filter->fo_groups[i] != NULL) {
552 dput(filter->fo_groups[i]);
553 filter->fo_groups[i] = NULL;
556 if (filter->fo_subdirs != NULL)
557 OBD_FREE(filter->fo_subdirs,
558 filter->fo_group_count * sizeof(*filter->fo_subdirs));
559 if (filter->fo_groups != NULL)
560 OBD_FREE(filter->fo_groups,
561 filter->fo_group_count * sizeof(*filter->fo_groups));
562 if (filter->fo_last_objids != NULL)
563 OBD_FREE(filter->fo_last_objids,
564 filter->fo_group_count * sizeof(__u64));
565 if (filter->fo_last_objid_files != NULL)
566 OBD_FREE(filter->fo_last_objid_files,
567 filter->fo_group_count * sizeof(struct file *));
568 f_dput(filter->fo_dentry_O);
572 static int filter_read_group_internal(struct obd_device *obd, int group,
575 struct filter_obd *filter = &obd->u.filter;
576 __u64 *new_objids = NULL;
577 struct filter_subdirs *new_subdirs = NULL, *tmp_subdirs = NULL;
578 struct dentry **new_groups = NULL;
579 struct file **new_files = NULL;
580 struct dentry *dentry;
582 int old_count = filter->fo_group_count, rc, stage = 0, i;
587 snprintf(name, 24, "%d", group);
591 dentry = ll_lookup_one_len(name, filter->fo_dentry_O,
593 if (IS_ERR(dentry)) {
594 CERROR("Cannot lookup expected object group %d: %ld\n",
595 group, PTR_ERR(dentry));
596 RETURN(PTR_ERR(dentry));
599 dentry = simple_mkdir(filter->fo_dentry_O, name, 0700, 1);
600 if (IS_ERR(dentry)) {
601 CERROR("cannot lookup/create O/%s: rc = %ld\n", name,
603 RETURN(PTR_ERR(dentry));
608 snprintf(name, 24, "O/%d/LAST_ID", group);
610 filp = filp_open(name, O_CREAT | O_RDWR, 0700);
612 CERROR("cannot create %s: rc = %ld\n", name, PTR_ERR(filp));
613 GOTO(cleanup, rc = PTR_ERR(filp));
617 rc = fsfilt_read_record(obd, filp, &last_objid, sizeof(__u64), &off);
619 CDEBUG(D_INODE, "error reading %s: rc %d\n", name, rc);
623 if (filter->fo_subdir_count) {
624 OBD_ALLOC(tmp_subdirs, sizeof(*tmp_subdirs));
625 if (tmp_subdirs == NULL)
626 GOTO(cleanup, rc = -ENOMEM);
629 for (i = 0; i < filter->fo_subdir_count; i++) {
631 snprintf(dir, sizeof(dir), "d%u", i);
633 tmp_subdirs->dentry[i] =
634 simple_mkdir(dentry, dir, 0700, 1);
635 if (IS_ERR(tmp_subdirs->dentry[i])) {
636 rc = PTR_ERR(tmp_subdirs->dentry[i]);
637 CERROR("can't lookup/create O/%d/%s: rc = %d\n",
641 CDEBUG(D_INODE, "got/created O/%d/%s: %p\n", group, dir,
642 tmp_subdirs->dentry[i]);
646 /* 'group' is an index; we need an array of length 'group + 1' */
647 if (group + 1 > old_count) {
649 OBD_ALLOC(new_objids, len * sizeof(*new_objids));
650 OBD_ALLOC(new_subdirs, len * sizeof(*new_subdirs));
651 OBD_ALLOC(new_groups, len * sizeof(*new_groups));
652 OBD_ALLOC(new_files, len * sizeof(*new_files));
654 if (new_objids == NULL || new_subdirs == NULL ||
655 new_groups == NULL || new_files == NULL)
656 GOTO(cleanup, rc = -ENOMEM);
658 memcpy(new_objids, filter->fo_last_objids,
659 old_count * sizeof(*new_objids));
660 memcpy(new_subdirs, filter->fo_subdirs,
661 old_count * sizeof(*new_subdirs));
662 memcpy(new_groups, filter->fo_groups,
663 old_count * sizeof(*new_groups));
664 memcpy(new_files, filter->fo_last_objid_files,
665 old_count * sizeof(*new_files));
668 OBD_FREE(filter->fo_last_objids,
669 old_count * sizeof(*new_objids));
670 OBD_FREE(filter->fo_subdirs,
671 old_count * sizeof(*new_subdirs));
672 OBD_FREE(filter->fo_groups,
673 old_count * sizeof(*new_groups));
674 OBD_FREE(filter->fo_last_objid_files,
675 old_count * sizeof(*new_files));
677 filter->fo_last_objids = new_objids;
678 filter->fo_subdirs = new_subdirs;
679 filter->fo_groups = new_groups;
680 filter->fo_last_objid_files = new_files;
681 filter->fo_group_count = len;
684 filter->fo_groups[group] = dentry;
685 filter->fo_last_objid_files[group] = filp;
686 if (filter->fo_subdir_count) {
687 filter->fo_subdirs[group] = *tmp_subdirs;
688 OBD_FREE(tmp_subdirs, sizeof(*tmp_subdirs));
691 if (filp->f_dentry->d_inode->i_size == 0) {
692 filter->fo_last_objids[group] = FILTER_INIT_OBJID;
696 filter->fo_last_objids[group] = le64_to_cpu(last_objid);
697 CDEBUG(D_INODE, "%s: server last_objid group %d: "LPU64"\n",
698 obd->obd_name, group, last_objid);
703 if (new_objids != NULL)
704 OBD_FREE(new_objids, group * sizeof(*new_objids));
705 if (new_subdirs != NULL)
706 OBD_FREE(new_subdirs, group * sizeof(*new_subdirs));
707 if (new_groups != NULL)
708 OBD_FREE(new_groups, group * sizeof(*new_groups));
709 if (new_files != NULL)
710 OBD_FREE(new_files, group * sizeof(*new_files));
712 if (filter->fo_subdir_count) {
713 for (i = 0; i < filter->fo_subdir_count; i++) {
714 if (tmp_subdirs->dentry[i] != NULL)
715 dput(tmp_subdirs->dentry[i]);
717 OBD_FREE(tmp_subdirs, sizeof(*tmp_subdirs));
727 static int filter_read_groups(struct obd_device *obd, int last_group,
730 struct filter_obd *filter = &obd->u.filter;
731 int old_count = filter->fo_group_count, group = old_count, rc = 0;
733 for (group = old_count; group <= last_group; group++) {
735 continue; /* no group zero */
737 rc = filter_read_group_internal(obd, group, create);
744 static int filter_prep_groups(struct obd_device *obd)
746 struct filter_obd *filter = &obd->u.filter;
747 struct dentry *dentry, *O_dentry;
748 int rc = 0, cleanup_phase = 0;
751 O_dentry = simple_mkdir(current->fs->pwd, "O", 0700, 1);
752 CDEBUG(D_INODE, "got/created O: %p\n", O_dentry);
753 if (IS_ERR(O_dentry)) {
754 rc = PTR_ERR(O_dentry);
755 CERROR("cannot open/create O: rc = %d\n", rc);
758 filter->fo_dentry_O = O_dentry;
759 cleanup_phase = 1; /* O_dentry */
761 /* Lookup "R" to tell if we're on an old OST FS and need to convert
762 * from O/R/<dir>/<objid> to O/0/<dir>/<objid>. This can be removed
763 * some time post 1.0 when all old-style OSTs have converted along
764 * with the init_objid hack. */
765 dentry = ll_lookup_one_len("R", O_dentry, 1);
767 GOTO(cleanup, rc = PTR_ERR(dentry));
768 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) {
769 struct dentry *O0_dentry = lookup_one_len("0", O_dentry, 1);
772 CWARN("converting OST to new object layout\n");
773 if (IS_ERR(O0_dentry)) {
774 rc = PTR_ERR(O0_dentry);
775 CERROR("error looking up O/0: rc %d\n", rc);
779 if (O0_dentry->d_inode) {
780 CERROR("Both O/R and O/0 exist. Fix manually.\n");
781 GOTO(cleanup_O0, rc = -EEXIST);
784 down(&O_dentry->d_inode->i_sem);
785 rc = vfs_rename(O_dentry->d_inode, dentry,
786 O_dentry->d_inode, O0_dentry);
787 up(&O_dentry->d_inode->i_sem);
790 CERROR("error renaming O/R to O/0: rc %d\n", rc);
791 GOTO(cleanup_O0, rc);
793 filter->fo_fsd->fsd_feature_incompat |=
794 cpu_to_le32(FILTER_INCOMPAT_GROUPS);
795 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
797 GOTO(cleanup_O0, rc);
809 cleanup_phase = 2; /* groups */
811 /* Group 0 is no longer a legal group, to catch uninitialized IDs */
812 #define FILTER_MIN_GROUPS 3
813 rc = filter_read_groups(obd, FILTER_MIN_GROUPS, 1);
820 switch (cleanup_phase) {
822 filter_cleanup_groups(obd);
824 f_dput(filter->fo_dentry_O);
825 filter->fo_dentry_O = NULL;
832 /* setup the object store with correct subdirectories */
833 static int filter_prep(struct obd_device *obd)
835 struct lvfs_run_ctxt saved;
836 struct filter_obd *filter = &obd->u.filter;
842 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
843 file = filp_open(LAST_RCVD, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
844 if (!file || IS_ERR(file)) {
846 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
851 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
852 CERROR("%s is not a regular file!: mode = %o\n", LAST_RCVD,
853 file->f_dentry->d_inode->i_mode);
854 GOTO(err_filp, rc = -ENOENT);
857 /* steal operations */
858 inode = file->f_dentry->d_inode;
859 filter->fo_fop = file->f_op;
860 filter->fo_iop = inode->i_op;
861 filter->fo_aops = inode->i_mapping->a_ops;
863 rc = filter_init_server_data(obd, file);
865 CERROR("cannot read %s: rc = %d\n", LAST_RCVD, rc);
868 filter->fo_rcvd_filp = file;
870 rc = filter_prep_groups(obd);
872 GOTO(err_server_data, rc);
875 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
880 //class_disconnect_exports(obd, 0);
881 filter_free_server_data(filter);
883 if (filp_close(file, 0))
884 CERROR("can't close %s after error\n", LAST_RCVD);
885 filter->fo_rcvd_filp = NULL;
889 /* cleanup the filter: write last used object id to status file */
890 static void filter_post(struct obd_device *obd)
892 struct lvfs_run_ctxt saved;
893 struct filter_obd *filter = &obd->u.filter;
896 /* XXX: filter_update_lastobjid used to call fsync_dev. It might be
897 * best to start a transaction with h_sync, because we removed this
900 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
901 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
904 CERROR("error writing server data: rc = %d\n", rc);
906 for (i = 1; i < filter->fo_group_count; i++) {
907 rc = filter_update_last_objid(obd, i,
908 (i == filter->fo_group_count - 1));
910 CERROR("error writing group %d lastobjid: rc = %d\n",
914 rc = filp_close(filter->fo_rcvd_filp, 0);
915 filter->fo_rcvd_filp = NULL;
917 CERROR("error closing %s: rc = %d\n", LAST_RCVD, rc);
919 filter_cleanup_groups(obd);
920 filter_free_server_data(filter);
921 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
924 static void filter_set_last_id(struct filter_obd *filter, int group, obd_id id)
926 LASSERT(filter->fo_fsd != NULL);
928 LASSERT(group < filter->fo_group_count);
930 spin_lock(&filter->fo_objidlock);
931 filter->fo_last_objids[group] = id;
932 spin_unlock(&filter->fo_objidlock);
935 __u64 filter_last_id(struct filter_obd *filter, int group)
938 LASSERT(filter->fo_fsd != NULL);
940 LASSERT(group < filter->fo_group_count);
942 spin_lock(&filter->fo_objidlock);
943 id = filter->fo_last_objids[group];
944 spin_unlock(&filter->fo_objidlock);
949 /* direct cut-n-paste of mds_blocking_ast() */
950 static int filter_blocking_ast(struct ldlm_lock *lock,
951 struct ldlm_lock_desc *desc,
952 void *data, int flag)
957 if (flag == LDLM_CB_CANCELING) {
958 /* Don't need to do anything here. */
962 /* XXX layering violation! -phil */
963 l_lock(&lock->l_resource->lr_namespace->ns_lock);
964 /* Get this: if filter_blocking_ast is racing with ldlm_intent_policy,
965 * such that filter_blocking_ast is called just before l_i_p takes the
966 * ns_lock, then by the time we get the lock, we might not be the
967 * correct blocking function anymore. So check, and return early, if
969 if (lock->l_blocking_ast != filter_blocking_ast) {
970 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
974 lock->l_flags |= LDLM_FL_CBPENDING;
975 do_ast = (!lock->l_readers && !lock->l_writers);
976 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
979 struct lustre_handle lockh;
982 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
983 ldlm_lock2handle(lock, &lockh);
984 rc = ldlm_cli_cancel(&lockh);
986 CERROR("ldlm_cli_cancel: %d\n", rc);
988 LDLM_DEBUG(lock, "Lock still has references, will be "
994 extern void *lock_dir(struct inode *dir, struct qstr *name);
995 extern void unlock_dir(struct inode *dir, void *lock);
997 static void * filter_lock_dentry(struct obd_device *obd,
998 struct dentry *dparent, obd_id id)
1004 qstr.len = sprintf(name, LPU64, id);
1005 return lock_dir(dparent->d_inode, &qstr);
1007 down(&dparent->d_inode->i_sem);
1012 /* We never dget the object parent, so DON'T dput it either */
1013 static void filter_parent_unlock(struct dentry *dparent, void *lock)
1016 LASSERT(lock != NULL);
1017 unlock_dir(dparent->d_inode, lock);
1019 up(&dparent->d_inode->i_sem);
1023 /* We never dget the object parent, so DON'T dput it either */
1024 struct dentry *filter_parent(struct obd_device *obd, obd_gr group, obd_id objid)
1026 struct filter_obd *filter = &obd->u.filter;
1027 LASSERT(group < filter->fo_group_count);
1030 if (filter->fo_subdir_count == 0)
1031 return filter->fo_groups[group];
1033 return filter->fo_subdirs[group].dentry[objid & (filter->fo_subdir_count - 1)];
1036 /* We never dget the object parent, so DON'T dput it either */
1037 struct dentry *filter_parent_lock(struct obd_device *obd, obd_gr group,
1038 obd_id objid, void **lock)
1040 unsigned long now = jiffies;
1041 struct dentry *dparent = filter_parent(obd, group, objid);
1043 if (IS_ERR(dparent))
1047 LASSERT(dparent->d_inode);
1049 *lock = filter_lock_dentry(obd, dparent, objid);
1050 if (time_after(jiffies, now + 15 * HZ))
1051 CERROR("slow parent lock %lus\n", (jiffies - now) / HZ);
1055 /* How to get files, dentries, inodes from object id's.
1057 * If dir_dentry is passed, the caller has already locked the parent
1058 * appropriately for this operation (normally a write lock). If
1059 * dir_dentry is NULL, we do a read lock while we do the lookup to
1060 * avoid races with create/destroy and such changing the directory
1061 * internal to the filesystem code. */
1062 struct dentry *filter_fid2dentry(struct obd_device *obd,
1063 struct dentry *dir_dentry,
1064 obd_gr group, obd_id id)
1066 struct dentry *dparent = dir_dentry;
1067 struct dentry *dchild;
1074 CERROR("fatal: invalid object id 0\n");
1075 RETURN(ERR_PTR(-ESTALE));
1078 len = sprintf(name, LPU64, id);
1079 if (dir_dentry == NULL) {
1080 dparent = filter_parent_lock(obd, group, id, &lock);
1081 if (IS_ERR(dparent))
1084 CDEBUG(D_INODE, "looking up object O/%*s/%s\n",
1085 dparent->d_name.len, dparent->d_name.name, name);
1086 dchild = /*ll_*/lookup_one_len(name, dparent, len);
1087 if (dir_dentry == NULL)
1088 filter_parent_unlock(dparent, lock);
1089 if (IS_ERR(dchild)) {
1090 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
1094 CDEBUG(D_INODE, "got child objid %s: %p, count = %d\n",
1095 name, dchild, atomic_read(&dchild->d_count));
1097 LASSERT(atomic_read(&dchild->d_count) > 0);
1102 static int filter_prepare_destroy(struct obd_device *obd, obd_id objid,
1105 struct lustre_handle lockh;
1106 int flags = LDLM_AST_DISCARD_DATA, rc;
1107 struct ldlm_res_id res_id = { .name = { objid, 0, group, 0 } };
1108 ldlm_policy_data_t policy = { .l_extent = { 0, OBD_OBJECT_EOF } };
1111 /* Tell the clients that the object is gone now and that they should
1112 * throw away any cached pages. */
1113 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, res_id,
1114 LDLM_EXTENT, &policy, LCK_PW,
1115 &flags, filter_blocking_ast, ldlm_completion_ast,
1116 NULL, NULL, NULL, 0, NULL, &lockh);
1118 /* We only care about the side-effects, just drop the lock. */
1120 ldlm_lock_decref(&lockh, LCK_PW);
1125 /* Caller must hold LCK_PW on parent and push us into kernel context.
1126 * Caller is also required to ensure that dchild->d_inode exists. */
1127 static int filter_destroy_internal(struct obd_device *obd, obd_id objid,
1128 struct dentry *dparent,
1129 struct dentry *dchild)
1131 struct inode *inode = dchild->d_inode;
1135 if (inode->i_nlink != 1 || atomic_read(&inode->i_count) != 1) {
1136 CERROR("destroying objid %*s nlink = %lu, count = %d\n",
1137 dchild->d_name.len, dchild->d_name.name,
1138 (unsigned long)inode->i_nlink,
1139 atomic_read(&inode->i_count));
1142 rc = vfs_unlink(dparent->d_inode, dchild);
1145 CERROR("error unlinking objid %*s: rc %d\n",
1146 dchild->d_name.len, dchild->d_name.name, rc);
1151 static int filter_intent_policy(struct ldlm_namespace *ns,
1152 struct ldlm_lock **lockp, void *req_cookie,
1153 ldlm_mode_t mode, int flags, void *data)
1155 struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
1156 struct ptlrpc_request *req = req_cookie;
1157 struct ldlm_lock *lock = *lockp, *l = NULL;
1158 struct ldlm_resource *res = lock->l_resource;
1159 ldlm_processing_policy policy;
1160 struct ost_lvb *res_lvb, *reply_lvb;
1161 struct list_head *tmp;
1163 int tmpflags = 0, rc, repsize[2] = {sizeof(struct ldlm_reply),
1164 sizeof(struct ost_lvb) };
1167 policy = ldlm_get_processing_policy(res);
1168 LASSERT(policy != NULL);
1169 LASSERT(req != NULL);
1171 rc = lustre_pack_reply(req, 2, repsize, NULL);
1173 RETURN(req->rq_status = rc);
1175 reply_lvb = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*reply_lvb));
1176 LASSERT(reply_lvb != NULL);
1178 //fixup_handle_for_resent_req(req, lock, &lockh);
1180 /* If we grant any lock at all, it will be a whole-file read lock.
1181 * Call the extent policy function to see if our request can be
1182 * granted, or is blocked. */
1183 lock->l_policy_data.l_extent.start = 0;
1184 lock->l_policy_data.l_extent.end = OBD_OBJECT_EOF;
1185 lock->l_req_mode = LCK_PR;
1187 l_lock(&res->lr_namespace->ns_lock);
1189 res->lr_tmp = &rpc_list;
1190 rc = policy(lock, &tmpflags, 0, &err);
1193 /* FIXME: we should change the policy function slightly, to not make
1194 * this list at all, since we just turn around and free it */
1195 while (!list_empty(&rpc_list)) {
1196 struct ldlm_ast_work *w =
1197 list_entry(rpc_list.next, struct ldlm_ast_work, w_list);
1198 list_del(&w->w_list);
1199 LDLM_LOCK_PUT(w->w_lock);
1200 OBD_FREE(w, sizeof(*w));
1203 if (rc == LDLM_ITER_CONTINUE) {
1204 /* The lock met with no resistance; we're finished. */
1205 l_unlock(&res->lr_namespace->ns_lock);
1206 RETURN(ELDLM_LOCK_REPLACED);
1209 /* Do not grant any lock, but instead send GL callbacks. The extent
1210 * policy nicely created a list of all PW locks for us. We will choose
1211 * the highest of those which are larger than the size in the LVB, if
1212 * any, and perform a glimpse callback. */
1213 down(&res->lr_lvb_sem);
1214 res_lvb = res->lr_lvb_data;
1215 LASSERT(res_lvb != NULL);
1216 reply_lvb->lvb_size = res_lvb->lvb_size;
1217 reply_lvb->lvb_blocks = res_lvb->lvb_blocks;
1218 up(&res->lr_lvb_sem);
1220 list_for_each(tmp, &res->lr_granted) {
1221 struct ldlm_lock *tmplock =
1222 list_entry(tmp, struct ldlm_lock, l_res_link);
1224 if (tmplock->l_granted_mode == LCK_PR)
1227 if (tmplock->l_policy_data.l_extent.end <= reply_lvb->lvb_size)
1231 l = LDLM_LOCK_GET(tmplock);
1235 if (l->l_policy_data.l_extent.start >
1236 tmplock->l_policy_data.l_extent.start)
1240 l = LDLM_LOCK_GET(tmplock);
1242 l_unlock(&res->lr_namespace->ns_lock);
1244 /* There were no PW locks beyond the size in the LVB; finished. */
1246 RETURN(ELDLM_LOCK_ABORTED);
1248 LASSERT(l->l_glimpse_ast != NULL);
1249 rc = l->l_glimpse_ast(l, NULL); /* this will update the LVB */
1250 if (rc != 0 && res->lr_namespace->ns_lvbo &&
1251 res->lr_namespace->ns_lvbo->lvbo_update) {
1252 res->lr_namespace->ns_lvbo->lvbo_update(res, NULL, 0, 1);
1255 down(&res->lr_lvb_sem);
1256 reply_lvb->lvb_size = res_lvb->lvb_size;
1257 reply_lvb->lvb_blocks = res_lvb->lvb_blocks;
1258 up(&res->lr_lvb_sem);
1262 RETURN(ELDLM_LOCK_ABORTED);
1265 static int filter_post_fs_cleanup(struct obd_device *obd)
1269 rc = fsfilt_post_cleanup(obd);
1274 static int filter_group_set_fs_flags(struct obd_device *obd, int group)
1276 struct filter_obd *filter = &obd->u.filter;
1280 /* zero group is not longer valid. */
1283 for (i = 0; i < filter->fo_subdir_count; i++) {
1284 struct dentry *dentry;
1285 dentry = (filter->fo_subdirs + group)->dentry[i];
1286 rc = fsfilt_set_fs_flags(obd, dentry->d_inode,
1287 SM_DO_REC | SM_DO_COW);
1293 static int filter_post_fs_setup(struct obd_device *obd)
1295 struct filter_obd *filter = &obd->u.filter;
1297 struct llog_ctxt *ctxt = NULL;
1299 rc = fsfilt_post_setup(obd);
1303 for (j = 0; j < filter->fo_group_count; j++) {
1304 rc = filter_group_set_fs_flags(obd, j);
1309 fsfilt_get_reint_log_ctxt(obd, filter->fo_sb, &ctxt);
1311 ctxt->loc_obd = obd;
1312 ctxt->loc_idx = LLOG_REINT_ORIG_CTXT;
1313 obd->obd_llog_ctxt[LLOG_REINT_ORIG_CTXT] = ctxt;
1315 fsfilt_set_ost_flags(obd, filter->fo_sb);
1319 /* mount the file system (secretly) */
1320 int filter_common_setup(struct obd_device *obd, obd_count len,
1321 void *buf, char *option)
1323 struct lustre_cfg* lcfg = buf;
1324 struct filter_obd *filter = &obd->u.filter;
1325 struct vfsmount *mnt;
1326 char name[32] = "CATLIST";
1330 dev_clear_rdonly(2);
1332 if (!lcfg->lcfg_inlbuf1 || !lcfg->lcfg_inlbuf2)
1335 obd->obd_fsops = fsfilt_get_ops(lcfg->lcfg_inlbuf2);
1336 if (IS_ERR(obd->obd_fsops))
1337 RETURN(PTR_ERR(obd->obd_fsops));
1339 mnt = do_kern_mount(lcfg->lcfg_inlbuf2, MS_NOATIME | MS_NODIRATIME,
1340 lcfg->lcfg_inlbuf1, option);
1345 if (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3) {
1346 if (*lcfg->lcfg_inlbuf3 == 'f') {
1347 obd->obd_replayable = 1;
1348 obd_sync_filter = 1;
1349 CWARN("%s: recovery enabled\n", obd->obd_name);
1351 if (*lcfg->lcfg_inlbuf3 != 'n') {
1352 CERROR("unrecognised flag '%c'\n",
1353 *lcfg->lcfg_inlbuf3);
1355 // XXX Robert? Why do we get errors here
1356 // GOTO(err_mntput, rc = -EINVAL);
1360 filter->fo_vfsmnt = mnt;
1361 filter->fo_sb = mnt->mnt_sb;
1362 filter->fo_fstype = mnt->mnt_sb->s_type->name;
1363 CDEBUG(D_SUPER, "%s: mnt = %p\n", filter->fo_fstype, mnt);
1365 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1366 obd->obd_lvfs_ctxt.pwdmnt = mnt;
1367 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
1368 obd->obd_lvfs_ctxt.fs = get_ds();
1369 obd->obd_lvfs_ctxt.cb_ops = filter_lvfs_ops;
1371 rc = fsfilt_setup(obd, mnt->mnt_sb);
1373 GOTO(err_mntput, rc);
1375 rc = filter_prep(obd);
1377 GOTO(err_mntput, rc);
1380 filter->fo_destroy_in_progress = 0;
1381 sema_init(&filter->fo_create_lock, 1);
1383 spin_lock_init(&filter->fo_translock);
1384 spin_lock_init(&filter->fo_objidlock);
1385 INIT_LIST_HEAD(&filter->fo_export_list);
1386 sema_init(&filter->fo_alloc_lock, 1);
1387 spin_lock_init(&filter->fo_r_pages.oh_lock);
1388 spin_lock_init(&filter->fo_w_pages.oh_lock);
1389 spin_lock_init(&filter->fo_r_discont_pages.oh_lock);
1390 spin_lock_init(&filter->fo_w_discont_pages.oh_lock);
1391 spin_lock_init(&filter->fo_r_discont_blocks.oh_lock);
1392 spin_lock_init(&filter->fo_w_discont_blocks.oh_lock);
1393 filter->fo_readcache_max_filesize = FILTER_MAX_CACHE_SIZE;
1395 INIT_LIST_HEAD(&filter->fo_llog_list);
1396 spin_lock_init(&filter->fo_llog_list_lock);
1398 obd->obd_namespace = ldlm_namespace_new("filter-tgt",
1399 LDLM_NAMESPACE_SERVER);
1400 if (obd->obd_namespace == NULL)
1401 GOTO(err_post, rc = -ENOMEM);
1402 obd->obd_namespace->ns_lvbp = obd;
1403 obd->obd_namespace->ns_lvbo = &filter_lvbo;
1404 ldlm_register_intent(obd->obd_namespace, filter_intent_policy);
1406 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1407 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
1409 rc = obd_llog_cat_initialize(obd, &obd->obd_llogs, 1, name);
1411 CERROR("failed to setup llogging subsystems\n");
1424 fsfilt_put_ops(obd->obd_fsops);
1428 static int filter_attach(struct obd_device *obd, obd_count len, void *data)
1430 struct lprocfs_static_vars lvars;
1433 lprocfs_init_vars(filter, &lvars);
1434 rc = lprocfs_obd_attach(obd, lvars.obd_vars);
1438 rc = lprocfs_alloc_obd_stats(obd, LPROC_FILTER_LAST);
1442 /* Init obdfilter private stats here */
1443 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_READ_BYTES,
1444 LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
1445 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_WRITE_BYTES,
1446 LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
1448 return lproc_filter_attach_seqstat(obd);
1451 static int filter_detach(struct obd_device *dev)
1453 lprocfs_free_obd_stats(dev);
1454 return lprocfs_obd_detach(dev);
1457 static int filter_setup(struct obd_device *obd, obd_count len, void *buf)
1459 struct lustre_cfg* lcfg = buf;
1462 /* all mount options including errors=remount-ro and asyncdel are passed
1463 * using 4th lcfg param. And it is good, finally we have got rid of
1464 * hardcoded fs types in the code. */
1465 rc = filter_common_setup(obd, len, buf, lcfg->lcfg_inlbuf4);
1468 rc = filter_post_fs_setup(obd);
1472 static int filter_cleanup(struct obd_device *obd, int flags)
1474 struct filter_obd *filter = &obd->u.filter;
1477 if (flags & OBD_OPT_FAILOVER)
1478 CERROR("%s: shutting down for failover; client state will"
1479 " be preserved.\n", obd->obd_name);
1481 if (!list_empty(&obd->obd_exports)) {
1482 CERROR("%s: still has clients!\n", obd->obd_name);
1483 class_disconnect_exports(obd, flags);
1484 if (!list_empty(&obd->obd_exports)) {
1485 CERROR("still has exports after forced cleanup?\n");
1490 ldlm_namespace_free(obd->obd_namespace, flags & OBD_OPT_FORCE);
1492 if (filter->fo_sb == NULL)
1495 filter_post_fs_cleanup(obd);
1498 shrink_dcache_parent(filter->fo_sb->s_root);
1501 if (atomic_read(&filter->fo_vfsmnt->mnt_count) > 1)
1502 CERROR("%s: mount point %p busy, mnt_count: %d\n",
1503 obd->obd_name, filter->fo_vfsmnt,
1504 atomic_read(&filter->fo_vfsmnt->mnt_count));
1507 mntput(filter->fo_vfsmnt);
1508 //destroy_buffers(filter->fo_sb->s_dev);
1509 filter->fo_sb = NULL;
1510 fsfilt_put_ops(obd->obd_fsops);
1513 dev_clear_rdonly(2);
1518 /* nearly identical to mds_connect */
1519 static int filter_connect(struct lustre_handle *conn, struct obd_device *obd,
1520 struct obd_uuid *cluuid)
1522 struct obd_export *exp;
1523 struct filter_export_data *fed;
1524 struct filter_client_data *fcd = NULL;
1525 struct filter_obd *filter = &obd->u.filter;
1529 if (conn == NULL || obd == NULL || cluuid == NULL)
1532 rc = class_connect(conn, obd, cluuid);
1535 exp = class_conn2export(conn);
1536 LASSERT(exp != NULL);
1538 fed = &exp->exp_filter_data;
1540 spin_lock_init(&fed->fed_lock);
1542 if (!obd->obd_replayable)
1543 GOTO(cleanup, rc = 0);
1545 OBD_ALLOC(fcd, sizeof(*fcd));
1547 CERROR("filter: out of memory for client data\n");
1548 GOTO(cleanup, rc = -ENOMEM);
1551 memcpy(fcd->fcd_uuid, cluuid, sizeof(fcd->fcd_uuid));
1554 rc = filter_client_add(obd, filter, fed, -1);
1559 OBD_FREE(fcd, sizeof(*fcd));
1560 class_disconnect(exp, 0);
1562 class_export_put(exp);
1567 static int filter_precleanup(struct obd_device *obd, int flags)
1569 struct filter_group_llog *log;
1570 struct filter_obd *filter;
1574 filter = &obd->u.filter;
1576 spin_lock(&filter->fo_llog_list_lock);
1577 while (!list_empty(&filter->fo_llog_list)) {
1578 log = list_entry(filter->fo_llog_list.next,
1579 struct filter_group_llog, list);
1580 list_del(&log->list);
1581 spin_unlock(&filter->fo_llog_list_lock);
1583 rc = obd_llog_finish(obd, log->llogs, 0);
1585 CERROR("failed to cleanup llogging subsystem for %u\n",
1587 OBD_FREE(log->llogs, sizeof(*(log->llogs)));
1588 OBD_FREE(log, sizeof(*log));
1589 spin_lock(&filter->fo_llog_list_lock);
1591 spin_unlock(&filter->fo_llog_list_lock);
1593 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1595 CERROR("failed to cleanup llogging subsystem\n");
1600 /* Do extra sanity checks for grant accounting. We do this at connect,
1601 * disconnect, and statfs RPC time, so it shouldn't be too bad. We can
1602 * always get rid of it or turn it off when we know accounting is good. */
1603 static void filter_grant_sanity_check(struct obd_device *obd, const char *func)
1605 struct filter_export_data *fed;
1606 struct obd_export *exp;
1607 obd_size maxsize = obd->obd_osfs.os_blocks * obd->obd_osfs.os_bsize;
1608 obd_size tot_dirty = 0, tot_pending = 0, tot_granted = 0;
1609 obd_size fo_tot_dirty, fo_tot_pending, fo_tot_granted;
1611 if (list_empty(&obd->obd_exports))
1614 spin_lock(&obd->obd_osfs_lock);
1615 spin_lock(&obd->obd_dev_lock);
1616 list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
1617 fed = &exp->exp_filter_data;
1618 LASSERTF(fed->fed_grant + fed->fed_pending <= maxsize,
1619 "cli %s/%p %lu+%lu > "LPU64"\n",
1620 exp->exp_client_uuid.uuid, exp,
1621 fed->fed_grant, fed->fed_pending, maxsize);
1622 LASSERTF(fed->fed_dirty <= maxsize, "cli %s/%p %lu > "LPU64"\n",
1623 exp->exp_client_uuid.uuid, exp,fed->fed_dirty,maxsize);
1624 CDEBUG(D_CACHE,"%s: cli %s/%p dirty %lu pend %lu grant %lu\n",
1625 obd->obd_name, exp->exp_client_uuid.uuid, exp,
1626 fed->fed_dirty, fed->fed_pending, fed->fed_grant);
1627 tot_granted += fed->fed_grant + fed->fed_pending;
1628 tot_pending += fed->fed_pending;
1629 tot_dirty += fed->fed_dirty;
1631 fo_tot_granted = obd->u.filter.fo_tot_granted;
1632 fo_tot_pending = obd->u.filter.fo_tot_pending;
1633 fo_tot_dirty = obd->u.filter.fo_tot_dirty;
1634 spin_unlock(&obd->obd_dev_lock);
1635 spin_unlock(&obd->obd_osfs_lock);
1637 /* Do these assertions outside the spinlocks so we don't kill system */
1638 if (tot_granted != fo_tot_granted)
1639 CERROR("%s: tot_granted "LPU64" != fo_tot_granted "LPU64"\n",
1640 func, tot_granted, fo_tot_granted);
1641 if (tot_pending != fo_tot_pending)
1642 CERROR("%s: tot_pending "LPU64" != fo_tot_pending "LPU64"\n",
1643 func, tot_pending, fo_tot_pending);
1644 if (tot_dirty != fo_tot_dirty)
1645 CERROR("%s: tot_dirty "LPU64" != fo_tot_dirty "LPU64"\n",
1646 func, tot_dirty, fo_tot_dirty);
1647 if (tot_pending > tot_granted)
1648 CERROR("%s: tot_pending "LPU64" > tot_granted "LPU64"\n",
1649 func, tot_pending, tot_granted);
1650 if (tot_granted > maxsize)
1651 CERROR("%s: tot_granted "LPU64" > maxsize "LPU64"\n",
1652 func, tot_granted, maxsize);
1653 if (tot_dirty > maxsize)
1654 CERROR("%s: tot_dirty "LPU64" > maxsize "LPU64"\n",
1655 func, tot_dirty, maxsize);
1658 /* Remove this client from the grant accounting totals. We also remove
1659 * the export from the obd device under the osfs and dev locks to ensure
1660 * that the filter_grant_sanity_check() calculations are always valid.
1661 * The client should do something similar when it invalidates its import. */
1662 static void filter_grant_discard(struct obd_export *exp)
1664 struct obd_device *obd = exp->exp_obd;
1665 struct filter_obd *filter = &obd->u.filter;
1666 struct filter_export_data *fed = &exp->exp_filter_data;
1668 spin_lock(&obd->obd_osfs_lock);
1669 spin_lock(&exp->exp_obd->obd_dev_lock);
1670 list_del_init(&exp->exp_obd_chain);
1671 spin_unlock(&exp->exp_obd->obd_dev_lock);
1673 CDEBUG(D_CACHE, "%s: cli %s/%p dirty %lu pend %lu grant %lu\n",
1674 obd->obd_name, exp->exp_client_uuid.uuid, exp,
1675 fed->fed_dirty, fed->fed_pending, fed->fed_grant);
1677 LASSERTF(filter->fo_tot_granted >= fed->fed_grant,
1678 "%s: tot_granted "LPU64" cli %s/%p fed_grant %lu\n",
1679 obd->obd_name, filter->fo_tot_granted,
1680 exp->exp_client_uuid.uuid, exp, fed->fed_grant);
1681 filter->fo_tot_granted -= fed->fed_grant;
1682 LASSERTF(exp->exp_obd->u.filter.fo_tot_pending >= fed->fed_pending,
1683 "%s: tot_pending "LPU64" cli %s/%p fed_pending %lu\n",
1684 obd->obd_name, filter->fo_tot_pending,
1685 exp->exp_client_uuid.uuid, exp, fed->fed_pending);
1686 LASSERTF(filter->fo_tot_dirty >= fed->fed_dirty,
1687 "%s: tot_dirty "LPU64" cli %s/%p fed_dirty %lu\n",
1688 obd->obd_name, filter->fo_tot_dirty,
1689 exp->exp_client_uuid.uuid, exp, fed->fed_dirty);
1690 filter->fo_tot_dirty -= fed->fed_dirty;
1694 spin_unlock(&obd->obd_osfs_lock);
1697 static int filter_destroy_export(struct obd_export *exp)
1701 if (exp->exp_filter_data.fed_pending)
1702 CERROR("%s: cli %s/%p has %lu pending on destroyed export\n",
1703 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
1704 exp, exp->exp_filter_data.fed_pending);
1706 target_destroy_export(exp);
1708 if (exp->exp_obd->obd_replayable)
1709 filter_client_free(exp, exp->exp_flags);
1711 filter_grant_discard(exp);
1712 if (!(exp->exp_flags & OBD_OPT_FORCE))
1713 filter_grant_sanity_check(exp->exp_obd, __FUNCTION__);
1718 static void filter_sync_llogs(struct obd_export *dexp)
1720 struct filter_group_llog *fglog, *nlog;
1721 struct obd_device *obd = dexp->exp_obd;
1722 struct filter_obd *filter;
1723 int worked = 0, group;
1724 struct llog_ctxt *ctxt;
1726 filter = &obd->u.filter;
1728 /* we can't sync log holding spinlock. also, we do not want to get
1729 * into livelock. so we do following: loop over MDS's exports in
1730 * group order and skip already synced llogs -bzzz */
1732 /* look for group with min. number, but > worked */
1735 spin_lock(&filter->fo_llog_list_lock);
1736 list_for_each_entry(nlog, &filter->fo_llog_list, list) {
1738 if (nlog->group <= worked) {
1739 /* this group is already synced */
1743 if (group < nlog->group) {
1744 /* we have group with smaller number to sync */
1748 /* store current minimal group */
1750 group = nlog->group;
1752 spin_unlock(&filter->fo_llog_list_lock);
1755 worked = fglog->group;
1756 ctxt = llog_get_context(fglog->llogs,
1757 LLOG_UNLINK_REPL_CTXT);
1758 llog_sync(ctxt, dexp);
1760 } while (fglog != NULL);
1763 /* also incredibly similar to mds_disconnect */
1764 static int filter_disconnect(struct obd_export *exp, int flags)
1766 struct obd_device *obd = exp->exp_obd;
1767 unsigned long irqflags;
1772 class_export_get(exp);
1774 spin_lock_irqsave(&exp->exp_lock, irqflags);
1775 exp->exp_flags = flags;
1776 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
1778 if (!(flags & OBD_OPT_FORCE))
1779 filter_grant_sanity_check(obd, __FUNCTION__);
1780 filter_grant_discard(exp);
1782 /* Disconnect early so that clients can't keep using export */
1783 rc = class_disconnect(exp, flags);
1785 ldlm_cancel_locks_for_export(exp);
1787 fsfilt_sync(obd, obd->u.filter.fo_sb);
1789 /* flush any remaining cancel messages out to the target */
1790 filter_sync_llogs(exp);
1792 class_export_put(exp);
1796 struct dentry *__filter_oa2dentry(struct obd_device *obd,
1797 struct obdo *oa, const char *what)
1799 struct dentry *dchild = NULL;
1802 if (oa->o_valid & OBD_MD_FLGROUP)
1805 dchild = filter_fid2dentry(obd, NULL, group, oa->o_id);
1807 if (IS_ERR(dchild)) {
1808 CERROR("%s error looking up object: "LPU64"\n", what, oa->o_id);
1812 if (dchild->d_inode == NULL) {
1813 CERROR("%s: %s on non-existent object: "LPU64"\n",
1814 obd->obd_name, what, oa->o_id);
1816 RETURN(ERR_PTR(-ENOENT));
1822 static int filter_getattr(struct obd_export *exp, struct obdo *oa,
1823 struct lov_stripe_md *md)
1825 struct dentry *dentry = NULL;
1826 struct obd_device *obd;
1830 obd = class_exp2obd(exp);
1832 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1833 exp->exp_handle.h_cookie);
1837 dentry = filter_oa2dentry(obd, oa);
1839 RETURN(PTR_ERR(dentry));
1841 /* Limit the valid bits in the return data to what we actually use */
1842 oa->o_valid = OBD_MD_FLID;
1843 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
1849 /* this is called from filter_truncate() until we have filter_punch() */
1850 static int filter_setattr(struct obd_export *exp, struct obdo *oa,
1851 struct lov_stripe_md *md, struct obd_trans_info *oti)
1853 struct lvfs_run_ctxt saved;
1854 struct filter_obd *filter;
1855 struct dentry *dentry;
1857 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0 } };
1858 struct ldlm_resource *res;
1863 LASSERT(oti != NULL);
1865 dentry = filter_oa2dentry(exp->exp_obd, oa);
1867 RETURN(PTR_ERR(dentry));
1869 filter = &exp->exp_obd->u.filter;
1871 iattr_from_obdo(&iattr, oa, oa->o_valid);
1873 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
1876 if (iattr.ia_valid & ATTR_SIZE)
1877 down(&dentry->d_inode->i_sem);
1878 handle = fsfilt_start(exp->exp_obd, dentry->d_inode, FSFILT_OP_SETATTR,
1881 GOTO(out_unlock, rc = PTR_ERR(handle));
1883 /* XXX this could be a rwsem instead, if filter_preprw played along */
1884 if (iattr.ia_valid & ATTR_ATTR_FLAG)
1885 rc = fsfilt_iocontrol(exp->exp_obd, dentry->d_inode, NULL,
1887 (long)&iattr.ia_attr_flags);
1889 rc = fsfilt_setattr(exp->exp_obd, dentry, handle, &iattr, 1);
1890 rc = filter_finish_transno(exp, oti, rc);
1891 rc2 = fsfilt_commit(exp->exp_obd, filter->fo_sb, dentry->d_inode, handle, 0);
1893 CERROR("error on commit, err = %d\n", rc2);
1898 if (iattr.ia_valid & ATTR_SIZE) {
1899 res = ldlm_resource_get(exp->exp_obd->obd_namespace, NULL,
1900 res_id, LDLM_EXTENT, 0);
1902 CERROR("!!! resource_get failed for object "LPU64" -- "
1903 "filter_setattr with no lock?\n", oa->o_id);
1905 if (res->lr_namespace->ns_lvbo &&
1906 res->lr_namespace->ns_lvbo->lvbo_update) {
1907 rc = res->lr_namespace->ns_lvbo->lvbo_update
1910 ldlm_resource_putref(res);
1914 oa->o_valid = OBD_MD_FLID;
1915 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
1918 if (iattr.ia_valid & ATTR_SIZE)
1919 up(&dentry->d_inode->i_sem);
1921 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
1927 /* XXX identical to osc_unpackmd */
1928 static int filter_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
1929 struct lov_mds_md *lmm, int lmm_bytes)
1935 if (lmm_bytes < sizeof (*lmm)) {
1936 CERROR("lov_mds_md too small: %d, need %d\n",
1937 lmm_bytes, (int)sizeof(*lmm));
1940 /* XXX LOV_MAGIC etc check? */
1942 if (lmm->lmm_object_id == cpu_to_le64(0)) {
1943 CERROR("lov_mds_md: zero lmm_object_id\n");
1948 lsm_size = lov_stripe_md_size(1);
1952 if (*lsmp != NULL && lmm == NULL) {
1953 OBD_FREE(*lsmp, lsm_size);
1958 if (*lsmp == NULL) {
1959 OBD_ALLOC(*lsmp, lsm_size);
1963 loi_init((*lsmp)->lsm_oinfo);
1967 /* XXX zero *lsmp? */
1968 (*lsmp)->lsm_object_id = le64_to_cpu (lmm->lmm_object_id);
1969 LASSERT((*lsmp)->lsm_object_id);
1972 (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
1977 static void filter_destroy_precreated(struct obd_export *exp, struct obdo *oa,
1978 struct filter_obd *filter)
1980 struct obdo doa; /* XXX obdo on stack */
1985 memset(&doa, 0, sizeof(doa));
1986 if (oa->o_valid & OBD_MD_FLGROUP) {
1987 doa.o_valid |= OBD_MD_FLGROUP;
1988 doa.o_gr = oa->o_gr;
1992 doa.o_mode = S_IFREG;
1993 doa.o_gr = oa->o_gr;
1994 doa.o_valid = oa->o_valid & OBD_MD_FLGROUP;
1996 filter->fo_destroy_in_progress = 1;
1997 down(&filter->fo_create_lock);
1998 if (!filter->fo_destroy_in_progress) {
1999 CERROR("%s: destroy_in_progress already cleared\n",
2000 exp->exp_obd->obd_name);
2001 up(&filter->fo_create_lock);
2006 last = filter_last_id(filter, doa.o_gr);
2007 CWARN("%s: deleting orphan objects from "LPU64" to "LPU64"\n",
2008 exp->exp_obd->obd_name, oa->o_id + 1, last);
2009 for (id = oa->o_id + 1; id <= last; id++) {
2011 filter_destroy(exp, &doa, NULL, NULL);
2014 CDEBUG(D_HA, "%s: after destroy: set last_objids["LPU64"] = "LPU64"\n",
2015 exp->exp_obd->obd_name, doa.o_gr, oa->o_id);
2017 spin_lock(&filter->fo_objidlock);
2018 filter->fo_last_objids[doa.o_gr] = oa->o_id;
2019 spin_unlock(&filter->fo_objidlock);
2021 filter->fo_destroy_in_progress = 0;
2022 up(&filter->fo_create_lock);
2027 /* returns a negative error or a nonnegative number of files to create */
2028 static int filter_should_precreate(struct obd_export *exp, struct obdo *oa,
2031 struct obd_device *obd = exp->exp_obd;
2032 struct filter_obd *filter = &obd->u.filter;
2036 diff = oa->o_id - filter_last_id(filter, oa->o_gr);
2037 CDEBUG(D_INFO, "filter_last_id() = "LPU64" -> diff = %d\n",
2038 filter_last_id(filter, oa->o_gr), diff);
2040 /* delete orphans request */
2041 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2042 (oa->o_flags & OBD_FL_DELORPHAN)) {
2045 if (-diff > 10000) { /* XXX make this smarter */
2046 CERROR("ignoring bogus orphan destroy request: obdid "
2047 LPU64" last_id "LPU64"\n",
2048 oa->o_id, filter_last_id(filter, oa->o_gr));
2051 filter_destroy_precreated(exp, oa, filter);
2052 rc = filter_update_last_objid(obd, group, 0);
2054 CERROR("unable to write lastobjid, but orphans"
2058 /* only precreate if group == 0 and o_id is specfied */
2059 if (!(oa->o_valid & OBD_FL_DELORPHAN) &&
2060 (/*group != 0 ||*/ oa->o_id == 0))
2067 static int filter_precreate_rec(struct obd_device *obd, struct dentry *dentry,
2068 int *number, struct obdo *oa)
2073 rc = fsfilt_precreate_rec(obd, dentry, number, oa);
2078 /* We rely on the fact that only one thread will be creating files in a given
2079 * group at a time, which is why we don't need an atomic filter_get_new_id.
2080 * Even if we had that atomic function, the following race would exist:
2082 * thread 1: gets id x from filter_next_id
2083 * thread 2: gets id (x + 1) from filter_next_id
2084 * thread 2: creates object (x + 1)
2085 * thread 1: tries to create object x, gets -ENOSPC
2087 static int filter_precreate(struct obd_device *obd, struct obdo *oa,
2088 obd_gr group, int *num)
2090 struct dentry *dchild = NULL, *dparent = NULL;
2091 struct filter_obd *filter;
2092 int err = 0, rc = 0, recreate_obj = 0, i;
2094 void *handle = NULL;
2098 filter = &obd->u.filter;
2100 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2101 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2105 CDEBUG(D_HA, "%s: precreating %d objects\n", obd->obd_name, *num);
2107 down(&filter->fo_create_lock);
2109 for (i = 0; i < *num && err == 0; i++) {
2110 int cleanup_phase = 0;
2112 if (filter->fo_destroy_in_progress) {
2113 CWARN("%s: precreate aborted by destroy\n",
2121 last_id = filter_last_id(filter, group);
2122 if (next_id > last_id) {
2123 CERROR("Error: Trying to recreate obj greater"
2124 "than last id "LPD64" > "LPD64"\n",
2126 GOTO(cleanup, rc = -EINVAL);
2129 next_id = filter_last_id(filter, group) + 1;
2132 CDEBUG(D_INFO, "precreate objid "LPU64"\n", next_id);
2134 dparent = filter_parent_lock(obd, group, next_id, &lock);
2135 if (IS_ERR(dparent))
2136 GOTO(cleanup, rc = PTR_ERR(dparent));
2139 /*only do precreate rec record. so clean kml flags here*/
2140 fsfilt_clear_fs_flags(obd, dparent->d_inode,
2143 dchild = filter_fid2dentry(obd, dparent, group, next_id);
2145 GOTO(cleanup, rc = PTR_ERR(dchild));
2148 if (dchild->d_inode != NULL) {
2149 /* This would only happen if lastobjid was bad on disk*/
2150 /* Could also happen if recreating missing obj but
2154 CERROR("%s: Serious error: recreating obj %*s "
2155 "but obj already exists \n",
2156 obd->obd_name, dchild->d_name.len,
2157 dchild->d_name.name);
2160 CERROR("%s: Serious error: objid %*s already "
2161 "exists; is this filesystem corrupt?\n",
2162 obd->obd_name, dchild->d_name.len,
2163 dchild->d_name.name);
2166 GOTO(cleanup, rc = -EEXIST);
2169 handle = fsfilt_start_log(obd, dparent->d_inode,
2170 FSFILT_OP_CREATE, NULL, 1);
2172 GOTO(cleanup, rc = PTR_ERR(handle));
2175 rc = ll_vfs_create(dparent->d_inode, dchild, S_IFREG, NULL);
2177 CERROR("create failed rc = %d\n", rc);
2181 if (!recreate_obj) {
2182 filter_set_last_id(filter, group, next_id);
2183 err = filter_update_last_objid(obd, group, 0);
2185 CERROR("unable to write lastobjid "
2186 "but file created\n");
2188 fsfilt_set_fs_flags(obd, dparent->d_inode, SM_DO_REC);
2191 switch(cleanup_phase) {
2193 err = fsfilt_commit(obd, filter->fo_sb, dparent->d_inode, handle, 0);
2195 CERROR("error on commit, err = %d\n", err);
2202 filter_parent_unlock(dparent, lock);
2213 /* check if we have an error after ll_vfs_create(). It is possible that
2214 * there will be say -ENOSPC and we will leak it. */
2216 rc = filter_precreate_rec(obd, dparent, num, oa);
2218 up(&filter->fo_create_lock);
2220 CDEBUG(D_HA, "%s: server last_objid for group "LPU64": "LPU64"\n",
2221 obd->obd_name, group, filter->fo_last_objids[group]);
2223 CDEBUG(D_HA, "%s: filter_precreate() created %d objects\n",
2229 static int filter_create(struct obd_export *exp, struct obdo *oa,
2230 struct lov_stripe_md **ea, struct obd_trans_info *oti)
2232 struct obd_device *obd = NULL;
2233 struct filter_obd *filter;
2234 struct lvfs_run_ctxt saved;
2235 struct lov_stripe_md *lsm = NULL;
2236 struct filter_export_data *fed;
2237 char str[PTL_NALFMT_SIZE];
2238 int group = oa->o_gr, rc = 0, diff, recreate_objs = 0;
2241 if (!(oa->o_valid & OBD_MD_FLGROUP) || group == 0) {
2242 portals_nid2str(exp->exp_connection->c_peer.peer_ni->pni_number,
2243 exp->exp_connection->c_peer.peer_nid, str);
2244 CERROR("!!! nid "LPX64"/%s sent invalid object group %d\n",
2245 exp->exp_connection->c_peer.peer_nid, str, group);
2249 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2250 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2255 fed = &exp->exp_filter_data;
2256 filter = &obd->u.filter;
2258 if (fed->fed_group != group && !recreate_objs &&
2259 !(oa->o_valid & OBD_MD_REINT)) {
2260 portals_nid2str(exp->exp_connection->c_peer.peer_ni->pni_number,
2261 exp->exp_connection->c_peer.peer_nid, str);
2262 CERROR("!!! This export (nid "LPX64"/%s) used object group %d "
2263 "earlier; now it's trying to use group %d! This could "
2264 "be a bug in the MDS. Tell CFS.\n",
2265 exp->exp_connection->c_peer.peer_nid, str,
2266 fed->fed_group, group);
2270 CDEBUG(D_INFO, "filter_create(od->o_gr=%d,od->o_id="LPU64")\n",
2275 rc = obd_alloc_memmd(exp, &lsm);
2282 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2284 if (oa->o_valid & OBD_MD_REINT) {
2285 int num = *((int*)oa->o_inline);
2286 rc = filter_precreate(obd, oa, oa->o_gr, &num);
2287 } else if (recreate_objs) {
2288 if (oa->o_id > filter_last_id(&obd->u.filter, group)) {
2289 CERROR("recreate objid "LPU64" > last id "LPU64"\n",
2290 oa->o_id, filter_last_id(&obd->u.filter, group));
2294 rc = filter_precreate(obd, oa, group, &diff);
2297 diff = filter_should_precreate(exp, oa, group);
2299 oa->o_id = filter_last_id(&obd->u.filter, group);
2300 rc = filter_precreate(obd, oa, group, &diff);
2302 oa->o_valid = OBD_MD_FLID;
2306 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2307 if (rc && ea != NULL && *ea != lsm) {
2308 obd_free_memmd(exp, &lsm);
2309 } else if (rc == 0 && ea != NULL) {
2310 /* XXX LOV STACKING: the lsm that is passed to us from
2311 * LOV does not have valid lsm_oinfo data structs, so
2312 * don't go touching that. This needs to be fixed in a
2314 lsm->lsm_object_id = oa->o_id;
2315 lsm->lsm_object_gr = oa->o_gr;
2322 static int filter_destroy(struct obd_export *exp, struct obdo *oa,
2323 struct lov_stripe_md *ea, struct obd_trans_info *oti)
2325 struct obd_device *obd;
2326 struct filter_obd *filter;
2327 struct dentry *dchild = NULL, *dparent = NULL;
2328 struct lvfs_run_ctxt saved;
2329 void *handle = NULL;
2330 struct llog_cookie *fcc = NULL;
2331 int rc, rc2, cleanup_phase = 0, have_prepared = 0;
2335 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
2338 filter = &obd->u.filter;
2340 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2343 dparent = filter_parent_lock(obd, oa->o_gr, oa->o_id, &lock);
2344 if (IS_ERR(dparent))
2345 GOTO(cleanup, rc = PTR_ERR(dparent));
2348 dchild = filter_fid2dentry(obd, dparent, oa->o_gr, oa->o_id);
2350 GOTO(cleanup, rc = -ENOENT);
2353 if (dchild->d_inode == NULL) {
2354 CDEBUG(D_INODE, "destroying non-existent object "LPU64"\n",
2356 GOTO(cleanup, rc = -ENOENT);
2359 if (!have_prepared) {
2360 /* If we're really going to destroy the object, get ready
2361 * by getting the clients to discard their cached data.
2363 * We have to drop the parent lock, because
2364 * filter_prepare_destroy will acquire a PW on the object, and
2365 * we don't want to deadlock with an incoming write to the
2366 * object, which has the extent PW and then wants to get the
2367 * parent dentry to do the lookup.
2369 * We dput the child because it's not worth the extra
2370 * complication of condition the above code to skip it on the
2371 * second time through. */
2373 filter_parent_unlock(dparent, lock);
2375 filter_prepare_destroy(obd, oa->o_id, oa->o_gr);
2380 handle = fsfilt_start_log(obd, dparent->d_inode, FSFILT_OP_UNLINK, oti, 1);
2382 GOTO(cleanup, rc = PTR_ERR(handle));
2386 /* Our MDC connection is established by the MDS to us */
2387 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2388 OBD_ALLOC(fcc, sizeof(*fcc));
2390 memcpy(fcc, obdo_logcookie(oa), sizeof(*fcc));
2393 rc = filter_destroy_internal(obd, oa->o_id, dparent, dchild);
2396 switch(cleanup_phase) {
2400 fsfilt_add_journal_cb(obd, filter->fo_sb, 0,
2402 filter_cancel_cookies_cb,
2405 fsfilt_add_journal_cb(obd, filter->fo_sb, 0,
2407 filter_cancel_cookies_cb,
2410 rc = filter_finish_transno(exp, oti, rc);
2411 rc2 = fsfilt_commit(obd, filter->fo_sb, dparent->d_inode,
2414 CERROR("error on commit, err = %d\n", rc2);
2421 filter_parent_unlock(dparent, lock);
2423 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2426 CERROR("invalid cleanup_phase %d\n", cleanup_phase);
2433 /* NB start and end are used for punch, but not truncate */
2434 static int filter_truncate(struct obd_export *exp, struct obdo *oa,
2435 struct lov_stripe_md *lsm,
2436 obd_off start, obd_off end,
2437 struct obd_trans_info *oti)
2442 if (end != OBD_OBJECT_EOF)
2443 CERROR("PUNCH not supported, only truncate: end = "LPX64"\n",
2446 CDEBUG(D_INODE, "calling truncate for object "LPU64", valid = %x, "
2447 "o_size = "LPD64"\n", oa->o_id, oa->o_valid, start);
2449 error = filter_setattr(exp, oa, NULL, oti);
2453 static int filter_sync(struct obd_export *exp, struct obdo *oa,
2454 struct lov_stripe_md *lsm, obd_off start, obd_off end)
2456 struct obd_device *obd = exp->exp_obd;
2457 struct lvfs_run_ctxt saved;
2458 struct filter_obd *filter;
2459 struct dentry *dentry;
2460 struct llog_ctxt *ctxt;
2464 filter = &obd->u.filter;
2466 /* an objid of zero is taken to mean "sync whole filesystem" */
2467 if (!oa || !(oa->o_valid & OBD_MD_FLID)) {
2468 rc = fsfilt_sync(obd, filter->fo_sb);
2469 /* flush any remaining cancel messages out to the target */
2470 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_REPL_CTXT);
2471 llog_sync(ctxt, exp);
2475 dentry = filter_oa2dentry(obd, oa);
2477 RETURN(PTR_ERR(dentry));
2479 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2481 down(&dentry->d_inode->i_sem);
2482 rc = filemap_fdatasync(dentry->d_inode->i_mapping);
2484 /* just any file to grab fsync method - "file" arg unused */
2485 struct file *file = filter->fo_rcvd_filp;
2487 if (file->f_op && file->f_op->fsync)
2488 rc = file->f_op->fsync(NULL, dentry, 1);
2490 rc2 = filemap_fdatawait(dentry->d_inode->i_mapping);
2494 up(&dentry->d_inode->i_sem);
2496 oa->o_valid = OBD_MD_FLID;
2497 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
2499 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2505 static int filter_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2506 unsigned long max_age)
2508 struct filter_obd *filter = &obd->u.filter;
2509 int blockbits = filter->fo_sb->s_blocksize_bits;
2513 /* at least try to account for cached pages. its still racey and
2514 * might be under-reporting if clients haven't announced their
2515 * caches with brw recently */
2516 spin_lock(&obd->obd_osfs_lock);
2517 rc = fsfilt_statfs(obd, filter->fo_sb, max_age);
2518 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
2519 spin_unlock(&obd->obd_osfs_lock);
2521 CDEBUG(D_SUPER | D_CACHE, "blocks cached "LPU64" granted "LPU64
2522 " pending "LPU64" free "LPU64" avail "LPU64"\n",
2523 filter->fo_tot_dirty, filter->fo_tot_granted,
2524 filter->fo_tot_pending,
2525 osfs->os_bfree << blockbits, osfs->os_bavail << blockbits);
2527 filter_grant_sanity_check(obd, __FUNCTION__);
2529 osfs->os_bavail -= min(osfs->os_bavail,
2530 (filter->fo_tot_dirty + filter->fo_tot_pending +
2531 osfs->os_bsize -1) >> blockbits);
2536 static int filter_get_info(struct obd_export *exp, __u32 keylen,
2537 void *key, __u32 *vallen, void *val)
2539 struct filter_export_data *fed = &exp->exp_filter_data;
2540 struct obd_device *obd;
2543 obd = class_exp2obd(exp);
2545 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2546 exp->exp_handle.h_cookie);
2550 if (keylen == strlen("blocksize") &&
2551 memcmp(key, "blocksize", keylen) == 0) {
2552 __u32 *blocksize = val;
2553 *vallen = sizeof(*blocksize);
2554 *blocksize = obd->u.filter.fo_sb->s_blocksize;
2558 if (keylen == strlen("blocksize_bits") &&
2559 memcmp(key, "blocksize_bits", keylen) == 0) {
2560 __u32 *blocksize_bits = val;
2561 *vallen = sizeof(*blocksize_bits);
2562 *blocksize_bits = obd->u.filter.fo_sb->s_blocksize_bits;
2566 if (keylen >= strlen("last_id") && memcmp(key, "last_id", 7) == 0) {
2567 obd_id *last_id = val;
2568 *last_id = filter_last_id(&obd->u.filter, fed->fed_group);
2571 if (keylen >= strlen("reint_log") && memcmp(key, "reint_log", 9) == 0) {
2572 /*Get log_context handle*/
2573 unsigned long *llh_handle = val;
2574 *vallen = sizeof(unsigned long);
2575 *llh_handle = (unsigned long)obd->obd_llog_ctxt[LLOG_REINT_ORIG_CTXT];
2578 if (keylen >= strlen("cache_sb") && memcmp(key, "cache_sb", 8) == 0) {
2579 /*Get log_context handle*/
2580 unsigned long *sb = val;
2581 *vallen = sizeof(unsigned long);
2582 *sb = (unsigned long)obd->u.filter.fo_sb;
2586 CDEBUG(D_IOCTL, "invalid key\n");
2590 struct obd_llogs *filter_grab_llog_for_group(struct obd_device *obd, int group)
2592 struct filter_group_llog *fglog, *nlog;
2593 char name[32] = "CATLIST";
2594 struct filter_obd *filter;
2595 struct list_head *cur;
2598 filter = &obd->u.filter;
2600 spin_lock(&filter->fo_llog_list_lock);
2601 list_for_each(cur, &filter->fo_llog_list) {
2602 fglog = list_entry(cur, struct filter_group_llog, list);
2603 if (fglog->group == group) {
2604 spin_unlock(&filter->fo_llog_list_lock);
2605 RETURN(fglog->llogs);
2608 spin_unlock(&filter->fo_llog_list_lock);
2610 OBD_ALLOC(fglog, sizeof(*fglog));
2613 fglog->group = group;
2615 OBD_ALLOC(fglog->llogs, sizeof(struct obd_llogs));
2616 if (fglog->llogs == NULL) {
2617 OBD_FREE(fglog, sizeof(*fglog));
2621 spin_lock(&filter->fo_llog_list_lock);
2622 list_for_each(cur, &filter->fo_llog_list) {
2623 nlog = list_entry(cur, struct filter_group_llog, list);
2624 LASSERT(nlog->group != group);
2626 list_add(&fglog->list, &filter->fo_llog_list);
2627 spin_unlock(&filter->fo_llog_list_lock);
2629 rc = obd_llog_cat_initialize(obd, fglog->llogs, 1, name);
2631 OBD_FREE(fglog->llogs, sizeof(*(fglog->llogs)));
2632 OBD_FREE(fglog, sizeof(*fglog));
2636 CDEBUG(D_OTHER, "%s: new llog 0x%p for group %u\n", obd->obd_name,
2637 fglog->llogs, group);
2639 RETURN(fglog->llogs);
2642 static int filter_set_info(struct obd_export *exp, __u32 keylen,
2643 void *key, __u32 vallen, void *val)
2645 struct lvfs_run_ctxt saved;
2646 struct filter_export_data *fed = &exp->exp_filter_data;
2647 struct obd_device *obd;
2648 struct lustre_handle conn;
2649 struct obd_llogs *llog;
2650 struct llog_ctxt *ctxt;
2655 conn.cookie = exp->exp_handle.h_cookie;
2659 CDEBUG(D_IOCTL, "invalid exp %p cookie "LPX64"\n",
2664 if (keylen < strlen("mds_conn") ||
2665 memcmp(key, "mds_conn", keylen) != 0)
2668 group = *((__u32 *)val);
2669 if (fed->fed_group != 0 && fed->fed_group != group) {
2670 char str[PTL_NALFMT_SIZE];
2671 portals_nid2str(exp->exp_connection->c_peer.peer_ni->pni_number,
2672 exp->exp_connection->c_peer.peer_nid, str);
2673 CERROR("!!! This export (nid "LPX64"/%s) used object group %d "
2674 "earlier; now it's trying to use group %d! This could "
2675 "be a bug in the MDS. Tell CFS.\n",
2676 exp->exp_connection->c_peer.peer_nid, str,
2677 fed->fed_group, group);
2680 fed->fed_group = group;
2681 CWARN("Received MDS connection ("LPX64"); group %d\n", conn.cookie,
2686 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2687 rc = filter_read_groups(obd, group, 1);
2688 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2690 CERROR("can't read group %u\n", group);
2693 rc = filter_group_set_fs_flags(obd, group);
2695 CERROR("can't set kml flags %u\n", group);
2698 llog = filter_grab_llog_for_group(obd, group);
2699 LASSERT(llog != NULL);
2701 ctxt = llog_get_context(llog, LLOG_UNLINK_REPL_CTXT);
2702 LASSERT(ctxt != NULL);
2703 rc = llog_receptor_accept(ctxt, exp->exp_imp_reverse);
2707 int filter_iocontrol(unsigned int cmd, struct obd_export *exp,
2708 int len, void *karg, void *uarg)
2710 struct obd_device *obd = exp->exp_obd;
2711 struct obd_ioctl_data *data = karg;
2715 case OBD_IOC_ABORT_RECOVERY:
2716 CERROR("aborting recovery for device %s\n", obd->obd_name);
2717 target_abort_recovery(obd);
2720 case OBD_IOC_SET_READONLY: {
2722 struct super_block *sb = obd->u.filter.fo_sb;
2723 struct inode *inode = sb->s_root->d_inode;
2724 BDEVNAME_DECLARE_STORAGE(tmp);
2725 CERROR("setting device %s read-only\n",
2726 ll_bdevname(sb, tmp));
2728 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
2730 (void)fsfilt_commit(obd, sb, inode, handle, 1);
2732 dev_set_rdonly(ll_sbdev(obd->u.filter.fo_sb), 2);
2736 case OBD_IOC_CATLOGLIST: {
2737 rc = llog_catalog_list(obd, 1, data);
2741 case OBD_IOC_SNAP_ADD: {
2742 char *name = data->ioc_inlbuf1;
2744 rc = fsfilt_set_snap_item(obd, obd->u.filter.fo_sb, name);
2748 case OBD_IOC_LLOG_CANCEL:
2749 case OBD_IOC_LLOG_REMOVE:
2750 case OBD_IOC_LLOG_INFO:
2751 case OBD_IOC_LLOG_PRINT: {
2752 /* FIXME to be finished */
2753 RETURN(-EOPNOTSUPP);
2755 struct llog_ctxt *ctxt = NULL;
2757 push_ctxt(&saved, &ctxt->loc_ctxt, NULL);
2758 rc = llog_ioctl(ctxt, cmd, data);
2759 pop_ctxt(&saved, &ctxt->loc_ctxt, NULL);
2772 static struct llog_operations filter_unlink_repl_logops;
2773 static struct llog_operations filter_size_orig_logops = {
2774 lop_setup: llog_obd_origin_setup,
2775 lop_cleanup: llog_catalog_cleanup,
2776 lop_add: llog_catalog_add,
2779 static int filter_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
2780 struct obd_device *tgt, int count,
2781 struct llog_catid *catid)
2783 struct llog_ctxt *ctxt;
2787 filter_unlink_repl_logops = llog_client_ops;
2788 filter_unlink_repl_logops.lop_cancel = llog_obd_repl_cancel;
2789 filter_unlink_repl_logops.lop_connect = llog_repl_connect;
2790 filter_unlink_repl_logops.lop_sync = llog_obd_repl_sync;
2792 rc = obd_llog_setup(obd, llogs, LLOG_UNLINK_REPL_CTXT, tgt, 0, NULL,
2793 &filter_unlink_repl_logops);
2796 /* FIXME - assign unlink_cb for filter's recovery */
2797 ctxt = llog_get_context(llogs, LLOG_UNLINK_REPL_CTXT);
2798 ctxt->llog_proc_cb = filter_recov_log_unlink_cb;
2800 /* FIXME - count should be 1 to setup size log */
2801 rc = obd_llog_setup(obd, llogs, LLOG_SIZE_ORIG_CTXT, tgt, 0,
2802 &catid->lci_logid, &filter_size_orig_logops);
2806 static int filter_llog_finish(struct obd_device *obd,
2807 struct obd_llogs *llogs, int count)
2812 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_UNLINK_REPL_CTXT));
2816 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_SIZE_ORIG_CTXT));
2820 static int filter_llog_connect(struct obd_device *obd,
2821 struct llogd_conn_body *body)
2823 struct llog_ctxt *ctxt;
2824 struct obd_llogs *llog;
2828 CDEBUG(D_OTHER, "handle connect for %s: %u/%u/%u\n", obd->obd_name,
2829 (unsigned) body->lgdc_logid.lgl_ogr,
2830 (unsigned) body->lgdc_logid.lgl_oid,
2831 (unsigned) body->lgdc_logid.lgl_ogen);
2832 llog = filter_grab_llog_for_group(obd, body->lgdc_logid.lgl_ogr);
2833 LASSERT(llog != NULL);
2834 ctxt = llog_get_context(llog, body->lgdc_ctxt_idx);
2835 rc = llog_connect(ctxt, 1, &body->lgdc_logid,
2836 &body->lgdc_gen, NULL);
2838 CERROR("failed to connect\n");
2843 static struct dentry *filter_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
2846 return filter_fid2dentry(data, NULL, gr, id);
2849 static struct lvfs_callback_ops filter_lvfs_ops = {
2850 l_fid2dentry: filter_lvfs_fid2dentry,
2853 static struct obd_ops filter_obd_ops = {
2854 .o_owner = THIS_MODULE,
2855 .o_attach = filter_attach,
2856 .o_detach = filter_detach,
2857 .o_get_info = filter_get_info,
2858 .o_set_info = filter_set_info,
2859 .o_setup = filter_setup,
2860 .o_precleanup = filter_precleanup,
2861 .o_cleanup = filter_cleanup,
2862 .o_connect = filter_connect,
2863 .o_disconnect = filter_disconnect,
2864 .o_statfs = filter_statfs,
2865 .o_getattr = filter_getattr,
2866 .o_unpackmd = filter_unpackmd,
2867 .o_create = filter_create,
2868 .o_setattr = filter_setattr,
2869 .o_destroy = filter_destroy,
2870 .o_brw = filter_brw,
2871 .o_punch = filter_truncate,
2872 .o_sync = filter_sync,
2873 .o_preprw = filter_preprw,
2874 .o_commitrw = filter_commitrw,
2875 .o_do_cow = filter_do_cow,
2876 .o_write_extents = filter_write_extents,
2877 .o_destroy_export = filter_destroy_export,
2878 .o_llog_init = filter_llog_init,
2879 .o_llog_finish = filter_llog_finish,
2880 .o_llog_connect = filter_llog_connect,
2881 .o_iocontrol = filter_iocontrol,
2884 static struct obd_ops filter_sanobd_ops = {
2885 .o_owner = THIS_MODULE,
2886 .o_attach = filter_attach,
2887 .o_detach = filter_detach,
2888 .o_get_info = filter_get_info,
2889 .o_set_info = filter_set_info,
2890 .o_setup = filter_san_setup,
2891 .o_precleanup = filter_precleanup,
2892 .o_cleanup = filter_cleanup,
2893 .o_connect = filter_connect,
2894 .o_disconnect = filter_disconnect,
2895 .o_statfs = filter_statfs,
2896 .o_getattr = filter_getattr,
2897 .o_unpackmd = filter_unpackmd,
2898 .o_create = filter_create,
2899 .o_setattr = filter_setattr,
2900 .o_destroy = filter_destroy,
2901 .o_brw = filter_brw,
2902 .o_punch = filter_truncate,
2903 .o_sync = filter_sync,
2904 .o_preprw = filter_preprw,
2905 .o_commitrw = filter_commitrw,
2906 .o_do_cow = filter_do_cow,
2907 .o_write_extents = filter_write_extents,
2908 .o_san_preprw = filter_san_preprw,
2909 .o_destroy_export = filter_destroy_export,
2910 .o_llog_init = filter_llog_init,
2911 .o_llog_finish = filter_llog_finish,
2912 .o_llog_connect = filter_llog_connect,
2913 .o_iocontrol = filter_iocontrol,
2916 static int __init obdfilter_init(void)
2918 struct lprocfs_static_vars lvars;
2921 printk(KERN_INFO "Lustre: Filtering OBD driver; info@clusterfs.com\n");
2923 lprocfs_init_vars(filter, &lvars);
2925 rc = class_register_type(&filter_obd_ops, NULL, lvars.module_vars,
2926 OBD_FILTER_DEVICENAME);
2930 rc = class_register_type(&filter_sanobd_ops, NULL, lvars.module_vars,
2931 OBD_FILTER_SAN_DEVICENAME);
2933 class_unregister_type(OBD_FILTER_DEVICENAME);
2937 static void __exit obdfilter_exit(void)
2939 class_unregister_type(OBD_FILTER_SAN_DEVICENAME);
2940 class_unregister_type(OBD_FILTER_DEVICENAME);
2943 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2944 MODULE_DESCRIPTION("Lustre Filtering OBD driver");
2945 MODULE_LICENSE("GPL");
2947 module_init(obdfilter_init);
2948 module_exit(obdfilter_exit);