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/obd_ost.h>
52 #include <linux/lustre_dlm.h>
53 #include <linux/lustre_fsfilt.h>
54 #include <linux/lprocfs_status.h>
55 #include <linux/lustre_log.h>
56 #include <linux/lustre_commit_confd.h>
57 #include <portals/list.h>
59 #include <linux/lustre_smfs.h>
60 #include "filter_internal.h"
62 static struct lvfs_callback_ops filter_lvfs_ops;
64 static int filter_destroy(struct obd_export *exp, struct obdo *oa,
65 struct lov_stripe_md *ea, struct obd_trans_info *);
67 static void filter_commit_cb(struct obd_device *obd, __u64 transno,
68 void *cb_data, int error)
70 obd_transno_commit_cb(obd, transno, error);
73 /* Assumes caller has already pushed us into the kernel context. */
74 int filter_finish_transno(struct obd_export *exp, struct obd_trans_info *oti,
77 struct filter_obd *filter = &exp->exp_obd->u.filter;
78 struct filter_export_data *fed = &exp->exp_filter_data;
79 struct filter_client_data *fcd = fed->fed_fcd;
82 int err, log_pri = D_HA;
84 /* Propagate error code. */
88 if (!exp->exp_obd->obd_replayable || oti == NULL)
91 /* we don't allocate new transnos for replayed requests */
92 if (oti->oti_transno == 0) {
93 spin_lock(&filter->fo_translock);
94 last_rcvd = le64_to_cpu(filter->fo_fsd->fsd_last_transno) + 1;
95 filter->fo_fsd->fsd_last_transno = cpu_to_le64(last_rcvd);
96 spin_unlock(&filter->fo_translock);
97 oti->oti_transno = last_rcvd;
99 spin_lock(&filter->fo_translock);
100 last_rcvd = oti->oti_transno;
101 if (last_rcvd > le64_to_cpu(filter->fo_fsd->fsd_last_transno))
102 filter->fo_fsd->fsd_last_transno =
103 cpu_to_le64(last_rcvd);
104 spin_unlock(&filter->fo_translock);
106 fcd->fcd_last_rcvd = cpu_to_le64(last_rcvd);
108 /* could get xid from oti, if it's ever needed */
109 fcd->fcd_last_xid = 0;
111 off = fed->fed_lr_off;
113 fsfilt_add_journal_cb(exp->exp_obd, filter->fo_sb, last_rcvd,
114 oti->oti_handle, filter_commit_cb, NULL);
116 err = fsfilt_write_record(exp->exp_obd, filter->fo_rcvd_filp, fcd,
117 sizeof(*fcd), &off, 0);
124 CDEBUG(log_pri, "wrote trans "LPU64" for client %s at #%d: err = %d\n",
125 last_rcvd, fcd->fcd_uuid, fed->fed_lr_idx, err);
130 void f_dput(struct dentry *dentry)
132 /* Can't go inside filter_ddelete because it can block */
133 CDEBUG(D_INODE, "putting %s: %p, count = %d\n",
134 dentry->d_name.name, dentry, atomic_read(&dentry->d_count) - 1);
135 LASSERT(atomic_read(&dentry->d_count) > 0);
140 /* Add client data to the FILTER. We use a bitmap to locate a free space
141 * in the last_rcvd file if cl_idx is -1 (i.e. a new client).
142 * Otherwise, we have just read the data from the last_rcvd file and
143 * we know its offset. */
144 static int filter_client_add(struct obd_device *obd, struct filter_obd *filter,
145 struct filter_export_data *fed, int cl_idx)
147 unsigned long *bitmap = filter->fo_last_rcvd_slots;
148 int new_client = (cl_idx == -1);
151 LASSERT(bitmap != NULL);
153 /* XXX if fcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
154 if (!strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid))
157 /* the bitmap operations can handle cl_idx > sizeof(long) * 8, so
158 * there's no need for extra complication here
161 cl_idx = find_first_zero_bit(bitmap, FILTER_LR_MAX_CLIENTS);
163 if (cl_idx >= FILTER_LR_MAX_CLIENTS) {
164 CERROR("no client slots - fix FILTER_LR_MAX_CLIENTS\n");
167 if (test_and_set_bit(cl_idx, bitmap)) {
168 CERROR("FILTER client %d: found bit is set in bitmap\n",
170 cl_idx = find_next_zero_bit(bitmap,
171 FILTER_LR_MAX_CLIENTS,
176 if (test_and_set_bit(cl_idx, bitmap)) {
177 CERROR("FILTER client %d: bit already set in bitmap!\n",
183 fed->fed_lr_idx = cl_idx;
184 fed->fed_lr_off = le32_to_cpu(filter->fo_fsd->fsd_client_start) +
185 cl_idx * le16_to_cpu(filter->fo_fsd->fsd_client_size);
187 CDEBUG(D_INFO, "client at index %d (%llu) with UUID '%s' added\n",
188 fed->fed_lr_idx, fed->fed_lr_off, fed->fed_fcd->fcd_uuid);
191 struct lvfs_run_ctxt saved;
192 loff_t off = fed->fed_lr_off;
196 CDEBUG(D_INFO, "writing client fcd at idx %u (%llu) (len %u)\n",
197 fed->fed_lr_idx,off,(unsigned int)sizeof(*fed->fed_fcd));
199 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
200 /* Transaction needed to fix bug 1403 */
201 handle = fsfilt_start(obd,
202 filter->fo_rcvd_filp->f_dentry->d_inode,
203 FSFILT_OP_SETATTR, NULL);
204 if (IS_ERR(handle)) {
205 err = PTR_ERR(handle);
206 CERROR("unable to start transaction: rc %d\n", err);
208 err = fsfilt_write_record(obd, filter->fo_rcvd_filp,
210 sizeof(*fed->fed_fcd),
212 fsfilt_commit(obd, filter->fo_sb,
213 filter->fo_rcvd_filp->f_dentry->d_inode,
216 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
219 CERROR("error writing %s client idx %u: rc %d\n",
220 LAST_RCVD, fed->fed_lr_idx, err);
227 static int filter_client_free(struct obd_export *exp, int flags)
229 struct filter_export_data *fed = &exp->exp_filter_data;
230 struct filter_obd *filter = &exp->exp_obd->u.filter;
231 struct obd_device *obd = exp->exp_obd;
232 struct filter_client_data zero_fcd;
233 struct lvfs_run_ctxt saved;
238 if (fed->fed_fcd == NULL)
241 if (flags & OBD_OPT_FAILOVER)
244 /* XXX if fcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
245 if (strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid ) == 0)
248 LASSERT(filter->fo_last_rcvd_slots != NULL);
250 off = fed->fed_lr_off;
252 CDEBUG(D_INFO, "freeing client at idx %u (%lld) with UUID '%s'\n",
253 fed->fed_lr_idx, fed->fed_lr_off, fed->fed_fcd->fcd_uuid);
255 /* Clear the bit _after_ zeroing out the client so we don't
256 race with filter_client_add and zero out new clients.*/
257 if (!test_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
258 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
263 memset(&zero_fcd, 0, sizeof zero_fcd);
264 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
265 rc = fsfilt_write_record(obd, filter->fo_rcvd_filp, &zero_fcd,
266 sizeof(zero_fcd), &off, 1);
268 /* update server's transno */
269 filter_update_server_data(obd, filter->fo_rcvd_filp,
271 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
273 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
274 "zeroing disconnecting client %s at idx %u (%llu) in %s rc %d\n",
275 fed->fed_fcd->fcd_uuid, fed->fed_lr_idx, fed->fed_lr_off,
278 if (!test_and_clear_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
279 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
285 OBD_FREE(fed->fed_fcd, sizeof(*fed->fed_fcd));
290 static int filter_free_server_data(struct filter_obd *filter)
292 OBD_FREE(filter->fo_fsd, sizeof(*filter->fo_fsd));
293 filter->fo_fsd = NULL;
294 OBD_FREE(filter->fo_last_rcvd_slots,
295 FILTER_LR_MAX_CLIENT_WORDS * sizeof(unsigned long));
296 filter->fo_last_rcvd_slots = NULL;
300 /* assumes caller is already in kernel ctxt */
301 int filter_update_server_data(struct obd_device *obd, struct file *filp,
302 struct filter_server_data *fsd, int force_sync)
308 CDEBUG(D_INODE, "server uuid : %s\n", fsd->fsd_uuid);
309 CDEBUG(D_INODE, "server last_rcvd : "LPU64"\n",
310 le64_to_cpu(fsd->fsd_last_transno));
311 CDEBUG(D_INODE, "server last_mount: "LPU64"\n",
312 le64_to_cpu(fsd->fsd_mount_count));
314 rc = fsfilt_write_record(obd, filp, fsd, sizeof(*fsd), &off,force_sync);
316 CERROR("error writing filter_server_data: rc = %d\n", rc);
321 int filter_update_last_objid(struct obd_device *obd, obd_gr group,
324 struct filter_obd *filter = &obd->u.filter;
330 if (filter->fo_last_objid_files[group] == NULL) {
331 CERROR("Object group "LPU64" not fully setup; not updating "
332 "last_objid\n", group);
336 CDEBUG(D_INODE, "server last_objid for group "LPU64": "LPU64"\n",
337 group, filter->fo_last_objids[group]);
339 tmp = cpu_to_le64(filter->fo_last_objids[group]);
340 rc = fsfilt_write_record(obd, filter->fo_last_objid_files[group],
341 &tmp, sizeof(tmp), &off, force_sync);
343 CERROR("error writing group "LPU64" last objid: rc = %d\n",
348 /* assumes caller has already in kernel ctxt */
349 static int filter_init_server_data(struct obd_device *obd, struct file * filp)
351 struct filter_obd *filter = &obd->u.filter;
352 struct filter_server_data *fsd;
353 struct filter_client_data *fcd = NULL;
354 struct inode *inode = filp->f_dentry->d_inode;
355 unsigned long last_rcvd_size = inode->i_size;
361 /* ensure padding in the struct is the correct size */
362 LASSERT (offsetof(struct filter_server_data, fsd_padding) +
363 sizeof(fsd->fsd_padding) == FILTER_LR_SERVER_SIZE);
364 LASSERT (offsetof(struct filter_client_data, fcd_padding) +
365 sizeof(fcd->fcd_padding) == FILTER_LR_CLIENT_SIZE);
367 OBD_ALLOC(fsd, sizeof(*fsd));
370 filter->fo_fsd = fsd;
372 OBD_ALLOC(filter->fo_last_rcvd_slots,
373 FILTER_LR_MAX_CLIENT_WORDS * sizeof(unsigned long));
374 if (filter->fo_last_rcvd_slots == NULL) {
375 OBD_FREE(fsd, sizeof(*fsd));
379 if (last_rcvd_size == 0) {
380 CWARN("%s: initializing new %s\n", obd->obd_name, LAST_RCVD);
382 memcpy(fsd->fsd_uuid, obd->obd_uuid.uuid,sizeof(fsd->fsd_uuid));
383 fsd->fsd_last_transno = 0;
384 mount_count = fsd->fsd_mount_count = 0;
385 fsd->fsd_server_size = cpu_to_le32(FILTER_LR_SERVER_SIZE);
386 fsd->fsd_client_start = cpu_to_le32(FILTER_LR_CLIENT_START);
387 fsd->fsd_client_size = cpu_to_le16(FILTER_LR_CLIENT_SIZE);
388 fsd->fsd_subdir_count = cpu_to_le16(FILTER_SUBDIR_COUNT);
389 filter->fo_subdir_count = FILTER_SUBDIR_COUNT;
391 rc = fsfilt_read_record(obd, filp, fsd, sizeof(*fsd), &off);
393 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
397 if (strcmp(fsd->fsd_uuid, obd->obd_uuid.uuid) != 0) {
398 CERROR("OBD UUID %s does not match last_rcvd UUID %s\n",
399 obd->obd_uuid.uuid, fsd->fsd_uuid);
400 GOTO(err_fsd, rc = -EINVAL);
402 mount_count = le64_to_cpu(fsd->fsd_mount_count);
403 filter->fo_subdir_count = le16_to_cpu(fsd->fsd_subdir_count);
406 if (fsd->fsd_feature_incompat & ~cpu_to_le32(FILTER_INCOMPAT_SUPP)) {
407 CERROR("unsupported feature %x\n",
408 le32_to_cpu(fsd->fsd_feature_incompat) &
409 ~FILTER_INCOMPAT_SUPP);
410 GOTO(err_fsd, rc = -EINVAL);
412 if (fsd->fsd_feature_rocompat & ~cpu_to_le32(FILTER_ROCOMPAT_SUPP)) {
413 CERROR("read-only feature %x\n",
414 le32_to_cpu(fsd->fsd_feature_rocompat) &
415 ~FILTER_ROCOMPAT_SUPP);
416 /* Do something like remount filesystem read-only */
417 GOTO(err_fsd, rc = -EINVAL);
420 CDEBUG(D_INODE, "%s: server last_rcvd : "LPU64"\n",
421 obd->obd_name, le64_to_cpu(fsd->fsd_last_transno));
422 CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
423 obd->obd_name, mount_count + 1);
424 CDEBUG(D_INODE, "%s: server data size: %u\n",
425 obd->obd_name, le32_to_cpu(fsd->fsd_server_size));
426 CDEBUG(D_INODE, "%s: per-client data start: %u\n",
427 obd->obd_name, le32_to_cpu(fsd->fsd_client_start));
428 CDEBUG(D_INODE, "%s: per-client data size: %u\n",
429 obd->obd_name, le32_to_cpu(fsd->fsd_client_size));
430 CDEBUG(D_INODE, "%s: server subdir_count: %u\n",
431 obd->obd_name, le16_to_cpu(fsd->fsd_subdir_count));
432 CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
433 last_rcvd_size <= le32_to_cpu(fsd->fsd_client_start) ? 0 :
434 (last_rcvd_size - le32_to_cpu(fsd->fsd_client_start)) /
435 le16_to_cpu(fsd->fsd_client_size));
437 if (!obd->obd_replayable) {
438 CWARN("%s: recovery support OFF\n", obd->obd_name);
442 for (cl_idx = 0, off = le32_to_cpu(fsd->fsd_client_start);
443 off < last_rcvd_size; cl_idx++) {
445 struct obd_export *exp;
446 struct filter_export_data *fed;
449 OBD_ALLOC(fcd, sizeof(*fcd));
451 GOTO(err_client, rc = -ENOMEM);
454 /* Don't assume off is incremented properly by
455 * fsfilt_read_record(), in case sizeof(*fcd)
456 * isn't the same as fsd->fsd_client_size. */
457 off = le32_to_cpu(fsd->fsd_client_start) +
458 cl_idx * le16_to_cpu(fsd->fsd_client_size);
459 rc = fsfilt_read_record(obd, filp, fcd, sizeof(*fcd), &off);
461 CERROR("error reading FILT %s idx %d off %llu: rc %d\n",
462 LAST_RCVD, cl_idx, off, rc);
463 break; /* read error shouldn't cause startup to fail */
466 if (fcd->fcd_uuid[0] == '\0') {
467 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
472 last_rcvd = le64_to_cpu(fcd->fcd_last_rcvd);
474 /* These exports are cleaned up by filter_disconnect(), so they
475 * need to be set up like real exports as filter_connect() does.
477 exp = class_new_export(obd);
478 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
479 " srv lr: "LPU64"\n", fcd->fcd_uuid, cl_idx,
480 last_rcvd, le64_to_cpu(fsd->fsd_last_transno));
482 GOTO(err_client, rc = -ENOMEM);
484 memcpy(&exp->exp_client_uuid.uuid, fcd->fcd_uuid,
485 sizeof exp->exp_client_uuid.uuid);
486 fed = &exp->exp_filter_data;
488 filter_client_add(obd, filter, fed, cl_idx);
489 /* create helper if export init gets more complex */
490 spin_lock_init(&fed->fed_lock);
493 exp->exp_replay_needed = 1;
494 obd->obd_recoverable_clients++;
495 obd->obd_max_recoverable_clients++;
496 class_export_put(exp);
498 CDEBUG(D_OTHER, "client at idx %d has last_rcvd = "LPU64"\n",
501 if (last_rcvd > le64_to_cpu(fsd->fsd_last_transno))
502 fsd->fsd_last_transno = cpu_to_le64(last_rcvd);
506 obd->obd_last_committed = le64_to_cpu(fsd->fsd_last_transno);
508 if (obd->obd_recoverable_clients) {
509 CWARN("RECOVERY: %d recoverable clients, last_rcvd "
510 LPU64"\n", obd->obd_recoverable_clients,
511 le64_to_cpu(fsd->fsd_last_transno));
512 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
513 target_start_recovery_thread(obd, ost_handle);
517 OBD_FREE(fcd, sizeof(*fcd));
520 filter->fo_mount_count = mount_count + 1;
521 fsd->fsd_mount_count = cpu_to_le64(filter->fo_mount_count);
523 /* save it, so mount count and last_transno is current */
524 rc = filter_update_server_data(obd, filp, filter->fo_fsd, 1);
529 class_disconnect_exports(obd, 0);
531 filter_free_server_data(filter);
535 static int filter_cleanup_groups(struct obd_device *obd)
537 struct filter_obd *filter = &obd->u.filter;
538 struct dentry *dentry;
542 for (i = 0; i < filter->fo_group_count; i++) {
543 if (filter->fo_subdirs != NULL) {
544 for (k = 0; k < filter->fo_subdir_count; k++) {
545 dentry = filter->fo_subdirs[i].dentry[k];
549 filter->fo_subdirs[i].dentry[k] = NULL;
552 if (filter->fo_last_objid_files[i] != NULL) {
553 filp_close(filter->fo_last_objid_files[i], 0);
554 filter->fo_last_objid_files[i] = NULL;
556 if (filter->fo_groups[i] != NULL) {
557 dput(filter->fo_groups[i]);
558 filter->fo_groups[i] = NULL;
561 if (filter->fo_subdirs != NULL)
562 OBD_FREE(filter->fo_subdirs,
563 filter->fo_group_count * sizeof(*filter->fo_subdirs));
564 if (filter->fo_groups != NULL)
565 OBD_FREE(filter->fo_groups,
566 filter->fo_group_count * sizeof(*filter->fo_groups));
567 if (filter->fo_last_objids != NULL)
568 OBD_FREE(filter->fo_last_objids,
569 filter->fo_group_count * sizeof(__u64));
570 if (filter->fo_last_objid_files != NULL)
571 OBD_FREE(filter->fo_last_objid_files,
572 filter->fo_group_count * sizeof(struct file *));
573 f_dput(filter->fo_dentry_O);
577 static int filter_read_group_internal(struct obd_device *obd, int group,
580 struct filter_obd *filter = &obd->u.filter;
581 __u64 *new_objids = NULL;
582 struct filter_subdirs *new_subdirs = NULL, *tmp_subdirs = NULL;
583 struct dentry **new_groups = NULL;
584 struct file **new_files = NULL;
585 struct dentry *dentry;
587 int old_count = filter->fo_group_count, rc, stage = 0, i;
592 snprintf(name, 24, "%d", group);
596 dentry = ll_lookup_one_len(name, filter->fo_dentry_O,
598 if (IS_ERR(dentry)) {
599 CERROR("Cannot lookup expected object group %d: %ld\n",
600 group, PTR_ERR(dentry));
601 RETURN(PTR_ERR(dentry));
604 dentry = simple_mkdir(filter->fo_dentry_O, name, 0700, 1);
605 if (IS_ERR(dentry)) {
606 CERROR("cannot lookup/create O/%s: rc = %ld\n", name,
608 RETURN(PTR_ERR(dentry));
613 snprintf(name, 24, "O/%d/LAST_ID", group);
615 filp = filp_open(name, O_CREAT | O_RDWR, 0700);
617 CERROR("cannot create %s: rc = %ld\n", name, PTR_ERR(filp));
618 GOTO(cleanup, rc = PTR_ERR(filp));
622 rc = fsfilt_read_record(obd, filp, &last_objid, sizeof(__u64), &off);
624 CDEBUG(D_INODE, "error reading %s: rc %d\n", name, rc);
628 if (filter->fo_subdir_count) {
629 OBD_ALLOC(tmp_subdirs, sizeof(*tmp_subdirs));
630 if (tmp_subdirs == NULL)
631 GOTO(cleanup, rc = -ENOMEM);
634 for (i = 0; i < filter->fo_subdir_count; i++) {
636 snprintf(dir, sizeof(dir), "d%u", i);
638 tmp_subdirs->dentry[i] =
639 simple_mkdir(dentry, dir, 0700, 1);
640 if (IS_ERR(tmp_subdirs->dentry[i])) {
641 rc = PTR_ERR(tmp_subdirs->dentry[i]);
642 CERROR("can't lookup/create O/%d/%s: rc = %d\n",
646 CDEBUG(D_INODE, "got/created O/%d/%s: %p\n", group, dir,
647 tmp_subdirs->dentry[i]);
651 /* 'group' is an index; we need an array of length 'group + 1' */
652 if (group + 1 > old_count) {
654 OBD_ALLOC(new_objids, len * sizeof(*new_objids));
655 OBD_ALLOC(new_subdirs, len * sizeof(*new_subdirs));
656 OBD_ALLOC(new_groups, len * sizeof(*new_groups));
657 OBD_ALLOC(new_files, len * sizeof(*new_files));
659 if (new_objids == NULL || new_subdirs == NULL ||
660 new_groups == NULL || new_files == NULL)
661 GOTO(cleanup, rc = -ENOMEM);
663 memcpy(new_objids, filter->fo_last_objids,
664 old_count * sizeof(*new_objids));
665 memcpy(new_subdirs, filter->fo_subdirs,
666 old_count * sizeof(*new_subdirs));
667 memcpy(new_groups, filter->fo_groups,
668 old_count * sizeof(*new_groups));
669 memcpy(new_files, filter->fo_last_objid_files,
670 old_count * sizeof(*new_files));
673 OBD_FREE(filter->fo_last_objids,
674 old_count * sizeof(*new_objids));
675 OBD_FREE(filter->fo_subdirs,
676 old_count * sizeof(*new_subdirs));
677 OBD_FREE(filter->fo_groups,
678 old_count * sizeof(*new_groups));
679 OBD_FREE(filter->fo_last_objid_files,
680 old_count * sizeof(*new_files));
682 filter->fo_last_objids = new_objids;
683 filter->fo_subdirs = new_subdirs;
684 filter->fo_groups = new_groups;
685 filter->fo_last_objid_files = new_files;
686 filter->fo_group_count = len;
689 filter->fo_groups[group] = dentry;
690 filter->fo_last_objid_files[group] = filp;
691 if (filter->fo_subdir_count) {
692 filter->fo_subdirs[group] = *tmp_subdirs;
693 OBD_FREE(tmp_subdirs, sizeof(*tmp_subdirs));
696 if (filp->f_dentry->d_inode->i_size == 0) {
697 filter->fo_last_objids[group] = FILTER_INIT_OBJID;
701 filter->fo_last_objids[group] = le64_to_cpu(last_objid);
702 CDEBUG(D_INODE, "%s: server last_objid group %d: "LPU64"\n",
703 obd->obd_name, group, last_objid);
708 if (new_objids != NULL)
709 OBD_FREE(new_objids, group * sizeof(*new_objids));
710 if (new_subdirs != NULL)
711 OBD_FREE(new_subdirs, group * sizeof(*new_subdirs));
712 if (new_groups != NULL)
713 OBD_FREE(new_groups, group * sizeof(*new_groups));
714 if (new_files != NULL)
715 OBD_FREE(new_files, group * sizeof(*new_files));
717 if (filter->fo_subdir_count) {
718 for (i = 0; i < filter->fo_subdir_count; i++) {
719 if (tmp_subdirs->dentry[i] != NULL)
720 dput(tmp_subdirs->dentry[i]);
722 OBD_FREE(tmp_subdirs, sizeof(*tmp_subdirs));
732 static int filter_read_groups(struct obd_device *obd, int last_group,
735 struct filter_obd *filter = &obd->u.filter;
736 int old_count, group, rc = 0;
738 down(&filter->fo_init_lock);
739 old_count = filter->fo_group_count;
740 for (group = old_count; group <= last_group; group++) {
742 continue; /* no group zero */
744 rc = filter_read_group_internal(obd, group, create);
748 up(&filter->fo_init_lock);
752 static int filter_prep_groups(struct obd_device *obd)
754 struct filter_obd *filter = &obd->u.filter;
755 struct dentry *dentry, *O_dentry;
756 int rc = 0, cleanup_phase = 0;
759 O_dentry = simple_mkdir(current->fs->pwd, "O", 0700, 1);
760 CDEBUG(D_INODE, "got/created O: %p\n", O_dentry);
761 if (IS_ERR(O_dentry)) {
762 rc = PTR_ERR(O_dentry);
763 CERROR("cannot open/create O: rc = %d\n", rc);
766 filter->fo_dentry_O = O_dentry;
767 cleanup_phase = 1; /* O_dentry */
769 /* Lookup "R" to tell if we're on an old OST FS and need to convert
770 * from O/R/<dir>/<objid> to O/0/<dir>/<objid>. This can be removed
771 * some time post 1.0 when all old-style OSTs have converted along
772 * with the init_objid hack. */
773 dentry = ll_lookup_one_len("R", O_dentry, 1);
775 GOTO(cleanup, rc = PTR_ERR(dentry));
776 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) {
777 struct dentry *O0_dentry = lookup_one_len("0", O_dentry, 1);
780 CWARN("converting OST to new object layout\n");
781 if (IS_ERR(O0_dentry)) {
782 rc = PTR_ERR(O0_dentry);
783 CERROR("error looking up O/0: rc %d\n", rc);
787 if (O0_dentry->d_inode) {
788 CERROR("Both O/R and O/0 exist. Fix manually.\n");
789 GOTO(cleanup_O0, rc = -EEXIST);
792 down(&O_dentry->d_inode->i_sem);
793 rc = vfs_rename(O_dentry->d_inode, dentry,
794 O_dentry->d_inode, O0_dentry);
795 up(&O_dentry->d_inode->i_sem);
798 CERROR("error renaming O/R to O/0: rc %d\n", rc);
799 GOTO(cleanup_O0, rc);
801 filter->fo_fsd->fsd_feature_incompat |=
802 cpu_to_le32(FILTER_INCOMPAT_GROUPS);
803 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
805 GOTO(cleanup_O0, rc);
817 cleanup_phase = 2; /* groups */
819 /* Group 0 is no longer a legal group, to catch uninitialized IDs */
820 #define FILTER_MIN_GROUPS 3
821 rc = filter_read_groups(obd, FILTER_MIN_GROUPS, 1);
828 switch (cleanup_phase) {
830 filter_cleanup_groups(obd);
832 f_dput(filter->fo_dentry_O);
833 filter->fo_dentry_O = NULL;
840 /* setup the object store with correct subdirectories */
841 static int filter_prep(struct obd_device *obd)
843 struct lvfs_run_ctxt saved;
844 struct filter_obd *filter = &obd->u.filter;
850 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
851 file = filp_open(LAST_RCVD, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
852 if (!file || IS_ERR(file)) {
854 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
859 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
860 CERROR("%s is not a regular file!: mode = %o\n", LAST_RCVD,
861 file->f_dentry->d_inode->i_mode);
862 GOTO(err_filp, rc = -ENOENT);
865 /* steal operations */
866 inode = file->f_dentry->d_inode;
867 filter->fo_fop = file->f_op;
868 filter->fo_iop = inode->i_op;
869 filter->fo_aops = inode->i_mapping->a_ops;
871 rc = filter_init_server_data(obd, file);
873 CERROR("cannot read %s: rc = %d\n", LAST_RCVD, rc);
876 filter->fo_rcvd_filp = file;
878 rc = filter_prep_groups(obd);
880 GOTO(err_server_data, rc);
883 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
888 //class_disconnect_exports(obd, 0);
889 filter_free_server_data(filter);
891 if (filp_close(file, 0))
892 CERROR("can't close %s after error\n", LAST_RCVD);
893 filter->fo_rcvd_filp = NULL;
897 /* cleanup the filter: write last used object id to status file */
898 static void filter_post(struct obd_device *obd)
900 struct lvfs_run_ctxt saved;
901 struct filter_obd *filter = &obd->u.filter;
904 /* XXX: filter_update_lastobjid used to call fsync_dev. It might be
905 * best to start a transaction with h_sync, because we removed this
908 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
909 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
912 CERROR("error writing server data: rc = %d\n", rc);
914 for (i = 1; i < filter->fo_group_count; i++) {
915 rc = filter_update_last_objid(obd, i,
916 (i == filter->fo_group_count - 1));
918 CERROR("error writing group %d lastobjid: rc = %d\n",
922 rc = filp_close(filter->fo_rcvd_filp, 0);
923 filter->fo_rcvd_filp = NULL;
925 CERROR("error closing %s: rc = %d\n", LAST_RCVD, rc);
927 filter_cleanup_groups(obd);
928 filter_free_server_data(filter);
929 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
932 static void filter_set_last_id(struct filter_obd *filter, int group, obd_id id)
934 LASSERT(filter->fo_fsd != NULL);
936 LASSERT(group < filter->fo_group_count);
938 spin_lock(&filter->fo_objidlock);
939 filter->fo_last_objids[group] = id;
940 spin_unlock(&filter->fo_objidlock);
943 __u64 filter_last_id(struct filter_obd *filter, int group)
946 LASSERT(filter->fo_fsd != NULL);
948 LASSERT(group < filter->fo_group_count);
950 spin_lock(&filter->fo_objidlock);
951 id = filter->fo_last_objids[group];
952 spin_unlock(&filter->fo_objidlock);
957 /* direct cut-n-paste of mds_blocking_ast() */
958 static int filter_blocking_ast(struct ldlm_lock *lock,
959 struct ldlm_lock_desc *desc,
960 void *data, int flag)
965 if (flag == LDLM_CB_CANCELING) {
966 /* Don't need to do anything here. */
970 /* XXX layering violation! -phil */
971 l_lock(&lock->l_resource->lr_namespace->ns_lock);
972 /* Get this: if filter_blocking_ast is racing with ldlm_intent_policy,
973 * such that filter_blocking_ast is called just before l_i_p takes the
974 * ns_lock, then by the time we get the lock, we might not be the
975 * correct blocking function anymore. So check, and return early, if
977 if (lock->l_blocking_ast != filter_blocking_ast) {
978 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
982 lock->l_flags |= LDLM_FL_CBPENDING;
983 do_ast = (!lock->l_readers && !lock->l_writers);
984 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
987 struct lustre_handle lockh;
990 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
991 ldlm_lock2handle(lock, &lockh);
992 rc = ldlm_cli_cancel(&lockh);
994 CERROR("ldlm_cli_cancel: %d\n", rc);
996 LDLM_DEBUG(lock, "Lock still has references, will be "
1002 extern void *lock_dir(struct inode *dir, struct qstr *name);
1003 extern void unlock_dir(struct inode *dir, void *lock);
1005 static void * filter_lock_dentry(struct obd_device *obd,
1006 struct dentry *dparent, obd_id id)
1012 qstr.len = sprintf(name, LPU64, id);
1013 return lock_dir(dparent->d_inode, &qstr);
1015 down(&dparent->d_inode->i_sem);
1020 /* We never dget the object parent, so DON'T dput it either */
1021 static void filter_parent_unlock(struct dentry *dparent, void *lock)
1024 LASSERT(lock != NULL);
1025 unlock_dir(dparent->d_inode, lock);
1027 up(&dparent->d_inode->i_sem);
1031 /* We never dget the object parent, so DON'T dput it either */
1032 struct dentry *filter_parent(struct obd_device *obd, obd_gr group, obd_id objid)
1034 struct filter_obd *filter = &obd->u.filter;
1035 LASSERT(group < filter->fo_group_count);
1038 if (filter->fo_subdir_count == 0)
1039 return filter->fo_groups[group];
1041 return filter->fo_subdirs[group].dentry[objid & (filter->fo_subdir_count - 1)];
1044 /* We never dget the object parent, so DON'T dput it either */
1045 struct dentry *filter_parent_lock(struct obd_device *obd, obd_gr group,
1046 obd_id objid, void **lock)
1048 unsigned long now = jiffies;
1049 struct dentry *dparent = filter_parent(obd, group, objid);
1051 if (IS_ERR(dparent))
1055 LASSERT(dparent->d_inode);
1057 *lock = filter_lock_dentry(obd, dparent, objid);
1058 if (time_after(jiffies, now + 15 * HZ))
1059 CERROR("slow parent lock %lus\n", (jiffies - now) / HZ);
1063 /* How to get files, dentries, inodes from object id's.
1065 * If dir_dentry is passed, the caller has already locked the parent
1066 * appropriately for this operation (normally a write lock). If
1067 * dir_dentry is NULL, we do a read lock while we do the lookup to
1068 * avoid races with create/destroy and such changing the directory
1069 * internal to the filesystem code. */
1070 struct dentry *filter_fid2dentry(struct obd_device *obd,
1071 struct dentry *dir_dentry,
1072 obd_gr group, obd_id id)
1074 struct dentry *dparent = dir_dentry;
1075 struct dentry *dchild;
1082 CERROR("fatal: invalid object id 0\n");
1083 RETURN(ERR_PTR(-ESTALE));
1086 len = sprintf(name, LPU64, id);
1087 if (dir_dentry == NULL) {
1088 dparent = filter_parent_lock(obd, group, id, &lock);
1089 if (IS_ERR(dparent))
1092 CDEBUG(D_INODE, "looking up object O/%*s/%s\n",
1093 dparent->d_name.len, dparent->d_name.name, name);
1094 dchild = /*ll_*/lookup_one_len(name, dparent, len);
1095 if (dir_dentry == NULL)
1096 filter_parent_unlock(dparent, lock);
1097 if (IS_ERR(dchild)) {
1098 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
1102 CDEBUG(D_INODE, "got child objid %s: %p, count = %d\n",
1103 name, dchild, atomic_read(&dchild->d_count));
1105 LASSERT(atomic_read(&dchild->d_count) > 0);
1110 static int filter_prepare_destroy(struct obd_device *obd, obd_id objid,
1113 struct lustre_handle lockh;
1114 int flags = LDLM_AST_DISCARD_DATA, rc;
1115 struct ldlm_res_id res_id = { .name = { objid, 0, group, 0 } };
1116 ldlm_policy_data_t policy = { .l_extent = { 0, OBD_OBJECT_EOF } };
1119 /* Tell the clients that the object is gone now and that they should
1120 * throw away any cached pages. */
1121 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, res_id,
1122 LDLM_EXTENT, &policy, LCK_PW,
1123 &flags, filter_blocking_ast, ldlm_completion_ast,
1124 NULL, NULL, NULL, 0, NULL, &lockh);
1126 /* We only care about the side-effects, just drop the lock. */
1128 ldlm_lock_decref(&lockh, LCK_PW);
1133 /* Caller must hold LCK_PW on parent and push us into kernel context.
1134 * Caller is also required to ensure that dchild->d_inode exists. */
1135 static int filter_destroy_internal(struct obd_device *obd, obd_id objid,
1136 struct dentry *dparent,
1137 struct dentry *dchild)
1139 struct inode *inode = dchild->d_inode;
1143 if (inode->i_nlink != 1 || atomic_read(&inode->i_count) != 1) {
1144 CERROR("destroying objid %*s nlink = %lu, count = %d\n",
1145 dchild->d_name.len, dchild->d_name.name,
1146 (unsigned long)inode->i_nlink,
1147 atomic_read(&inode->i_count));
1150 rc = vfs_unlink(dparent->d_inode, dchild);
1153 CERROR("error unlinking objid %*s: rc %d\n",
1154 dchild->d_name.len, dchild->d_name.name, rc);
1159 static int filter_intent_policy(struct ldlm_namespace *ns,
1160 struct ldlm_lock **lockp, void *req_cookie,
1161 ldlm_mode_t mode, int flags, void *data)
1163 struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
1164 struct ptlrpc_request *req = req_cookie;
1165 struct ldlm_lock *lock = *lockp, *l = NULL;
1166 struct ldlm_resource *res = lock->l_resource;
1167 ldlm_processing_policy policy;
1168 struct ost_lvb *res_lvb, *reply_lvb;
1169 struct list_head *tmp;
1171 int tmpflags = 0, rc, repsize[2] = {sizeof(struct ldlm_reply),
1172 sizeof(struct ost_lvb) };
1175 policy = ldlm_get_processing_policy(res);
1176 LASSERT(policy != NULL);
1177 LASSERT(req != NULL);
1179 rc = lustre_pack_reply(req, 2, repsize, NULL);
1181 RETURN(req->rq_status = rc);
1183 reply_lvb = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*reply_lvb));
1184 LASSERT(reply_lvb != NULL);
1186 //fixup_handle_for_resent_req(req, lock, &lockh);
1188 /* If we grant any lock at all, it will be a whole-file read lock.
1189 * Call the extent policy function to see if our request can be
1190 * granted, or is blocked. */
1191 lock->l_policy_data.l_extent.start = 0;
1192 lock->l_policy_data.l_extent.end = OBD_OBJECT_EOF;
1193 lock->l_req_mode = LCK_PR;
1195 l_lock(&res->lr_namespace->ns_lock);
1197 res->lr_tmp = &rpc_list;
1198 rc = policy(lock, &tmpflags, 0, &err);
1201 /* FIXME: we should change the policy function slightly, to not make
1202 * this list at all, since we just turn around and free it */
1203 while (!list_empty(&rpc_list)) {
1204 struct ldlm_ast_work *w =
1205 list_entry(rpc_list.next, struct ldlm_ast_work, w_list);
1206 list_del(&w->w_list);
1207 LDLM_LOCK_PUT(w->w_lock);
1208 OBD_FREE(w, sizeof(*w));
1211 if (rc == LDLM_ITER_CONTINUE) {
1212 /* The lock met with no resistance; we're finished. */
1213 l_unlock(&res->lr_namespace->ns_lock);
1214 RETURN(ELDLM_LOCK_REPLACED);
1217 /* Do not grant any lock, but instead send GL callbacks. The extent
1218 * policy nicely created a list of all PW locks for us. We will choose
1219 * the highest of those which are larger than the size in the LVB, if
1220 * any, and perform a glimpse callback. */
1221 down(&res->lr_lvb_sem);
1222 res_lvb = res->lr_lvb_data;
1223 LASSERT(res_lvb != NULL);
1224 reply_lvb->lvb_size = res_lvb->lvb_size;
1225 reply_lvb->lvb_blocks = res_lvb->lvb_blocks;
1226 up(&res->lr_lvb_sem);
1228 list_for_each(tmp, &res->lr_granted) {
1229 struct ldlm_lock *tmplock =
1230 list_entry(tmp, struct ldlm_lock, l_res_link);
1232 if (tmplock->l_granted_mode == LCK_PR)
1235 if (tmplock->l_policy_data.l_extent.end <= reply_lvb->lvb_size)
1239 l = LDLM_LOCK_GET(tmplock);
1243 if (l->l_policy_data.l_extent.start >
1244 tmplock->l_policy_data.l_extent.start)
1248 l = LDLM_LOCK_GET(tmplock);
1250 l_unlock(&res->lr_namespace->ns_lock);
1252 /* There were no PW locks beyond the size in the LVB; finished. */
1254 RETURN(ELDLM_LOCK_ABORTED);
1256 LASSERT(l->l_glimpse_ast != NULL);
1257 rc = l->l_glimpse_ast(l, NULL); /* this will update the LVB */
1258 if (rc != 0 && res->lr_namespace->ns_lvbo &&
1259 res->lr_namespace->ns_lvbo->lvbo_update) {
1260 res->lr_namespace->ns_lvbo->lvbo_update(res, NULL, 0, 1);
1263 down(&res->lr_lvb_sem);
1264 reply_lvb->lvb_size = res_lvb->lvb_size;
1265 reply_lvb->lvb_blocks = res_lvb->lvb_blocks;
1266 up(&res->lr_lvb_sem);
1270 RETURN(ELDLM_LOCK_ABORTED);
1273 static int filter_post_fs_cleanup(struct obd_device *obd)
1277 rc = fsfilt_post_cleanup(obd);
1282 static int filter_group_set_fs_flags(struct obd_device *obd, int group)
1284 struct filter_obd *filter = &obd->u.filter;
1288 /* zero group is not longer valid. */
1291 for (i = 0; i < filter->fo_subdir_count; i++) {
1292 struct dentry *dentry;
1293 dentry = (filter->fo_subdirs + group)->dentry[i];
1294 rc = fsfilt_set_fs_flags(obd, dentry->d_inode,
1295 SM_DO_REC | SM_DO_COW);
1301 static int filter_post_fs_setup(struct obd_device *obd)
1303 struct filter_obd *filter = &obd->u.filter;
1305 struct llog_ctxt *ctxt = NULL;
1307 rc = fsfilt_post_setup(obd, filter->fo_dentry_O);
1311 for (j = 0; j < filter->fo_group_count; j++) {
1312 rc = filter_group_set_fs_flags(obd, j);
1317 fsfilt_get_reint_log_ctxt(obd, filter->fo_sb, &ctxt);
1319 ctxt->loc_obd = obd;
1320 ctxt->loc_idx = LLOG_REINT_ORIG_CTXT;
1321 obd->obd_llog_ctxt[LLOG_REINT_ORIG_CTXT] = ctxt;
1323 fsfilt_set_ost_flags(obd, filter->fo_sb);
1327 /* mount the file system (secretly) */
1328 int filter_common_setup(struct obd_device *obd, obd_count len,
1329 void *buf, char *option)
1331 struct lustre_cfg* lcfg = buf;
1332 struct filter_obd *filter = &obd->u.filter;
1333 struct vfsmount *mnt;
1334 char name[32] = "CATLIST";
1338 dev_clear_rdonly(2);
1340 if (!lcfg->lcfg_inlbuf1 || !lcfg->lcfg_inlbuf2)
1343 obd->obd_fsops = fsfilt_get_ops(lcfg->lcfg_inlbuf2);
1344 if (IS_ERR(obd->obd_fsops))
1345 RETURN(PTR_ERR(obd->obd_fsops));
1347 mnt = do_kern_mount(lcfg->lcfg_inlbuf2, MS_NOATIME | MS_NODIRATIME,
1348 lcfg->lcfg_inlbuf1, option);
1353 if (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3) {
1354 if (*lcfg->lcfg_inlbuf3 == 'f') {
1355 obd->obd_replayable = 1;
1356 obd_sync_filter = 1;
1357 CWARN("%s: recovery enabled\n", obd->obd_name);
1359 if (*lcfg->lcfg_inlbuf3 != 'n') {
1360 CERROR("unrecognised flag '%c'\n",
1361 *lcfg->lcfg_inlbuf3);
1363 // XXX Robert? Why do we get errors here
1364 // GOTO(err_mntput, rc = -EINVAL);
1368 filter->fo_vfsmnt = mnt;
1369 filter->fo_sb = mnt->mnt_sb;
1370 filter->fo_fstype = mnt->mnt_sb->s_type->name;
1371 CDEBUG(D_SUPER, "%s: mnt = %p\n", filter->fo_fstype, mnt);
1373 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1374 obd->obd_lvfs_ctxt.pwdmnt = mnt;
1375 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
1376 obd->obd_lvfs_ctxt.fs = get_ds();
1377 obd->obd_lvfs_ctxt.cb_ops = filter_lvfs_ops;
1379 rc = fsfilt_setup(obd, mnt->mnt_sb);
1381 GOTO(err_mntput, rc);
1383 sema_init(&filter->fo_init_lock, 1);
1384 rc = filter_prep(obd);
1386 GOTO(err_mntput, rc);
1388 filter->fo_destroy_in_progress = 0;
1389 sema_init(&filter->fo_create_lock, 1);
1391 spin_lock_init(&filter->fo_translock);
1392 spin_lock_init(&filter->fo_objidlock);
1393 INIT_LIST_HEAD(&filter->fo_export_list);
1394 sema_init(&filter->fo_alloc_lock, 1);
1395 spin_lock_init(&filter->fo_r_pages.oh_lock);
1396 spin_lock_init(&filter->fo_w_pages.oh_lock);
1397 spin_lock_init(&filter->fo_r_discont_pages.oh_lock);
1398 spin_lock_init(&filter->fo_w_discont_pages.oh_lock);
1399 spin_lock_init(&filter->fo_r_discont_blocks.oh_lock);
1400 spin_lock_init(&filter->fo_w_discont_blocks.oh_lock);
1401 filter->fo_readcache_max_filesize = FILTER_MAX_CACHE_SIZE;
1403 INIT_LIST_HEAD(&filter->fo_llog_list);
1404 spin_lock_init(&filter->fo_llog_list_lock);
1406 obd->obd_namespace = ldlm_namespace_new("filter-tgt",
1407 LDLM_NAMESPACE_SERVER);
1408 if (obd->obd_namespace == NULL)
1409 GOTO(err_post, rc = -ENOMEM);
1410 obd->obd_namespace->ns_lvbp = obd;
1411 obd->obd_namespace->ns_lvbo = &filter_lvbo;
1412 ldlm_register_intent(obd->obd_namespace, filter_intent_policy);
1414 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1415 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
1417 rc = obd_llog_cat_initialize(obd, &obd->obd_llogs, 1, name);
1419 CERROR("failed to setup llogging subsystems\n");
1432 fsfilt_put_ops(obd->obd_fsops);
1436 static int filter_attach(struct obd_device *obd, obd_count len, void *data)
1438 struct lprocfs_static_vars lvars;
1441 lprocfs_init_vars(filter, &lvars);
1442 rc = lprocfs_obd_attach(obd, lvars.obd_vars);
1446 rc = lprocfs_alloc_obd_stats(obd, LPROC_FILTER_LAST);
1450 /* Init obdfilter private stats here */
1451 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_READ_BYTES,
1452 LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
1453 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_WRITE_BYTES,
1454 LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
1456 return lproc_filter_attach_seqstat(obd);
1459 static int filter_detach(struct obd_device *dev)
1461 lprocfs_free_obd_stats(dev);
1462 return lprocfs_obd_detach(dev);
1465 static int filter_setup(struct obd_device *obd, obd_count len, void *buf)
1467 struct lustre_cfg* lcfg = buf;
1470 /* all mount options including errors=remount-ro and asyncdel are passed
1471 * using 4th lcfg param. And it is good, finally we have got rid of
1472 * hardcoded fs types in the code. */
1473 rc = filter_common_setup(obd, len, buf, lcfg->lcfg_inlbuf4);
1476 rc = filter_post_fs_setup(obd);
1480 static int filter_cleanup(struct obd_device *obd, int flags)
1482 struct filter_obd *filter = &obd->u.filter;
1485 if (flags & OBD_OPT_FAILOVER)
1486 CERROR("%s: shutting down for failover; client state will"
1487 " be preserved.\n", obd->obd_name);
1489 if (!list_empty(&obd->obd_exports)) {
1490 CERROR("%s: still has clients!\n", obd->obd_name);
1491 class_disconnect_exports(obd, flags);
1492 if (!list_empty(&obd->obd_exports)) {
1493 CERROR("still has exports after forced cleanup?\n");
1498 ldlm_namespace_free(obd->obd_namespace, flags & OBD_OPT_FORCE);
1500 if (filter->fo_sb == NULL)
1503 filter_post_fs_cleanup(obd);
1506 shrink_dcache_parent(filter->fo_sb->s_root);
1509 if (atomic_read(&filter->fo_vfsmnt->mnt_count) > 1)
1510 CERROR("%s: mount point %p busy, mnt_count: %d\n",
1511 obd->obd_name, filter->fo_vfsmnt,
1512 atomic_read(&filter->fo_vfsmnt->mnt_count));
1515 mntput(filter->fo_vfsmnt);
1516 //destroy_buffers(filter->fo_sb->s_dev);
1517 filter->fo_sb = NULL;
1518 fsfilt_put_ops(obd->obd_fsops);
1521 dev_clear_rdonly(2);
1526 /* nearly identical to mds_connect */
1527 static int filter_connect(struct lustre_handle *conn, struct obd_device *obd,
1528 struct obd_uuid *cluuid, unsigned long connect_flags)
1530 struct obd_export *exp;
1531 struct filter_export_data *fed;
1532 struct filter_client_data *fcd = NULL;
1533 struct filter_obd *filter = &obd->u.filter;
1537 if (conn == NULL || obd == NULL || cluuid == NULL)
1540 rc = class_connect(conn, obd, cluuid);
1543 exp = class_conn2export(conn);
1544 LASSERT(exp != NULL);
1546 fed = &exp->exp_filter_data;
1548 spin_lock_init(&fed->fed_lock);
1550 if (!obd->obd_replayable)
1551 GOTO(cleanup, rc = 0);
1553 OBD_ALLOC(fcd, sizeof(*fcd));
1555 CERROR("filter: out of memory for client data\n");
1556 GOTO(cleanup, rc = -ENOMEM);
1559 memcpy(fcd->fcd_uuid, cluuid, sizeof(fcd->fcd_uuid));
1562 rc = filter_client_add(obd, filter, fed, -1);
1567 OBD_FREE(fcd, sizeof(*fcd));
1568 class_disconnect(exp, 0);
1570 class_export_put(exp);
1575 static int filter_precleanup(struct obd_device *obd, int flags)
1577 struct filter_group_llog *log;
1578 struct filter_obd *filter;
1582 filter = &obd->u.filter;
1584 spin_lock(&filter->fo_llog_list_lock);
1585 while (!list_empty(&filter->fo_llog_list)) {
1586 log = list_entry(filter->fo_llog_list.next,
1587 struct filter_group_llog, list);
1588 list_del(&log->list);
1589 spin_unlock(&filter->fo_llog_list_lock);
1591 rc = obd_llog_finish(obd, log->llogs, 0);
1593 CERROR("failed to cleanup llogging subsystem for %u\n",
1595 OBD_FREE(log->llogs, sizeof(*(log->llogs)));
1596 OBD_FREE(log, sizeof(*log));
1597 spin_lock(&filter->fo_llog_list_lock);
1599 spin_unlock(&filter->fo_llog_list_lock);
1601 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1603 CERROR("failed to cleanup llogging subsystem\n");
1608 /* Do extra sanity checks for grant accounting. We do this at connect,
1609 * disconnect, and statfs RPC time, so it shouldn't be too bad. We can
1610 * always get rid of it or turn it off when we know accounting is good. */
1611 static void filter_grant_sanity_check(struct obd_device *obd, const char *func)
1613 struct filter_export_data *fed;
1614 struct obd_export *exp;
1615 obd_size maxsize = obd->obd_osfs.os_blocks * obd->obd_osfs.os_bsize;
1616 obd_size tot_dirty = 0, tot_pending = 0, tot_granted = 0;
1617 obd_size fo_tot_dirty, fo_tot_pending, fo_tot_granted;
1619 if (list_empty(&obd->obd_exports))
1622 spin_lock(&obd->obd_osfs_lock);
1623 spin_lock(&obd->obd_dev_lock);
1624 list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
1625 fed = &exp->exp_filter_data;
1626 LASSERTF(fed->fed_grant + fed->fed_pending <= maxsize,
1627 "cli %s/%p %lu+%lu > "LPU64"\n",
1628 exp->exp_client_uuid.uuid, exp,
1629 fed->fed_grant, fed->fed_pending, maxsize);
1630 LASSERTF(fed->fed_dirty <= maxsize, "cli %s/%p %lu > "LPU64"\n",
1631 exp->exp_client_uuid.uuid, exp,fed->fed_dirty,maxsize);
1632 CDEBUG(D_CACHE,"%s: cli %s/%p dirty %lu pend %lu grant %lu\n",
1633 obd->obd_name, exp->exp_client_uuid.uuid, exp,
1634 fed->fed_dirty, fed->fed_pending, fed->fed_grant);
1635 tot_granted += fed->fed_grant + fed->fed_pending;
1636 tot_pending += fed->fed_pending;
1637 tot_dirty += fed->fed_dirty;
1639 fo_tot_granted = obd->u.filter.fo_tot_granted;
1640 fo_tot_pending = obd->u.filter.fo_tot_pending;
1641 fo_tot_dirty = obd->u.filter.fo_tot_dirty;
1642 spin_unlock(&obd->obd_dev_lock);
1643 spin_unlock(&obd->obd_osfs_lock);
1645 /* Do these assertions outside the spinlocks so we don't kill system */
1646 if (tot_granted != fo_tot_granted)
1647 CERROR("%s: tot_granted "LPU64" != fo_tot_granted "LPU64"\n",
1648 func, tot_granted, fo_tot_granted);
1649 if (tot_pending != fo_tot_pending)
1650 CERROR("%s: tot_pending "LPU64" != fo_tot_pending "LPU64"\n",
1651 func, tot_pending, fo_tot_pending);
1652 if (tot_dirty != fo_tot_dirty)
1653 CERROR("%s: tot_dirty "LPU64" != fo_tot_dirty "LPU64"\n",
1654 func, tot_dirty, fo_tot_dirty);
1655 if (tot_pending > tot_granted)
1656 CERROR("%s: tot_pending "LPU64" > tot_granted "LPU64"\n",
1657 func, tot_pending, tot_granted);
1658 if (tot_granted > maxsize)
1659 CERROR("%s: tot_granted "LPU64" > maxsize "LPU64"\n",
1660 func, tot_granted, maxsize);
1661 if (tot_dirty > maxsize)
1662 CERROR("%s: tot_dirty "LPU64" > maxsize "LPU64"\n",
1663 func, tot_dirty, maxsize);
1666 /* Remove this client from the grant accounting totals. We also remove
1667 * the export from the obd device under the osfs and dev locks to ensure
1668 * that the filter_grant_sanity_check() calculations are always valid.
1669 * The client should do something similar when it invalidates its import. */
1670 static void filter_grant_discard(struct obd_export *exp)
1672 struct obd_device *obd = exp->exp_obd;
1673 struct filter_obd *filter = &obd->u.filter;
1674 struct filter_export_data *fed = &exp->exp_filter_data;
1676 spin_lock(&obd->obd_osfs_lock);
1677 spin_lock(&exp->exp_obd->obd_dev_lock);
1678 list_del_init(&exp->exp_obd_chain);
1679 spin_unlock(&exp->exp_obd->obd_dev_lock);
1681 CDEBUG(D_CACHE, "%s: cli %s/%p dirty %lu pend %lu grant %lu\n",
1682 obd->obd_name, exp->exp_client_uuid.uuid, exp,
1683 fed->fed_dirty, fed->fed_pending, fed->fed_grant);
1685 LASSERTF(filter->fo_tot_granted >= fed->fed_grant,
1686 "%s: tot_granted "LPU64" cli %s/%p fed_grant %lu\n",
1687 obd->obd_name, filter->fo_tot_granted,
1688 exp->exp_client_uuid.uuid, exp, fed->fed_grant);
1689 filter->fo_tot_granted -= fed->fed_grant;
1690 LASSERTF(exp->exp_obd->u.filter.fo_tot_pending >= fed->fed_pending,
1691 "%s: tot_pending "LPU64" cli %s/%p fed_pending %lu\n",
1692 obd->obd_name, filter->fo_tot_pending,
1693 exp->exp_client_uuid.uuid, exp, fed->fed_pending);
1694 LASSERTF(filter->fo_tot_dirty >= fed->fed_dirty,
1695 "%s: tot_dirty "LPU64" cli %s/%p fed_dirty %lu\n",
1696 obd->obd_name, filter->fo_tot_dirty,
1697 exp->exp_client_uuid.uuid, exp, fed->fed_dirty);
1698 filter->fo_tot_dirty -= fed->fed_dirty;
1702 spin_unlock(&obd->obd_osfs_lock);
1705 static int filter_destroy_export(struct obd_export *exp)
1709 if (exp->exp_filter_data.fed_pending)
1710 CERROR("%s: cli %s/%p has %lu pending on destroyed export\n",
1711 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
1712 exp, exp->exp_filter_data.fed_pending);
1714 target_destroy_export(exp);
1716 if (exp->exp_obd->obd_replayable)
1717 filter_client_free(exp, exp->exp_flags);
1719 filter_grant_discard(exp);
1720 if (!(exp->exp_flags & OBD_OPT_FORCE))
1721 filter_grant_sanity_check(exp->exp_obd, __FUNCTION__);
1726 static void filter_sync_llogs(struct obd_export *dexp)
1728 struct filter_group_llog *fglog, *nlog;
1729 struct obd_device *obd = dexp->exp_obd;
1730 struct filter_obd *filter;
1731 int worked = 0, group;
1732 struct llog_ctxt *ctxt;
1734 filter = &obd->u.filter;
1736 /* we can't sync log holding spinlock. also, we do not want to get
1737 * into livelock. so we do following: loop over MDS's exports in
1738 * group order and skip already synced llogs -bzzz */
1740 /* look for group with min. number, but > worked */
1743 spin_lock(&filter->fo_llog_list_lock);
1744 list_for_each_entry(nlog, &filter->fo_llog_list, list) {
1746 if (nlog->group <= worked) {
1747 /* this group is already synced */
1751 if (group < nlog->group) {
1752 /* we have group with smaller number to sync */
1756 /* store current minimal group */
1758 group = nlog->group;
1760 spin_unlock(&filter->fo_llog_list_lock);
1763 worked = fglog->group;
1764 ctxt = llog_get_context(fglog->llogs,
1765 LLOG_UNLINK_REPL_CTXT);
1766 llog_sync(ctxt, dexp);
1768 } while (fglog != NULL);
1771 /* also incredibly similar to mds_disconnect */
1772 static int filter_disconnect(struct obd_export *exp, int flags)
1774 struct obd_device *obd = exp->exp_obd;
1775 unsigned long irqflags;
1780 class_export_get(exp);
1782 spin_lock_irqsave(&exp->exp_lock, irqflags);
1783 exp->exp_flags = flags;
1784 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
1786 if (!(flags & OBD_OPT_FORCE))
1787 filter_grant_sanity_check(obd, __FUNCTION__);
1788 filter_grant_discard(exp);
1790 /* Disconnect early so that clients can't keep using export */
1791 rc = class_disconnect(exp, flags);
1793 ldlm_cancel_locks_for_export(exp);
1795 fsfilt_sync(obd, obd->u.filter.fo_sb);
1797 /* flush any remaining cancel messages out to the target */
1798 filter_sync_llogs(exp);
1800 class_export_put(exp);
1804 struct dentry *__filter_oa2dentry(struct obd_device *obd,
1805 struct obdo *oa, const char *what)
1807 struct dentry *dchild = NULL;
1810 if (oa->o_valid & OBD_MD_FLGROUP)
1813 dchild = filter_fid2dentry(obd, NULL, group, oa->o_id);
1815 if (IS_ERR(dchild)) {
1816 CERROR("%s error looking up object: "LPU64"\n", what, oa->o_id);
1820 if (dchild->d_inode == NULL) {
1821 CERROR("%s: %s on non-existent object: "LPU64"\n",
1822 obd->obd_name, what, oa->o_id);
1824 RETURN(ERR_PTR(-ENOENT));
1830 static int filter_getattr(struct obd_export *exp, struct obdo *oa,
1831 struct lov_stripe_md *md)
1833 struct dentry *dentry = NULL;
1834 struct obd_device *obd;
1838 obd = class_exp2obd(exp);
1840 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1841 exp->exp_handle.h_cookie);
1845 dentry = filter_oa2dentry(obd, oa);
1847 RETURN(PTR_ERR(dentry));
1849 /* Limit the valid bits in the return data to what we actually use */
1850 oa->o_valid = OBD_MD_FLID;
1851 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
1857 /* this is called from filter_truncate() until we have filter_punch() */
1858 static int filter_setattr(struct obd_export *exp, struct obdo *oa,
1859 struct lov_stripe_md *md, struct obd_trans_info *oti)
1861 struct lvfs_run_ctxt saved;
1862 struct filter_obd *filter;
1863 struct dentry *dentry;
1865 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0 } };
1866 struct ldlm_resource *res;
1871 LASSERT(oti != NULL);
1873 dentry = filter_oa2dentry(exp->exp_obd, oa);
1875 RETURN(PTR_ERR(dentry));
1877 filter = &exp->exp_obd->u.filter;
1879 iattr_from_obdo(&iattr, oa, oa->o_valid);
1881 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
1884 if (iattr.ia_valid & ATTR_SIZE)
1885 down(&dentry->d_inode->i_sem);
1886 handle = fsfilt_start(exp->exp_obd, dentry->d_inode, FSFILT_OP_SETATTR,
1889 GOTO(out_unlock, rc = PTR_ERR(handle));
1891 /* XXX this could be a rwsem instead, if filter_preprw played along */
1892 if (iattr.ia_valid & ATTR_ATTR_FLAG)
1893 rc = fsfilt_iocontrol(exp->exp_obd, dentry->d_inode, NULL,
1895 (long)&iattr.ia_attr_flags);
1897 rc = fsfilt_setattr(exp->exp_obd, dentry, handle, &iattr, 1);
1898 rc = filter_finish_transno(exp, oti, rc);
1899 rc2 = fsfilt_commit(exp->exp_obd, filter->fo_sb, dentry->d_inode, handle, 0);
1901 CERROR("error on commit, err = %d\n", rc2);
1906 if (iattr.ia_valid & ATTR_SIZE) {
1907 res = ldlm_resource_get(exp->exp_obd->obd_namespace, NULL,
1908 res_id, LDLM_EXTENT, 0);
1910 CERROR("!!! resource_get failed for object "LPU64" -- "
1911 "filter_setattr with no lock?\n", oa->o_id);
1913 if (res->lr_namespace->ns_lvbo &&
1914 res->lr_namespace->ns_lvbo->lvbo_update) {
1915 rc = res->lr_namespace->ns_lvbo->lvbo_update
1918 ldlm_resource_putref(res);
1922 oa->o_valid = OBD_MD_FLID;
1923 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
1926 if (iattr.ia_valid & ATTR_SIZE)
1927 up(&dentry->d_inode->i_sem);
1929 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
1935 /* XXX identical to osc_unpackmd */
1936 static int filter_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
1937 struct lov_mds_md *lmm, int lmm_bytes)
1943 if (lmm_bytes < sizeof (*lmm)) {
1944 CERROR("lov_mds_md too small: %d, need %d\n",
1945 lmm_bytes, (int)sizeof(*lmm));
1948 /* XXX LOV_MAGIC etc check? */
1950 if (lmm->lmm_object_id == cpu_to_le64(0)) {
1951 CERROR("lov_mds_md: zero lmm_object_id\n");
1956 lsm_size = lov_stripe_md_size(1);
1960 if (*lsmp != NULL && lmm == NULL) {
1961 OBD_FREE(*lsmp, lsm_size);
1966 if (*lsmp == NULL) {
1967 OBD_ALLOC(*lsmp, lsm_size);
1971 loi_init((*lsmp)->lsm_oinfo);
1975 /* XXX zero *lsmp? */
1976 (*lsmp)->lsm_object_id = le64_to_cpu (lmm->lmm_object_id);
1977 LASSERT((*lsmp)->lsm_object_id);
1980 (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
1985 static void filter_destroy_precreated(struct obd_export *exp, struct obdo *oa,
1986 struct filter_obd *filter)
1988 struct obdo doa; /* XXX obdo on stack */
1993 memset(&doa, 0, sizeof(doa));
1994 if (oa->o_valid & OBD_MD_FLGROUP) {
1995 doa.o_valid |= OBD_MD_FLGROUP;
1996 doa.o_gr = oa->o_gr;
2000 doa.o_mode = S_IFREG;
2001 doa.o_gr = oa->o_gr;
2002 doa.o_valid = oa->o_valid & OBD_MD_FLGROUP;
2004 filter->fo_destroy_in_progress = 1;
2005 down(&filter->fo_create_lock);
2006 if (!filter->fo_destroy_in_progress) {
2007 CERROR("%s: destroy_in_progress already cleared\n",
2008 exp->exp_obd->obd_name);
2009 up(&filter->fo_create_lock);
2014 last = filter_last_id(filter, doa.o_gr);
2015 CWARN("%s: deleting orphan objects from "LPU64" to "LPU64"\n",
2016 exp->exp_obd->obd_name, oa->o_id + 1, last);
2017 for (id = oa->o_id + 1; id <= last; id++) {
2019 filter_destroy(exp, &doa, NULL, NULL);
2022 CDEBUG(D_HA, "%s: after destroy: set last_objids["LPU64"] = "LPU64"\n",
2023 exp->exp_obd->obd_name, doa.o_gr, oa->o_id);
2025 spin_lock(&filter->fo_objidlock);
2026 filter->fo_last_objids[doa.o_gr] = oa->o_id;
2027 spin_unlock(&filter->fo_objidlock);
2029 filter->fo_destroy_in_progress = 0;
2030 up(&filter->fo_create_lock);
2035 /* returns a negative error or a nonnegative number of files to create */
2036 static int filter_should_precreate(struct obd_export *exp, struct obdo *oa,
2039 struct obd_device *obd = exp->exp_obd;
2040 struct filter_obd *filter = &obd->u.filter;
2044 diff = oa->o_id - filter_last_id(filter, oa->o_gr);
2045 CDEBUG(D_INFO, "filter_last_id() = "LPU64" -> diff = %d\n",
2046 filter_last_id(filter, oa->o_gr), diff);
2048 /* delete orphans request */
2049 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2050 (oa->o_flags & OBD_FL_DELORPHAN)) {
2053 if (-diff > 10000) { /* XXX make this smarter */
2054 CERROR("ignoring bogus orphan destroy request: obdid "
2055 LPU64" last_id "LPU64"\n",
2056 oa->o_id, filter_last_id(filter, oa->o_gr));
2059 filter_destroy_precreated(exp, oa, filter);
2060 rc = filter_update_last_objid(obd, group, 0);
2062 CERROR("unable to write lastobjid, but orphans"
2066 /* only precreate if group == 0 and o_id is specfied */
2067 if (!(oa->o_valid & OBD_FL_DELORPHAN) &&
2068 (/*group != 0 ||*/ oa->o_id == 0))
2075 static int filter_precreate_rec(struct obd_device *obd, struct dentry *dentry,
2076 int *number, struct obdo *oa)
2081 rc = fsfilt_precreate_rec(obd, dentry, number, oa);
2086 /* We rely on the fact that only one thread will be creating files in a given
2087 * group at a time, which is why we don't need an atomic filter_get_new_id.
2088 * Even if we had that atomic function, the following race would exist:
2090 * thread 1: gets id x from filter_next_id
2091 * thread 2: gets id (x + 1) from filter_next_id
2092 * thread 2: creates object (x + 1)
2093 * thread 1: tries to create object x, gets -ENOSPC
2095 static int filter_precreate(struct obd_device *obd, struct obdo *oa,
2096 obd_gr group, int *num)
2098 struct dentry *dchild = NULL, *dparent = NULL;
2099 struct filter_obd *filter;
2100 int err = 0, rc = 0, recreate_obj = 0, i;
2102 void *handle = NULL;
2106 filter = &obd->u.filter;
2108 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2109 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2113 CDEBUG(D_HA, "%s: precreating %d objects\n", obd->obd_name, *num);
2115 down(&filter->fo_create_lock);
2117 for (i = 0; i < *num && err == 0; i++) {
2118 int cleanup_phase = 0;
2120 if (filter->fo_destroy_in_progress) {
2121 CWARN("%s: precreate aborted by destroy\n",
2129 last_id = filter_last_id(filter, group);
2130 if (next_id > last_id) {
2131 CERROR("Error: Trying to recreate obj greater"
2132 "than last id "LPD64" > "LPD64"\n",
2134 GOTO(cleanup, rc = -EINVAL);
2137 next_id = filter_last_id(filter, group) + 1;
2140 CDEBUG(D_INFO, "precreate objid "LPU64"\n", next_id);
2142 dparent = filter_parent_lock(obd, group, next_id, &lock);
2143 if (IS_ERR(dparent))
2144 GOTO(cleanup, rc = PTR_ERR(dparent));
2147 /*only do precreate rec record. so clean kml flags here*/
2148 fsfilt_clear_fs_flags(obd, dparent->d_inode,
2151 dchild = filter_fid2dentry(obd, dparent, group, next_id);
2153 GOTO(cleanup, rc = PTR_ERR(dchild));
2156 if (dchild->d_inode != NULL) {
2157 /* This would only happen if lastobjid was bad on disk*/
2158 /* Could also happen if recreating missing obj but
2162 CERROR("%s: Serious error: recreating obj %*s "
2163 "but obj already exists \n",
2164 obd->obd_name, dchild->d_name.len,
2165 dchild->d_name.name);
2168 CERROR("%s: Serious error: objid %*s already "
2169 "exists; is this filesystem corrupt?\n",
2170 obd->obd_name, dchild->d_name.len,
2171 dchild->d_name.name);
2174 GOTO(cleanup, rc = -EEXIST);
2177 handle = fsfilt_start_log(obd, dparent->d_inode,
2178 FSFILT_OP_CREATE, NULL, 1);
2180 GOTO(cleanup, rc = PTR_ERR(handle));
2183 rc = ll_vfs_create(dparent->d_inode, dchild, S_IFREG, NULL);
2185 CERROR("create failed rc = %d\n", rc);
2189 if (!recreate_obj) {
2190 filter_set_last_id(filter, group, next_id);
2191 err = filter_update_last_objid(obd, group, 0);
2193 CERROR("unable to write lastobjid "
2194 "but file created\n");
2196 fsfilt_set_fs_flags(obd, dparent->d_inode, SM_DO_REC);
2199 switch(cleanup_phase) {
2201 err = fsfilt_commit(obd, filter->fo_sb, dparent->d_inode, handle, 0);
2203 CERROR("error on commit, err = %d\n", err);
2210 filter_parent_unlock(dparent, lock);
2221 /* check if we have an error after ll_vfs_create(). It is possible that
2222 * there will be say -ENOSPC and we will leak it. */
2224 rc = filter_precreate_rec(obd, dparent, num, oa);
2226 up(&filter->fo_create_lock);
2228 CDEBUG(D_HA, "%s: server last_objid for group "LPU64": "LPU64"\n",
2229 obd->obd_name, group, filter->fo_last_objids[group]);
2231 CDEBUG(D_HA, "%s: filter_precreate() created %d objects\n",
2237 static int filter_create(struct obd_export *exp, struct obdo *oa,
2238 struct lov_stripe_md **ea, struct obd_trans_info *oti)
2240 struct obd_device *obd = NULL;
2241 struct filter_obd *filter;
2242 struct lvfs_run_ctxt saved;
2243 struct lov_stripe_md *lsm = NULL;
2244 struct filter_export_data *fed;
2245 char str[PTL_NALFMT_SIZE];
2246 int group = oa->o_gr, rc = 0, diff, recreate_objs = 0;
2249 if (!(oa->o_valid & OBD_MD_FLGROUP) || group == 0) {
2250 portals_nid2str(exp->exp_connection->c_peer.peer_ni->pni_number,
2251 exp->exp_connection->c_peer.peer_nid, str);
2252 CERROR("!!! nid "LPX64"/%s sent invalid object group %d\n",
2253 exp->exp_connection->c_peer.peer_nid, str, group);
2257 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2258 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2263 fed = &exp->exp_filter_data;
2264 filter = &obd->u.filter;
2266 if (fed->fed_group != group && !recreate_objs &&
2267 !(oa->o_valid & OBD_MD_REINT)) {
2268 portals_nid2str(exp->exp_connection->c_peer.peer_ni->pni_number,
2269 exp->exp_connection->c_peer.peer_nid, str);
2270 CERROR("!!! This export (nid "LPX64"/%s) used object group %d "
2271 "earlier; now it's trying to use group %d! This could "
2272 "be a bug in the MDS. Tell CFS.\n",
2273 exp->exp_connection->c_peer.peer_nid, str,
2274 fed->fed_group, group);
2278 CDEBUG(D_INFO, "filter_create(od->o_gr=%d,od->o_id="LPU64")\n",
2283 rc = obd_alloc_memmd(exp, &lsm);
2290 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2292 if (oa->o_valid & OBD_MD_REINT) {
2293 int num = *((int*)oa->o_inline);
2294 rc = filter_precreate(obd, oa, oa->o_gr, &num);
2295 } else if (recreate_objs) {
2296 if (oa->o_id > filter_last_id(&obd->u.filter, group)) {
2297 CERROR("recreate objid "LPU64" > last id "LPU64"\n",
2298 oa->o_id, filter_last_id(&obd->u.filter, group));
2302 rc = filter_precreate(obd, oa, group, &diff);
2305 diff = filter_should_precreate(exp, oa, group);
2307 oa->o_id = filter_last_id(&obd->u.filter, group);
2308 rc = filter_precreate(obd, oa, group, &diff);
2310 oa->o_valid = OBD_MD_FLID;
2314 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2315 if (rc && ea != NULL && *ea != lsm) {
2316 obd_free_memmd(exp, &lsm);
2317 } else if (rc == 0 && ea != NULL) {
2318 /* XXX LOV STACKING: the lsm that is passed to us from
2319 * LOV does not have valid lsm_oinfo data structs, so
2320 * don't go touching that. This needs to be fixed in a
2322 lsm->lsm_object_id = oa->o_id;
2323 lsm->lsm_object_gr = oa->o_gr;
2330 static int filter_destroy(struct obd_export *exp, struct obdo *oa,
2331 struct lov_stripe_md *ea, struct obd_trans_info *oti)
2333 struct obd_device *obd;
2334 struct filter_obd *filter;
2335 struct dentry *dchild = NULL, *dparent = NULL;
2336 struct lvfs_run_ctxt saved;
2337 void *handle = NULL;
2338 struct llog_cookie *fcc = NULL;
2339 int rc, rc2, cleanup_phase = 0, have_prepared = 0;
2343 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
2346 filter = &obd->u.filter;
2348 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2351 dparent = filter_parent_lock(obd, oa->o_gr, oa->o_id, &lock);
2352 if (IS_ERR(dparent))
2353 GOTO(cleanup, rc = PTR_ERR(dparent));
2356 dchild = filter_fid2dentry(obd, dparent, oa->o_gr, oa->o_id);
2358 GOTO(cleanup, rc = -ENOENT);
2361 if (dchild->d_inode == NULL) {
2362 CDEBUG(D_INODE, "destroying non-existent object "LPU64"\n",
2364 GOTO(cleanup, rc = -ENOENT);
2367 if (!have_prepared) {
2368 /* If we're really going to destroy the object, get ready
2369 * by getting the clients to discard their cached data.
2371 * We have to drop the parent lock, because
2372 * filter_prepare_destroy will acquire a PW on the object, and
2373 * we don't want to deadlock with an incoming write to the
2374 * object, which has the extent PW and then wants to get the
2375 * parent dentry to do the lookup.
2377 * We dput the child because it's not worth the extra
2378 * complication of condition the above code to skip it on the
2379 * second time through. */
2381 filter_parent_unlock(dparent, lock);
2383 filter_prepare_destroy(obd, oa->o_id, oa->o_gr);
2388 handle = fsfilt_start_log(obd, dparent->d_inode, FSFILT_OP_UNLINK, oti, 1);
2390 GOTO(cleanup, rc = PTR_ERR(handle));
2394 /* Our MDC connection is established by the MDS to us */
2395 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2396 OBD_ALLOC(fcc, sizeof(*fcc));
2398 memcpy(fcc, obdo_logcookie(oa), sizeof(*fcc));
2401 rc = filter_destroy_internal(obd, oa->o_id, dparent, dchild);
2404 switch(cleanup_phase) {
2408 fsfilt_add_journal_cb(obd, filter->fo_sb, 0,
2410 filter_cancel_cookies_cb,
2413 fsfilt_add_journal_cb(obd, filter->fo_sb, 0,
2415 filter_cancel_cookies_cb,
2418 rc = filter_finish_transno(exp, oti, rc);
2419 rc2 = fsfilt_commit(obd, filter->fo_sb, dparent->d_inode,
2422 CERROR("error on commit, err = %d\n", rc2);
2429 filter_parent_unlock(dparent, lock);
2431 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2434 CERROR("invalid cleanup_phase %d\n", cleanup_phase);
2441 /* NB start and end are used for punch, but not truncate */
2442 static int filter_truncate(struct obd_export *exp, struct obdo *oa,
2443 struct lov_stripe_md *lsm,
2444 obd_off start, obd_off end,
2445 struct obd_trans_info *oti)
2450 if (end != OBD_OBJECT_EOF)
2451 CERROR("PUNCH not supported, only truncate: end = "LPX64"\n",
2454 CDEBUG(D_INODE, "calling truncate for object "LPU64", valid = %x, "
2455 "o_size = "LPD64"\n", oa->o_id, oa->o_valid, start);
2457 error = filter_setattr(exp, oa, NULL, oti);
2461 static int filter_sync(struct obd_export *exp, struct obdo *oa,
2462 struct lov_stripe_md *lsm, obd_off start, obd_off end)
2464 struct obd_device *obd = exp->exp_obd;
2465 struct lvfs_run_ctxt saved;
2466 struct filter_obd *filter;
2467 struct dentry *dentry;
2468 struct llog_ctxt *ctxt;
2472 filter = &obd->u.filter;
2474 /* an objid of zero is taken to mean "sync whole filesystem" */
2475 if (!oa || !(oa->o_valid & OBD_MD_FLID)) {
2476 rc = fsfilt_sync(obd, filter->fo_sb);
2477 /* flush any remaining cancel messages out to the target */
2478 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_REPL_CTXT);
2479 llog_sync(ctxt, exp);
2483 dentry = filter_oa2dentry(obd, oa);
2485 RETURN(PTR_ERR(dentry));
2487 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2489 down(&dentry->d_inode->i_sem);
2490 rc = filemap_fdatasync(dentry->d_inode->i_mapping);
2492 /* just any file to grab fsync method - "file" arg unused */
2493 struct file *file = filter->fo_rcvd_filp;
2495 if (file->f_op && file->f_op->fsync)
2496 rc = file->f_op->fsync(NULL, dentry, 1);
2498 rc2 = filemap_fdatawait(dentry->d_inode->i_mapping);
2502 up(&dentry->d_inode->i_sem);
2504 oa->o_valid = OBD_MD_FLID;
2505 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
2507 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2513 static int filter_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2514 unsigned long max_age)
2516 struct filter_obd *filter = &obd->u.filter;
2517 int blockbits = filter->fo_sb->s_blocksize_bits;
2521 /* at least try to account for cached pages. its still racey and
2522 * might be under-reporting if clients haven't announced their
2523 * caches with brw recently */
2524 spin_lock(&obd->obd_osfs_lock);
2525 rc = fsfilt_statfs(obd, filter->fo_sb, max_age);
2526 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
2527 spin_unlock(&obd->obd_osfs_lock);
2529 CDEBUG(D_SUPER | D_CACHE, "blocks cached "LPU64" granted "LPU64
2530 " pending "LPU64" free "LPU64" avail "LPU64"\n",
2531 filter->fo_tot_dirty, filter->fo_tot_granted,
2532 filter->fo_tot_pending,
2533 osfs->os_bfree << blockbits, osfs->os_bavail << blockbits);
2535 filter_grant_sanity_check(obd, __FUNCTION__);
2537 osfs->os_bavail -= min(osfs->os_bavail,
2538 (filter->fo_tot_dirty + filter->fo_tot_pending +
2539 osfs->os_bsize -1) >> blockbits);
2544 static int filter_get_info(struct obd_export *exp, __u32 keylen,
2545 void *key, __u32 *vallen, void *val)
2547 struct filter_export_data *fed = &exp->exp_filter_data;
2548 struct obd_device *obd;
2551 obd = class_exp2obd(exp);
2553 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2554 exp->exp_handle.h_cookie);
2558 if (keylen == strlen("blocksize") &&
2559 memcmp(key, "blocksize", keylen) == 0) {
2560 __u32 *blocksize = val;
2561 *vallen = sizeof(*blocksize);
2562 *blocksize = obd->u.filter.fo_sb->s_blocksize;
2566 if (keylen == strlen("blocksize_bits") &&
2567 memcmp(key, "blocksize_bits", keylen) == 0) {
2568 __u32 *blocksize_bits = val;
2569 *vallen = sizeof(*blocksize_bits);
2570 *blocksize_bits = obd->u.filter.fo_sb->s_blocksize_bits;
2574 if (keylen >= strlen("last_id") && memcmp(key, "last_id", 7) == 0) {
2575 obd_id *last_id = val;
2576 *last_id = filter_last_id(&obd->u.filter, fed->fed_group);
2579 if (keylen >= strlen("reint_log") && memcmp(key, "reint_log", 9) == 0) {
2580 /*Get log_context handle*/
2581 unsigned long *llh_handle = val;
2582 *vallen = sizeof(unsigned long);
2583 *llh_handle = (unsigned long)obd->obd_llog_ctxt[LLOG_REINT_ORIG_CTXT];
2586 if (keylen >= strlen("cache_sb") && memcmp(key, "cache_sb", 8) == 0) {
2587 /*Get log_context handle*/
2588 unsigned long *sb = val;
2589 *vallen = sizeof(unsigned long);
2590 *sb = (unsigned long)obd->u.filter.fo_sb;
2594 CDEBUG(D_IOCTL, "invalid key\n");
2598 struct obd_llogs *filter_grab_llog_for_group(struct obd_device *obd, int group)
2600 struct filter_group_llog *fglog, *nlog;
2601 char name[32] = "CATLIST";
2602 struct filter_obd *filter;
2603 struct list_head *cur;
2606 filter = &obd->u.filter;
2608 spin_lock(&filter->fo_llog_list_lock);
2609 list_for_each(cur, &filter->fo_llog_list) {
2610 fglog = list_entry(cur, struct filter_group_llog, list);
2611 if (fglog->group == group) {
2612 spin_unlock(&filter->fo_llog_list_lock);
2613 RETURN(fglog->llogs);
2616 spin_unlock(&filter->fo_llog_list_lock);
2618 OBD_ALLOC(fglog, sizeof(*fglog));
2621 fglog->group = group;
2623 OBD_ALLOC(fglog->llogs, sizeof(struct obd_llogs));
2624 if (fglog->llogs == NULL) {
2625 OBD_FREE(fglog, sizeof(*fglog));
2629 spin_lock(&filter->fo_llog_list_lock);
2630 list_for_each(cur, &filter->fo_llog_list) {
2631 nlog = list_entry(cur, struct filter_group_llog, list);
2632 LASSERT(nlog->group != group);
2634 list_add(&fglog->list, &filter->fo_llog_list);
2635 spin_unlock(&filter->fo_llog_list_lock);
2637 rc = obd_llog_cat_initialize(obd, fglog->llogs, 1, name);
2639 OBD_FREE(fglog->llogs, sizeof(*(fglog->llogs)));
2640 OBD_FREE(fglog, sizeof(*fglog));
2644 CDEBUG(D_OTHER, "%s: new llog 0x%p for group %u\n", obd->obd_name,
2645 fglog->llogs, group);
2647 RETURN(fglog->llogs);
2650 static int filter_set_info(struct obd_export *exp, __u32 keylen,
2651 void *key, __u32 vallen, void *val)
2653 struct lvfs_run_ctxt saved;
2654 struct filter_export_data *fed = &exp->exp_filter_data;
2655 struct obd_device *obd;
2656 struct lustre_handle conn;
2657 struct obd_llogs *llog;
2658 struct llog_ctxt *ctxt;
2663 conn.cookie = exp->exp_handle.h_cookie;
2667 CDEBUG(D_IOCTL, "invalid exp %p cookie "LPX64"\n",
2672 if (keylen < strlen("mds_conn") ||
2673 memcmp(key, "mds_conn", keylen) != 0)
2676 group = *((__u32 *)val);
2677 if (fed->fed_group != 0 && fed->fed_group != group) {
2678 char str[PTL_NALFMT_SIZE];
2679 portals_nid2str(exp->exp_connection->c_peer.peer_ni->pni_number,
2680 exp->exp_connection->c_peer.peer_nid, str);
2681 CERROR("!!! This export (nid "LPX64"/%s) used object group %d "
2682 "earlier; now it's trying to use group %d! This could "
2683 "be a bug in the MDS. Tell CFS.\n",
2684 exp->exp_connection->c_peer.peer_nid, str,
2685 fed->fed_group, group);
2688 fed->fed_group = group;
2689 CWARN("Received MDS connection ("LPX64"); group %d\n", conn.cookie,
2694 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2695 rc = filter_read_groups(obd, group, 1);
2696 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2698 CERROR("can't read group %u\n", group);
2701 rc = filter_group_set_fs_flags(obd, group);
2703 CERROR("can't set kml flags %u\n", group);
2706 llog = filter_grab_llog_for_group(obd, group);
2707 LASSERT(llog != NULL);
2709 ctxt = llog_get_context(llog, LLOG_UNLINK_REPL_CTXT);
2710 LASSERT(ctxt != NULL);
2711 rc = llog_receptor_accept(ctxt, exp->exp_imp_reverse);
2715 int filter_iocontrol(unsigned int cmd, struct obd_export *exp,
2716 int len, void *karg, void *uarg)
2718 struct obd_device *obd = exp->exp_obd;
2719 struct obd_ioctl_data *data = karg;
2723 case OBD_IOC_ABORT_RECOVERY:
2724 target_stop_recovery_thread(obd);
2727 case OBD_IOC_SET_READONLY: {
2729 struct super_block *sb = obd->u.filter.fo_sb;
2730 struct inode *inode = sb->s_root->d_inode;
2731 BDEVNAME_DECLARE_STORAGE(tmp);
2732 CERROR("setting device %s read-only\n",
2733 ll_bdevname(sb, tmp));
2735 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
2737 (void)fsfilt_commit(obd, sb, inode, handle, 1);
2739 dev_set_rdonly(ll_sbdev(obd->u.filter.fo_sb), 2);
2743 case OBD_IOC_CATLOGLIST: {
2744 rc = llog_catalog_list(obd, 1, data);
2748 case OBD_IOC_SNAP_ADD: {
2749 char *name = data->ioc_inlbuf1;
2751 rc = fsfilt_set_snap_item(obd, obd->u.filter.fo_sb, name);
2755 case OBD_IOC_LLOG_CANCEL:
2756 case OBD_IOC_LLOG_REMOVE:
2757 case OBD_IOC_LLOG_INFO:
2758 case OBD_IOC_LLOG_PRINT: {
2759 /* FIXME to be finished */
2760 RETURN(-EOPNOTSUPP);
2762 struct llog_ctxt *ctxt = NULL;
2764 push_ctxt(&saved, &ctxt->loc_ctxt, NULL);
2765 rc = llog_ioctl(ctxt, cmd, data);
2766 pop_ctxt(&saved, &ctxt->loc_ctxt, NULL);
2779 static struct llog_operations filter_unlink_repl_logops;
2780 static struct llog_operations filter_size_orig_logops = {
2781 lop_setup: llog_obd_origin_setup,
2782 lop_cleanup: llog_catalog_cleanup,
2783 lop_add: llog_catalog_add,
2786 static int filter_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
2787 struct obd_device *tgt, int count,
2788 struct llog_catid *catid)
2790 struct llog_ctxt *ctxt;
2794 filter_unlink_repl_logops = llog_client_ops;
2795 filter_unlink_repl_logops.lop_cancel = llog_obd_repl_cancel;
2796 filter_unlink_repl_logops.lop_connect = llog_repl_connect;
2797 filter_unlink_repl_logops.lop_sync = llog_obd_repl_sync;
2799 rc = obd_llog_setup(obd, llogs, LLOG_UNLINK_REPL_CTXT, tgt, 0, NULL,
2800 &filter_unlink_repl_logops);
2803 /* FIXME - assign unlink_cb for filter's recovery */
2804 ctxt = llog_get_context(llogs, LLOG_UNLINK_REPL_CTXT);
2805 ctxt->llog_proc_cb = filter_recov_log_unlink_cb;
2807 /* FIXME - count should be 1 to setup size log */
2808 rc = obd_llog_setup(obd, llogs, LLOG_SIZE_ORIG_CTXT, tgt, 0,
2809 &catid->lci_logid, &filter_size_orig_logops);
2813 static int filter_llog_finish(struct obd_device *obd,
2814 struct obd_llogs *llogs, int count)
2819 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_UNLINK_REPL_CTXT));
2823 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_SIZE_ORIG_CTXT));
2827 static int filter_llog_connect(struct obd_device *obd,
2828 struct llogd_conn_body *body)
2830 struct llog_ctxt *ctxt;
2831 struct obd_llogs *llog;
2835 CDEBUG(D_OTHER, "handle connect for %s: %u/%u/%u\n", obd->obd_name,
2836 (unsigned) body->lgdc_logid.lgl_ogr,
2837 (unsigned) body->lgdc_logid.lgl_oid,
2838 (unsigned) body->lgdc_logid.lgl_ogen);
2839 llog = filter_grab_llog_for_group(obd, body->lgdc_logid.lgl_ogr);
2840 LASSERT(llog != NULL);
2841 ctxt = llog_get_context(llog, body->lgdc_ctxt_idx);
2842 rc = llog_connect(ctxt, 1, &body->lgdc_logid,
2843 &body->lgdc_gen, NULL);
2845 CERROR("failed to connect\n");
2850 static struct dentry *filter_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
2853 return filter_fid2dentry(data, NULL, gr, id);
2856 static struct lvfs_callback_ops filter_lvfs_ops = {
2857 l_fid2dentry: filter_lvfs_fid2dentry,
2860 static struct obd_ops filter_obd_ops = {
2861 .o_owner = THIS_MODULE,
2862 .o_attach = filter_attach,
2863 .o_detach = filter_detach,
2864 .o_get_info = filter_get_info,
2865 .o_set_info = filter_set_info,
2866 .o_setup = filter_setup,
2867 .o_precleanup = filter_precleanup,
2868 .o_cleanup = filter_cleanup,
2869 .o_connect = filter_connect,
2870 .o_disconnect = filter_disconnect,
2871 .o_statfs = filter_statfs,
2872 .o_getattr = filter_getattr,
2873 .o_unpackmd = filter_unpackmd,
2874 .o_create = filter_create,
2875 .o_setattr = filter_setattr,
2876 .o_destroy = filter_destroy,
2877 .o_brw = filter_brw,
2878 .o_punch = filter_truncate,
2879 .o_sync = filter_sync,
2880 .o_preprw = filter_preprw,
2881 .o_commitrw = filter_commitrw,
2882 .o_do_cow = filter_do_cow,
2883 .o_write_extents = filter_write_extents,
2884 .o_destroy_export = filter_destroy_export,
2885 .o_llog_init = filter_llog_init,
2886 .o_llog_finish = filter_llog_finish,
2887 .o_llog_connect = filter_llog_connect,
2888 .o_iocontrol = filter_iocontrol,
2891 static struct obd_ops filter_sanobd_ops = {
2892 .o_owner = THIS_MODULE,
2893 .o_attach = filter_attach,
2894 .o_detach = filter_detach,
2895 .o_get_info = filter_get_info,
2896 .o_set_info = filter_set_info,
2897 .o_setup = filter_san_setup,
2898 .o_precleanup = filter_precleanup,
2899 .o_cleanup = filter_cleanup,
2900 .o_connect = filter_connect,
2901 .o_disconnect = filter_disconnect,
2902 .o_statfs = filter_statfs,
2903 .o_getattr = filter_getattr,
2904 .o_unpackmd = filter_unpackmd,
2905 .o_create = filter_create,
2906 .o_setattr = filter_setattr,
2907 .o_destroy = filter_destroy,
2908 .o_brw = filter_brw,
2909 .o_punch = filter_truncate,
2910 .o_sync = filter_sync,
2911 .o_preprw = filter_preprw,
2912 .o_commitrw = filter_commitrw,
2913 .o_do_cow = filter_do_cow,
2914 .o_write_extents = filter_write_extents,
2915 .o_san_preprw = filter_san_preprw,
2916 .o_destroy_export = filter_destroy_export,
2917 .o_llog_init = filter_llog_init,
2918 .o_llog_finish = filter_llog_finish,
2919 .o_llog_connect = filter_llog_connect,
2920 .o_iocontrol = filter_iocontrol,
2923 static int __init obdfilter_init(void)
2925 struct lprocfs_static_vars lvars;
2928 printk(KERN_INFO "Lustre: Filtering OBD driver; info@clusterfs.com\n");
2930 lprocfs_init_vars(filter, &lvars);
2932 rc = class_register_type(&filter_obd_ops, NULL, lvars.module_vars,
2933 OBD_FILTER_DEVICENAME);
2937 rc = class_register_type(&filter_sanobd_ops, NULL, lvars.module_vars,
2938 OBD_FILTER_SAN_DEVICENAME);
2940 class_unregister_type(OBD_FILTER_DEVICENAME);
2944 static void __exit obdfilter_exit(void)
2946 class_unregister_type(OBD_FILTER_SAN_DEVICENAME);
2947 class_unregister_type(OBD_FILTER_DEVICENAME);
2950 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2951 MODULE_DESCRIPTION("Lustre Filtering OBD driver");
2952 MODULE_LICENSE("GPL");
2954 module_init(obdfilter_init);
2955 module_exit(obdfilter_exit);