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 #include <linux/sched.h>
45 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
46 # include <linux/mount.h>
47 # include <linux/buffer_head.h>
50 #include <linux/obd_class.h>
51 #include <linux/obd_lov.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_ver.h>
57 #include <linux/lustre_commit_confd.h>
58 #include <libcfs/list.h>
59 #include <linux/lustre_disk.h>
60 #include <linux/lustre_quota.h>
62 #include "filter_internal.h"
64 static struct lvfs_callback_ops filter_lvfs_ops;
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->lsd_last_transno) + 1;
94 filter->fo_fsd->lsd_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->lsd_last_transno))
101 filter->fo_fsd->lsd_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 CERROR("%s: client idx %d is %lld\n", exp->exp_obd->obd_name,
113 fed->fed_lr_idx, fed->fed_lr_off);
116 fsfilt_add_journal_cb(exp->exp_obd, last_rcvd, oti->oti_handle,
117 filter_commit_cb, NULL);
118 err = fsfilt_write_record(exp->exp_obd, filter->fo_rcvd_filp,
119 fcd, sizeof(*fcd), &off, 0);
127 CDEBUG(log_pri, "wrote trans "LPU64" for client %s at #%d: err = %d\n",
128 last_rcvd, fcd->fcd_uuid, fed->fed_lr_idx, err);
133 void f_dput(struct dentry *dentry)
135 /* Can't go inside filter_ddelete because it can block */
136 CDEBUG(D_INODE, "putting %s: %p, count = %d\n",
137 dentry->d_name.name, dentry, atomic_read(&dentry->d_count) - 1);
138 LASSERT(atomic_read(&dentry->d_count) > 0);
143 /* Add client data to the FILTER. We use a bitmap to locate a free space
144 * in the last_rcvd file if cl_idx is -1 (i.e. a new client).
145 * Otherwise, we have just read the data from the last_rcvd file and
146 * we know its offset. */
147 static int filter_client_add(struct obd_device *obd, struct filter_obd *filter,
148 struct filter_export_data *fed, int cl_idx)
150 unsigned long *bitmap = filter->fo_last_rcvd_slots;
151 int new_client = (cl_idx == -1);
154 LASSERT(bitmap != NULL);
155 LASSERTF(cl_idx > -2, "%d\n", cl_idx);
157 /* XXX if fcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
158 if (!strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid))
161 /* the bitmap operations can handle cl_idx > sizeof(long) * 8, so
162 * there's no need for extra complication here
165 cl_idx = find_first_zero_bit(bitmap, FILTER_LR_MAX_CLIENTS);
167 if (cl_idx >= FILTER_LR_MAX_CLIENTS) {
168 CERROR("no client slots - fix FILTER_LR_MAX_CLIENTS\n");
171 if (test_and_set_bit(cl_idx, bitmap)) {
172 cl_idx = find_next_zero_bit(bitmap,
173 FILTER_LR_MAX_CLIENTS,
178 if (test_and_set_bit(cl_idx, bitmap)) {
179 CERROR("FILTER client %d: bit already set in bitmap!\n",
185 fed->fed_lr_idx = cl_idx;
186 fed->fed_lr_off = le32_to_cpu(filter->fo_fsd->lsd_client_start) +
187 cl_idx * le16_to_cpu(filter->fo_fsd->lsd_client_size);
188 LASSERTF(fed->fed_lr_off > 0, "fed_lr_off = %llu\n", fed->fed_lr_off);
190 CDEBUG(D_INFO, "client at index %d (%llu) with UUID '%s' added\n",
191 fed->fed_lr_idx, fed->fed_lr_off, fed->fed_fcd->fcd_uuid);
194 struct lvfs_run_ctxt saved;
195 loff_t off = fed->fed_lr_off;
199 CDEBUG(D_INFO, "writing client fcd at idx %u (%llu) (len %u)\n",
200 fed->fed_lr_idx,off,(unsigned int)sizeof(*fed->fed_fcd));
202 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
203 /* Transaction needed to fix bug 1403 */
204 handle = fsfilt_start(obd,
205 filter->fo_rcvd_filp->f_dentry->d_inode,
206 FSFILT_OP_SETATTR, NULL);
207 if (IS_ERR(handle)) {
208 err = PTR_ERR(handle);
209 CERROR("unable to start transaction: rc %d\n", err);
211 err = fsfilt_write_record(obd, filter->fo_rcvd_filp,
213 sizeof(*fed->fed_fcd),
216 filter->fo_rcvd_filp->f_dentry->d_inode,
219 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
222 CERROR("error writing %s client idx %u: rc %d\n",
223 LAST_RCVD, fed->fed_lr_idx, err);
230 static int filter_client_free(struct obd_export *exp)
232 struct filter_export_data *fed = &exp->exp_filter_data;
233 struct filter_obd *filter = &exp->exp_obd->u.filter;
234 struct obd_device *obd = exp->exp_obd;
235 struct filter_client_data zero_fcd;
236 struct lvfs_run_ctxt saved;
241 if (fed->fed_fcd == NULL)
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 CDEBUG(D_INFO, "freeing client at idx %u, offset %lld with UUID '%s'\n",
249 fed->fed_lr_idx, off, fed->fed_fcd->fcd_uuid);
251 LASSERT(filter->fo_last_rcvd_slots != NULL);
253 off = fed->fed_lr_off;
255 /* Don't clear fed_lr_idx here as it is likely also unset. At worst
256 * we leak a client slot that will be cleaned on the next recovery. */
258 CERROR("%s: client idx %d has med_off %lld\n",
259 obd->obd_name, fed->fed_lr_idx, off);
260 GOTO(free, rc = -EINVAL);
263 /* Clear the bit _after_ zeroing out the client so we don't
264 race with filter_client_add and zero out new clients.*/
265 if (!test_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
266 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
271 if (!(exp->exp_flags & OBD_OPT_FAILOVER)) {
272 memset(&zero_fcd, 0, sizeof zero_fcd);
273 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
274 rc = fsfilt_write_record(obd, filter->fo_rcvd_filp, &zero_fcd,
275 sizeof(zero_fcd), &off, 0);
278 /* update server's transno */
279 filter_update_server_data(obd, filter->fo_rcvd_filp,
281 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
283 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
284 "zeroing out client %s at idx %u (%llu) in %s rc %d\n",
285 fed->fed_fcd->fcd_uuid, fed->fed_lr_idx, fed->fed_lr_off,
289 if (!test_and_clear_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
290 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
297 OBD_FREE(fed->fed_fcd, sizeof(*fed->fed_fcd));
303 static int filter_free_server_data(struct filter_obd *filter)
305 OBD_FREE(filter->fo_fsd, sizeof(*filter->fo_fsd));
306 filter->fo_fsd = NULL;
307 OBD_FREE(filter->fo_last_rcvd_slots, FILTER_LR_MAX_CLIENTS / 8);
308 filter->fo_last_rcvd_slots = NULL;
312 /* assumes caller is already in kernel ctxt */
313 int filter_update_server_data(struct obd_device *obd, struct file *filp,
314 struct lr_server_data *fsd, int force_sync)
320 CDEBUG(D_INODE, "server uuid : %s\n", fsd->lsd_uuid);
321 CDEBUG(D_INODE, "server last_rcvd : "LPU64"\n",
322 le64_to_cpu(fsd->lsd_last_transno));
323 CDEBUG(D_INODE, "server last_mount: "LPU64"\n",
324 le64_to_cpu(fsd->lsd_mount_count));
326 rc = fsfilt_write_record(obd, filp, fsd, sizeof(*fsd), &off,force_sync);
328 CERROR("error writing lr_server_data: rc = %d\n", rc);
333 int filter_update_last_objid(struct obd_device *obd, obd_gr group,
336 struct filter_obd *filter = &obd->u.filter;
342 CDEBUG(D_INODE, "%s: server last_objid for group "LPU64": "LPU64"\n",
343 obd->obd_name, group, filter->fo_last_objids[group]);
345 tmp = cpu_to_le64(filter->fo_last_objids[group]);
346 rc = fsfilt_write_record(obd, filter->fo_last_objid_files[group],
347 &tmp, sizeof(tmp), &off, force_sync);
349 CERROR("error writing group "LPU64" last objid: rc = %d\n",
354 /* assumes caller has already in kernel ctxt */
355 static int filter_init_server_data(struct obd_device *obd, struct file * filp)
357 struct filter_obd *filter = &obd->u.filter;
358 struct lr_server_data *fsd;
359 struct filter_client_data *fcd = NULL;
360 struct inode *inode = filp->f_dentry->d_inode;
361 unsigned long last_rcvd_size = inode->i_size;
367 /* ensure padding in the struct is the correct size */
368 LASSERT (offsetof(struct lr_server_data, lsd_padding) +
369 sizeof(fsd->lsd_padding) == FILTER_LR_SERVER_SIZE);
370 LASSERT (offsetof(struct filter_client_data, fcd_padding) +
371 sizeof(fcd->fcd_padding) == FILTER_LR_CLIENT_SIZE);
372 LASSERT(FILTER_LR_CLIENT_SIZE == LR_CLIENT_SIZE);
373 LASSERT(FILTER_LR_CLIENT_START == LR_CLIENT_START);
375 OBD_ALLOC(fsd, sizeof(*fsd));
378 filter->fo_fsd = fsd;
380 OBD_ALLOC(filter->fo_last_rcvd_slots, FILTER_LR_MAX_CLIENTS / 8);
381 if (filter->fo_last_rcvd_slots == NULL) {
382 OBD_FREE(fsd, sizeof(*fsd));
386 if (last_rcvd_size == 0) {
387 CWARN("%s: initializing new %s\n", obd->obd_name, LAST_RCVD);
389 memcpy(fsd->lsd_uuid, obd->obd_uuid.uuid,sizeof(fsd->lsd_uuid));
390 fsd->lsd_last_transno = 0;
391 mount_count = fsd->lsd_mount_count = 0;
392 fsd->lsd_server_size = cpu_to_le32(FILTER_LR_SERVER_SIZE);
393 fsd->lsd_client_start = cpu_to_le32(FILTER_LR_CLIENT_START);
394 fsd->lsd_client_size = cpu_to_le16(FILTER_LR_CLIENT_SIZE);
395 fsd->lsd_subdir_count = cpu_to_le16(FILTER_SUBDIR_COUNT);
396 filter->fo_subdir_count = FILTER_SUBDIR_COUNT;
398 rc = fsfilt_read_record(obd, filp, fsd, sizeof(*fsd), &off);
400 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
404 if (strcmp(fsd->lsd_uuid, obd->obd_uuid.uuid) != 0) {
405 CERROR("OBD UUID %s does not match last_rcvd UUID %s\n",
406 obd->obd_uuid.uuid, fsd->lsd_uuid);
407 GOTO(err_fsd, rc = -EINVAL);
409 mount_count = le64_to_cpu(fsd->lsd_mount_count);
410 filter->fo_subdir_count = le16_to_cpu(fsd->lsd_subdir_count);
413 if (fsd->lsd_feature_incompat & ~cpu_to_le32(FILTER_INCOMPAT_SUPP)) {
414 CERROR("unsupported feature %x\n",
415 le32_to_cpu(fsd->lsd_feature_incompat) &
416 ~FILTER_INCOMPAT_SUPP);
417 GOTO(err_fsd, rc = -EINVAL);
419 if (fsd->lsd_feature_rocompat & ~cpu_to_le32(FILTER_ROCOMPAT_SUPP)) {
420 CERROR("read-only feature %x\n",
421 le32_to_cpu(fsd->lsd_feature_rocompat) &
422 ~FILTER_ROCOMPAT_SUPP);
423 /* Do something like remount filesystem read-only */
424 GOTO(err_fsd, rc = -EINVAL);
427 CDEBUG(D_INODE, "%s: server last_rcvd : "LPU64"\n",
428 obd->obd_name, le64_to_cpu(fsd->lsd_last_transno));
429 CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
430 obd->obd_name, mount_count + 1);
431 CDEBUG(D_INODE, "%s: server data size: %u\n",
432 obd->obd_name, le32_to_cpu(fsd->lsd_server_size));
433 CDEBUG(D_INODE, "%s: per-client data start: %u\n",
434 obd->obd_name, le32_to_cpu(fsd->lsd_client_start));
435 CDEBUG(D_INODE, "%s: per-client data size: %u\n",
436 obd->obd_name, le32_to_cpu(fsd->lsd_client_size));
437 CDEBUG(D_INODE, "%s: server subdir_count: %u\n",
438 obd->obd_name, le16_to_cpu(fsd->lsd_subdir_count));
439 CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
440 last_rcvd_size <= le32_to_cpu(fsd->lsd_client_start) ? 0 :
441 (last_rcvd_size - le32_to_cpu(fsd->lsd_client_start)) /
442 le16_to_cpu(fsd->lsd_client_size));
444 if (!obd->obd_replayable) {
445 CWARN("%s: recovery support OFF\n", obd->obd_name);
449 for (cl_idx = 0, off = le32_to_cpu(fsd->lsd_client_start);
450 off < last_rcvd_size; cl_idx++) {
452 struct obd_export *exp;
453 struct filter_export_data *fed;
456 OBD_ALLOC(fcd, sizeof(*fcd));
458 GOTO(err_client, rc = -ENOMEM);
461 /* Don't assume off is incremented properly by
462 * fsfilt_read_record(), in case sizeof(*fcd)
463 * isn't the same as fsd->lsd_client_size. */
464 off = le32_to_cpu(fsd->lsd_client_start) +
465 cl_idx * le16_to_cpu(fsd->lsd_client_size);
466 rc = fsfilt_read_record(obd, filp, fcd, sizeof(*fcd), &off);
468 CERROR("error reading FILT %s idx %d off %llu: rc %d\n",
469 LAST_RCVD, cl_idx, off, rc);
470 break; /* read error shouldn't cause startup to fail */
473 if (fcd->fcd_uuid[0] == '\0') {
474 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
479 last_rcvd = le64_to_cpu(fcd->fcd_last_rcvd);
481 /* These exports are cleaned up by filter_disconnect(), so they
482 * need to be set up like real exports as filter_connect() does.
484 exp = class_new_export(obd);
485 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
486 " srv lr: "LPU64"\n", fcd->fcd_uuid, cl_idx,
487 last_rcvd, le64_to_cpu(fsd->lsd_last_transno));
489 GOTO(err_client, rc = -ENOMEM);
491 memcpy(&exp->exp_client_uuid.uuid, fcd->fcd_uuid,
492 sizeof exp->exp_client_uuid.uuid);
493 fed = &exp->exp_filter_data;
495 rc = filter_client_add(obd, filter, fed, cl_idx);
496 LASSERTF(rc == 0, "rc = %d\n", rc); /* can't fail existing */
498 /* create helper if export init gets more complex */
499 spin_lock_init(&fed->fed_lock);
502 exp->exp_replay_needed = 1;
503 obd->obd_recoverable_clients++;
504 obd->obd_max_recoverable_clients++;
505 class_export_put(exp);
507 CDEBUG(D_OTHER, "client at idx %d has last_rcvd = "LPU64"\n",
510 if (last_rcvd > le64_to_cpu(fsd->lsd_last_transno))
511 fsd->lsd_last_transno = cpu_to_le64(last_rcvd);
516 OBD_FREE(fcd, sizeof(*fcd));
518 obd->obd_last_committed = le64_to_cpu(fsd->lsd_last_transno);
520 if (obd->obd_recoverable_clients) {
521 CWARN("RECOVERY: service %s, %d recoverable clients, "
522 "last_rcvd "LPU64"\n", obd->obd_name,
523 obd->obd_recoverable_clients,
524 le64_to_cpu(fsd->lsd_last_transno));
525 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
526 obd->obd_recovering = 1;
527 obd->obd_recovery_start = CURRENT_SECONDS;
528 /* Only used for lprocfs_status */
529 obd->obd_recovery_end = obd->obd_recovery_start +
530 OBD_RECOVERY_TIMEOUT / HZ;
534 filter->fo_mount_count = mount_count + 1;
535 fsd->lsd_mount_count = cpu_to_le64(filter->fo_mount_count);
537 /* save it, so mount count and last_transno is current */
538 rc = filter_update_server_data(obd, filp, filter->fo_fsd, 1);
540 GOTO(err_client, rc);
545 class_disconnect_exports(obd);
547 filter_free_server_data(filter);
551 static int filter_cleanup_groups(struct obd_device *obd)
553 struct filter_obd *filter = &obd->u.filter;
555 struct dentry *dentry;
559 if (filter->fo_dentry_O_groups != NULL) {
560 for (i = 0; i < FILTER_GROUPS; i++) {
561 dentry = filter->fo_dentry_O_groups[i];
565 OBD_FREE(filter->fo_dentry_O_groups,
566 FILTER_GROUPS * sizeof(*filter->fo_dentry_O_groups));
567 filter->fo_dentry_O_groups = NULL;
569 if (filter->fo_last_objid_files != NULL) {
570 for (i = 0; i < FILTER_GROUPS; i++) {
571 filp = filter->fo_last_objid_files[i];
575 OBD_FREE(filter->fo_last_objid_files,
576 FILTER_GROUPS * sizeof(*filter->fo_last_objid_files));
577 filter->fo_last_objid_files = NULL;
579 if (filter->fo_dentry_O_sub != NULL) {
580 for (i = 0; i < filter->fo_subdir_count; i++) {
581 dentry = filter->fo_dentry_O_sub[i];
585 OBD_FREE(filter->fo_dentry_O_sub,
586 filter->fo_subdir_count *
587 sizeof(*filter->fo_dentry_O_sub));
588 filter->fo_dentry_O_sub = NULL;
590 if (filter->fo_last_objids != NULL) {
591 OBD_FREE(filter->fo_last_objids,
592 FILTER_GROUPS * sizeof(*filter->fo_last_objids));
593 filter->fo_last_objids = NULL;
595 if (filter->fo_dentry_O != NULL) {
596 f_dput(filter->fo_dentry_O);
597 filter->fo_dentry_O = NULL;
602 /* FIXME: object groups */
603 static int filter_prep_groups(struct obd_device *obd)
605 struct filter_obd *filter = &obd->u.filter;
606 struct dentry *dentry, *O_dentry;
608 int i, rc = 0, cleanup_phase = 0;
611 O_dentry = simple_mkdir(current->fs->pwd, "O", 0700, 1);
612 CDEBUG(D_INODE, "got/created O: %p\n", O_dentry);
613 if (IS_ERR(O_dentry)) {
614 rc = PTR_ERR(O_dentry);
615 CERROR("cannot open/create O: rc = %d\n", rc);
618 filter->fo_dentry_O = O_dentry;
619 cleanup_phase = 1; /* O_dentry */
621 /* Lookup "R" to tell if we're on an old OST FS and need to convert
622 * from O/R/<dir>/<objid> to O/0/<dir>/<objid>. This can be removed
623 * some time post 1.0 when all old-style OSTs have converted along
624 * with the init_objid hack. */
625 dentry = ll_lookup_one_len("R", O_dentry, 1);
627 GOTO(cleanup, rc = PTR_ERR(dentry));
628 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) {
629 struct dentry *O0_dentry = lookup_one_len("0", O_dentry, 1);
632 CWARN("converting OST to new object layout\n");
633 if (IS_ERR(O0_dentry)) {
634 rc = PTR_ERR(O0_dentry);
635 CERROR("error looking up O/0: rc %d\n", rc);
639 if (O0_dentry->d_inode) {
640 CERROR("Both O/R and O/0 exist. Fix manually.\n");
641 GOTO(cleanup_O0, rc = -EEXIST);
644 down(&O_dentry->d_inode->i_sem);
645 rc = vfs_rename(O_dentry->d_inode, dentry,
646 O_dentry->d_inode, O0_dentry);
647 up(&O_dentry->d_inode->i_sem);
650 CERROR("error renaming O/R to O/0: rc %d\n", rc);
651 GOTO(cleanup_O0, rc);
653 filter->fo_fsd->lsd_feature_incompat |=
654 cpu_to_le32(FILTER_INCOMPAT_GROUPS);
655 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
657 GOTO(cleanup_O0, rc);
669 OBD_ALLOC(filter->fo_last_objids, FILTER_GROUPS * sizeof(__u64));
670 if (filter->fo_last_objids == NULL)
671 GOTO(cleanup, rc = -ENOMEM);
672 cleanup_phase = 2; /* groups */
674 OBD_ALLOC(filter->fo_dentry_O_groups, FILTER_GROUPS * sizeof(dentry));
675 if (filter->fo_dentry_O_groups == NULL)
676 GOTO(cleanup, rc = -ENOMEM);
677 OBD_ALLOC(filter->fo_last_objid_files, FILTER_GROUPS * sizeof(filp));
678 if (filter->fo_last_objid_files == NULL)
679 GOTO(cleanup, rc = -ENOMEM);
681 for (i = 0; i < FILTER_GROUPS; i++) {
685 sprintf(name, "%d", i);
686 dentry = simple_mkdir(O_dentry, name, 0700, 1);
687 CDEBUG(D_INODE, "got/created O/%s: %p\n", name, dentry);
688 if (IS_ERR(dentry)) {
689 rc = PTR_ERR(dentry);
690 CERROR("cannot lookup/create O/%s: rc = %d\n",
694 filter->fo_dentry_O_groups[i] = dentry;
696 sprintf(name, "O/%d/LAST_ID", i);
697 filp = filp_open(name, O_CREAT | O_RDWR, 0700);
700 CERROR("cannot create %s: rc = %d\n", name, rc);
703 filter->fo_last_objid_files[i] = filp;
705 if (filp->f_dentry->d_inode->i_size == 0) {
706 if (i == 0 && filter->fo_fsd->lsd_unused != 0) {
707 /* OST conversion, remove sometime post 1.0 */
708 filter->fo_last_objids[0] =
709 le64_to_cpu(filter->fo_fsd->lsd_unused);
710 CWARN("saving old objid "LPU64" to LAST_ID\n",
711 filter->fo_last_objids[0]);
713 filter->fo_last_objids[i] = FILTER_INIT_OBJID;
715 rc = filter_update_last_objid(obd, i, 1);
721 rc = fsfilt_read_record(obd, filp, &filter->fo_last_objids[i],
722 sizeof(__u64), &off);
724 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
728 filter->fo_last_objids[i] =
729 le64_to_cpu(filter->fo_last_objids[i]);
730 CDEBUG(D_HA, "%s: server last_objid group %d: "LPU64"\n",
731 obd->obd_name, i, filter->fo_last_objids[i]);
734 if (filter->fo_subdir_count) {
735 O_dentry = filter->fo_dentry_O_groups[0];
736 OBD_ALLOC(filter->fo_dentry_O_sub,
737 filter->fo_subdir_count * sizeof(dentry));
738 if (filter->fo_dentry_O_sub == NULL)
739 GOTO(cleanup, rc = -ENOMEM);
741 for (i = 0; i < filter->fo_subdir_count; i++) {
743 snprintf(dir, sizeof(dir), "d%u", i);
745 dentry = simple_mkdir(O_dentry, dir, 0700, 1);
746 CDEBUG(D_INODE, "got/created O/0/%s: %p\n", dir,dentry);
747 if (IS_ERR(dentry)) {
748 rc = PTR_ERR(dentry);
749 CERROR("can't lookup/create O/0/%s: rc = %d\n",
753 filter->fo_dentry_O_sub[i] = dentry;
759 filter_cleanup_groups(obd);
763 /* setup the object store with correct subdirectories */
764 static int filter_prep(struct obd_device *obd)
766 struct lvfs_run_ctxt saved;
767 struct filter_obd *filter = &obd->u.filter;
773 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
774 file = filp_open(LAST_RCVD, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
775 if (!file || IS_ERR(file)) {
777 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
781 filter->fo_rcvd_filp = file;
782 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
783 CERROR("%s is not a regular file!: mode = %o\n", LAST_RCVD,
784 file->f_dentry->d_inode->i_mode);
785 GOTO(err_filp, rc = -ENOENT);
788 /* steal operations */
789 inode = file->f_dentry->d_inode;
790 filter->fo_fop = file->f_op;
791 filter->fo_iop = inode->i_op;
792 filter->fo_aops = inode->i_mapping->a_ops;
794 rc = filter_init_server_data(obd, file);
796 CERROR("cannot read %s: rc = %d\n", LAST_RCVD, rc);
799 /* open and create health check io file*/
800 file = filp_open(HEALTH_CHECK, O_RDWR | O_CREAT, 0644);
803 CERROR("OBD filter: cannot open/create %s rc = %d\n",
807 filter->fo_health_check_filp = file;
808 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
809 CERROR("%s is not a regular file!: mode = %o\n", HEALTH_CHECK,
810 file->f_dentry->d_inode->i_mode);
811 GOTO(err_health_check, rc = -ENOENT);
813 rc = lvfs_check_io_health(obd, file);
815 GOTO(err_health_check, rc);
817 rc = filter_prep_groups(obd);
819 GOTO(err_server_data, rc);
821 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
826 //class_disconnect_exports(obd, 0);
827 filter_free_server_data(filter);
829 if (filp_close(filter->fo_health_check_filp, 0))
830 CERROR("can't close %s after error\n", HEALTH_CHECK);
831 filter->fo_health_check_filp = NULL;
833 if (filp_close(filter->fo_rcvd_filp, 0))
834 CERROR("can't close %s after error\n", LAST_RCVD);
835 filter->fo_rcvd_filp = NULL;
839 /* cleanup the filter: write last used object id to status file */
840 static void filter_post(struct obd_device *obd)
842 struct lvfs_run_ctxt saved;
843 struct filter_obd *filter = &obd->u.filter;
846 /* XXX: filter_update_lastobjid used to call fsync_dev. It might be
847 * best to start a transaction with h_sync, because we removed this
850 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
851 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
854 CERROR("error writing server data: rc = %d\n", rc);
856 for (i = 0; i < FILTER_GROUPS; i++) {
857 rc = filter_update_last_objid(obd, i, (i == FILTER_GROUPS - 1));
859 CERROR("error writing group %d lastobjid: rc = %d\n",
863 rc = filp_close(filter->fo_rcvd_filp, 0);
864 filter->fo_rcvd_filp = NULL;
866 CERROR("error closing %s: rc = %d\n", LAST_RCVD, rc);
868 rc = filp_close(filter->fo_health_check_filp, 0);
869 filter->fo_health_check_filp = NULL;
871 CERROR("error closing %s: rc = %d\n", HEALTH_CHECK, rc);
873 filter_cleanup_groups(obd);
874 filter_free_server_data(filter);
875 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
878 static void filter_set_last_id(struct filter_obd *filter, struct obdo *oa,
882 LASSERT(filter->fo_fsd != NULL);
885 LASSERT(oa->o_gr <= FILTER_GROUPS);
889 spin_lock(&filter->fo_objidlock);
890 filter->fo_last_objids[group] = id;
891 spin_unlock(&filter->fo_objidlock);
894 __u64 filter_last_id(struct filter_obd *filter, struct obdo *oa)
898 LASSERT(filter->fo_fsd != NULL);
901 LASSERT(oa->o_gr <= FILTER_GROUPS);
905 /* FIXME: object groups */
906 spin_lock(&filter->fo_objidlock);
907 id = filter->fo_last_objids[group];
908 spin_unlock(&filter->fo_objidlock);
913 static int filter_lock_dentry(struct obd_device *obd, struct dentry *dparent)
915 down(&dparent->d_inode->i_sem);
919 /* We never dget the object parent, so DON'T dput it either */
920 static void filter_parent_unlock(struct dentry *dparent)
922 up(&dparent->d_inode->i_sem);
925 /* We never dget the object parent, so DON'T dput it either */
926 struct dentry *filter_parent(struct obd_device *obd, obd_gr group, obd_id objid)
928 struct filter_obd *filter = &obd->u.filter;
929 LASSERT(group < FILTER_GROUPS); /* FIXME: object groups */
931 if (group > 0 || filter->fo_subdir_count == 0)
932 return filter->fo_dentry_O_groups[group];
934 return filter->fo_dentry_O_sub[objid & (filter->fo_subdir_count - 1)];
937 /* We never dget the object parent, so DON'T dput it either */
938 struct dentry *filter_parent_lock(struct obd_device *obd, obd_gr group,
941 unsigned long now = jiffies;
942 struct dentry *dparent = filter_parent(obd, group, objid);
948 rc = filter_lock_dentry(obd, dparent);
949 fsfilt_check_slow(now, obd_timeout, "parent lock");
950 return rc ? ERR_PTR(rc) : dparent;
953 /* How to get files, dentries, inodes from object id's.
955 * If dir_dentry is passed, the caller has already locked the parent
956 * appropriately for this operation (normally a write lock). If
957 * dir_dentry is NULL, we do a read lock while we do the lookup to
958 * avoid races with create/destroy and such changing the directory
959 * internal to the filesystem code. */
960 struct dentry *filter_fid2dentry(struct obd_device *obd,
961 struct dentry *dir_dentry,
962 obd_gr group, obd_id id)
964 struct dentry *dparent = dir_dentry;
965 struct dentry *dchild;
970 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT)) {
971 CERROR("test case OBD_FAIL_OST_ENOENT\n");
972 RETURN(ERR_PTR(-ENOENT));
976 CERROR("fatal: invalid object id 0\n");
977 RETURN(ERR_PTR(-ESTALE));
980 len = sprintf(name, LPU64, id);
981 if (dir_dentry == NULL) {
982 dparent = filter_parent_lock(obd, group, id);
983 if (IS_ERR(dparent)) {
984 CERROR("%s: error getting object "LPU64":"LPU64
985 " parent: rc %ld\n", obd->obd_name,
986 id, group, PTR_ERR(dparent));
990 CDEBUG(D_INODE, "looking up object O/%.*s/%s\n",
991 dparent->d_name.len, dparent->d_name.name, name);
992 dchild = /*ll_*/lookup_one_len(name, dparent, len);
993 if (dir_dentry == NULL)
994 filter_parent_unlock(dparent);
995 if (IS_ERR(dchild)) {
996 CERROR("%s: child lookup error %ld\n", obd->obd_name,
1001 if (dchild->d_inode != NULL && is_bad_inode(dchild->d_inode)) {
1002 CERROR("%s: got bad object "LPU64" inode %lu\n",
1003 obd->obd_name, id, dchild->d_inode->i_ino);
1005 RETURN(ERR_PTR(-ENOENT));
1008 CDEBUG(D_INODE, "got child objid %s: %p, count = %d\n",
1009 name, dchild, atomic_read(&dchild->d_count));
1011 LASSERT(atomic_read(&dchild->d_count) > 0);
1016 static int filter_prepare_destroy(struct obd_device *obd, obd_id objid)
1018 struct lustre_handle lockh;
1019 int flags = LDLM_AST_DISCARD_DATA, rc;
1020 struct ldlm_res_id res_id = { .name = { objid } };
1021 ldlm_policy_data_t policy = { .l_extent = { 0, OBD_OBJECT_EOF } };
1024 /* Tell the clients that the object is gone now and that they should
1025 * throw away any cached pages. */
1026 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, res_id,
1027 LDLM_EXTENT, &policy, LCK_PW,
1028 &flags, ldlm_blocking_ast, ldlm_completion_ast,
1029 NULL, NULL, NULL, 0, NULL, &lockh);
1031 /* We only care about the side-effects, just drop the lock. */
1033 ldlm_lock_decref(&lockh, LCK_PW);
1038 /* Caller must hold LCK_PW on parent and push us into kernel context.
1039 * Caller is also required to ensure that dchild->d_inode exists. */
1040 static int filter_destroy_internal(struct obd_device *obd, obd_id objid,
1041 struct dentry *dparent,
1042 struct dentry *dchild)
1044 struct inode *inode = dchild->d_inode;
1048 if (inode->i_nlink != 1 || atomic_read(&inode->i_count) != 1) {
1049 CERROR("destroying objid %.*s ino %lu nlink %lu count %d\n",
1050 dchild->d_name.len, dchild->d_name.name, inode->i_ino,
1051 (unsigned long)inode->i_nlink,
1052 atomic_read(&inode->i_count));
1055 rc = vfs_unlink(dparent->d_inode, dchild);
1057 CERROR("error unlinking objid %.*s: rc %d\n",
1058 dchild->d_name.len, dchild->d_name.name, rc);
1062 static int filter_intent_policy(struct ldlm_namespace *ns,
1063 struct ldlm_lock **lockp, void *req_cookie,
1064 ldlm_mode_t mode, int flags, void *data)
1066 struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
1067 struct ptlrpc_request *req = req_cookie;
1068 struct ldlm_lock *lock = *lockp, *l = NULL;
1069 struct ldlm_resource *res = lock->l_resource;
1070 ldlm_processing_policy policy;
1071 struct ost_lvb *res_lvb, *reply_lvb;
1072 struct ldlm_reply *rep;
1073 struct list_head *tmp;
1075 int tmpflags = 0, rc, repsize[2] = {sizeof(*rep), sizeof(*reply_lvb)};
1076 int only_liblustre = 0;
1079 policy = ldlm_get_processing_policy(res);
1080 LASSERT(policy != NULL);
1081 LASSERT(req != NULL);
1083 rc = lustre_pack_reply(req, 2, repsize, NULL);
1085 RETURN(req->rq_status = rc);
1087 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
1088 LASSERT(rep != NULL);
1090 reply_lvb = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*reply_lvb));
1091 LASSERT(reply_lvb != NULL);
1093 //fixup_handle_for_resent_req(req, lock, &lockh);
1095 /* If we grant any lock at all, it will be a whole-file read lock.
1096 * Call the extent policy function to see if our request can be
1097 * granted, or is blocked. */
1098 lock->l_policy_data.l_extent.start = 0;
1099 lock->l_policy_data.l_extent.end = OBD_OBJECT_EOF;
1100 lock->l_req_mode = LCK_PR;
1102 LASSERT(ns == res->lr_namespace);
1103 l_lock(&ns->ns_lock);
1105 res->lr_tmp = &rpc_list;
1106 rc = policy(lock, &tmpflags, 0, &err);
1109 /* FIXME: we should change the policy function slightly, to not make
1110 * this list at all, since we just turn around and free it */
1111 while (!list_empty(&rpc_list)) {
1112 struct ldlm_ast_work *w =
1113 list_entry(rpc_list.next, struct ldlm_ast_work, w_list);
1114 list_del(&w->w_list);
1115 LDLM_LOCK_PUT(w->w_lock);
1116 OBD_FREE(w, sizeof(*w));
1119 /* The lock met with no resistance; we're finished. */
1120 if (rc == LDLM_ITER_CONTINUE) {
1121 l_unlock(&ns->ns_lock);
1123 * do not grant locks to the liblustre clients: they cannot
1124 * handle ASTs robustly.
1126 if (lock->l_export->exp_libclient) {
1127 ldlm_resource_unlink_lock(lock);
1128 RETURN(ELDLM_LOCK_ABORTED);
1130 RETURN(ELDLM_LOCK_REPLACED);
1133 /* Do not grant any lock, but instead send GL callbacks. The extent
1134 * policy nicely created a list of all PW locks for us. We will choose
1135 * the highest of those which are larger than the size in the LVB, if
1136 * any, and perform a glimpse callback. */
1137 down(&res->lr_lvb_sem);
1138 res_lvb = res->lr_lvb_data;
1139 LASSERT(res_lvb != NULL);
1140 *reply_lvb = *res_lvb;
1141 up(&res->lr_lvb_sem);
1143 list_for_each(tmp, &res->lr_granted) {
1144 struct ldlm_lock *tmplock =
1145 list_entry(tmp, struct ldlm_lock, l_res_link);
1147 if (tmplock->l_granted_mode == LCK_PR)
1150 * ->ns_lock guarantees that no new locks are granted, and,
1151 * therefore, that res->lr_lvb_data cannot increase beyond the
1152 * end of already granted lock. As a result, it is safe to
1153 * check against "stale" reply_lvb->lvb_size value without
1156 if (tmplock->l_policy_data.l_extent.end <= reply_lvb->lvb_size)
1159 /* Don't send glimpse ASTs to liblustre clients. They aren't
1160 * listening for them, and they do entirely synchronous I/O
1162 if (tmplock->l_export == NULL ||
1163 tmplock->l_export->exp_libclient == 1) {
1169 l = LDLM_LOCK_GET(tmplock);
1173 if (l->l_policy_data.l_extent.start >
1174 tmplock->l_policy_data.l_extent.start)
1178 l = LDLM_LOCK_GET(tmplock);
1180 l_unlock(&ns->ns_lock);
1182 /* There were no PW locks beyond the size in the LVB; finished. */
1184 if (only_liblustre) {
1185 /* If we discovered a liblustre client with a PW lock,
1186 * however, the LVB may be out of date! The LVB is
1187 * updated only on glimpse (which we don't do for
1188 * liblustre clients) and cancel (which the client
1189 * obviously has not yet done). So if it has written
1190 * data but kept the lock, the LVB is stale and needs
1191 * to be updated from disk.
1193 * Of course, this will all disappear when we switch to
1194 * taking liblustre locks on the OST. */
1195 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_update)
1196 ns->ns_lvbo->lvbo_update(res, NULL, 0, 1);
1198 RETURN(ELDLM_LOCK_ABORTED);
1201 * This check is for lock taken in filter_prepare_destroy() that does
1202 * not have l_glimpse_ast set. So the logic is: if there is a lock
1203 * with no l_glimpse_ast set, this object is being destroyed already.
1205 * Hence, if you are grabbing DLM locks on the server, always set
1206 * non-NULL glimpse_ast (e.g., ldlm_request.c:ldlm_glimpse_ast()).
1208 if (l->l_glimpse_ast == NULL) {
1209 /* We are racing with unlink(); just return -ENOENT */
1210 rep->lock_policy_res1 = -ENOENT;
1214 LASSERTF(l->l_glimpse_ast != NULL, "l == %p", l);
1215 rc = l->l_glimpse_ast(l, NULL); /* this will update the LVB */
1216 /* Update the LVB from disk if the AST failed (this is a legal race) */
1218 * XXX nikita: situation when ldlm_server_glimpse_ast() failed before
1219 * sending ast is not handled. This can result in lost client writes.
1221 if (rc != 0 && ns->ns_lvbo && ns->ns_lvbo->lvbo_update)
1222 ns->ns_lvbo->lvbo_update(res, NULL, 0, 1);
1224 down(&res->lr_lvb_sem);
1225 *reply_lvb = *res_lvb;
1226 up(&res->lr_lvb_sem);
1231 RETURN(ELDLM_LOCK_ABORTED);
1235 * per-obd_device iobuf pool.
1237 * To avoid memory deadlocks in low-memory setups, amount of dynamic
1238 * allocations in write-path has to be minimized (see bug 5137).
1240 * Pages, niobuf_local's and niobuf_remote's are pre-allocated and attached to
1241 * OST threads (see ost_thread_{init,done}()).
1243 * "iobuf's" used by filter cannot be attached to OST thread, however, because
1244 * at the OST layer there are only (potentially) multiple obd_device of type
1245 * unknown at the time of OST thread creation.
1247 * Instead array of iobuf's is attached to struct filter_obd (->fo_iobuf_pool
1248 * field). This array has size OST_NUM_THREADS, so that each OST thread uses
1249 * it's very own iobuf.
1253 * filter_kiobuf_pool_init()
1255 * filter_kiobuf_pool_done()
1257 * filter_iobuf_get()
1259 * operate on this array. They are "generic" in a sense that they don't depend
1260 * on actual type of iobuf's (the latter depending on Linux kernel version).
1264 * destroy pool created by filter_iobuf_pool_init
1266 static void filter_iobuf_pool_done(struct filter_obd *filter)
1273 pool = filter->fo_iobuf_pool;
1275 for (i = 0; i < OST_NUM_THREADS; ++ i) {
1276 if (pool[i] != NULL)
1277 filter_free_iobuf(pool[i]);
1279 OBD_FREE(pool, OST_NUM_THREADS * sizeof pool[0]);
1280 filter->fo_iobuf_pool = NULL;
1286 * pre-allocate pool of iobuf's to be used by filter_{prep,commit}rw_write().
1288 static int filter_iobuf_pool_init(struct filter_obd *filter, int count)
1296 LASSERT(count <= OST_NUM_THREADS);
1298 OBD_ALLOC_GFP(pool, OST_NUM_THREADS * sizeof pool[0], GFP_KERNEL);
1302 filter->fo_iobuf_pool = pool;
1303 filter->fo_iobuf_count = count;
1304 for (i = 0; i < count; ++ i) {
1306 * allocate kiobuf to be used by i-th OST thread.
1308 result = filter_alloc_iobuf(filter, OBD_BRW_WRITE,
1309 PTLRPC_MAX_BRW_PAGES,
1312 filter_iobuf_pool_done(filter);
1320 * return iobuf preallocated by filter_iobuf_pool_init() for @thread.
1322 void *filter_iobuf_get(struct ptlrpc_thread *thread, struct filter_obd *filter)
1326 LASSERT(thread->t_id < filter->fo_iobuf_count);
1327 kio = filter->fo_iobuf_pool[thread->t_id];
1328 LASSERT(kio != NULL);
1332 /* mount the file system (secretly). lustre_cfg parameters are:
1335 * 3 = flags: failover=f, failout=n
1338 int filter_common_setup(struct obd_device *obd, obd_count len, void *buf,
1341 struct lustre_cfg* lcfg = buf;
1342 struct filter_obd *filter = &obd->u.filter;
1343 struct vfsmount *mnt;
1344 struct lustre_mount_info *lmi;
1350 if (lcfg->lcfg_bufcount < 3 ||
1351 LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
1352 LUSTRE_CFG_BUFLEN(lcfg, 2) < 1)
1355 lmi = server_get_mount(obd->obd_name);
1357 /* We already mounted in lustre_fill_super.
1358 lcfg bufs 1, 2, 4 (device, fstype, mount opts) are ignored.*/
1359 struct lustre_sb_info *lsi = s2lsi(lmi->lmi_sb);
1361 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
1363 /* old path - used by lctl */
1364 CERROR("Using old MDS mount method\n");
1365 mnt = do_kern_mount(lustre_cfg_string(lcfg, 2),
1366 MS_NOATIME|MS_NODIRATIME,
1367 lustre_cfg_string(lcfg, 1), option);
1370 LCONSOLE_ERROR("Can't mount disk %s (%d)\n",
1371 lustre_cfg_string(lcfg, 1), rc);
1375 obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2));
1377 if (IS_ERR(obd->obd_fsops))
1378 GOTO(err_mntput, rc = PTR_ERR(obd->obd_fsops));
1380 rc = filter_iobuf_pool_init(filter, OST_NUM_THREADS);
1384 LASSERT(!lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb)));
1386 /* failover is the default */
1387 obd->obd_replayable = 1;
1388 obd_sync_filter = 1;
1390 if (lcfg->lcfg_bufcount > 3 && LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
1391 str = lustre_cfg_string(lcfg, 3);
1392 if (strchr(str, 'n')) {
1393 CWARN("%s: recovery disabled\n", obd->obd_name);
1394 obd->obd_replayable = 0;
1395 obd_sync_filter = 0;
1399 filter->fo_vfsmnt = mnt;
1400 filter->fo_sb = mnt->mnt_sb;
1401 filter->fo_fstype = mnt->mnt_sb->s_type->name;
1402 CDEBUG(D_SUPER, "%s: mnt = %p\n", filter->fo_fstype, mnt);
1404 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1405 obd->obd_lvfs_ctxt.pwdmnt = mnt;
1406 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
1407 obd->obd_lvfs_ctxt.fs = get_ds();
1408 obd->obd_lvfs_ctxt.cb_ops = filter_lvfs_ops;
1410 rc = filter_prep(obd);
1414 filter->fo_destroy_in_progress = 0;
1415 sema_init(&filter->fo_create_lock, 1);
1417 spin_lock_init(&filter->fo_translock);
1418 spin_lock_init(&filter->fo_objidlock);
1419 spin_lock_init(&filter->fo_stats_lock);
1420 INIT_LIST_HEAD(&filter->fo_export_list);
1421 sema_init(&filter->fo_alloc_lock, 1);
1422 spin_lock_init(&filter->fo_r_pages.oh_lock);
1423 spin_lock_init(&filter->fo_w_pages.oh_lock);
1424 spin_lock_init(&filter->fo_read_rpc_hist.oh_lock);
1425 spin_lock_init(&filter->fo_write_rpc_hist.oh_lock);
1426 spin_lock_init(&filter->fo_r_io_time.oh_lock);
1427 spin_lock_init(&filter->fo_w_io_time.oh_lock);
1428 spin_lock_init(&filter->fo_r_discont_pages.oh_lock);
1429 spin_lock_init(&filter->fo_w_discont_pages.oh_lock);
1430 spin_lock_init(&filter->fo_r_discont_blocks.oh_lock);
1431 spin_lock_init(&filter->fo_w_discont_blocks.oh_lock);
1432 spin_lock_init(&filter->fo_r_disk_iosize.oh_lock);
1433 spin_lock_init(&filter->fo_w_disk_iosize.oh_lock);
1434 filter->fo_readcache_max_filesize = FILTER_MAX_CACHE_SIZE;
1436 sprintf(ns_name, "filter-%s", obd->obd_uuid.uuid);
1437 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
1438 if (obd->obd_namespace == NULL)
1439 GOTO(err_post, rc = -ENOMEM);
1440 obd->obd_namespace->ns_lvbp = obd;
1441 obd->obd_namespace->ns_lvbo = &filter_lvbo;
1442 ldlm_register_intent(obd->obd_namespace, filter_intent_policy);
1444 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1445 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
1447 rc = llog_cat_initialize(obd, 1);
1449 CERROR("failed to setup llogging subsystems\n");
1453 rc = filter_quota_setup(filter);
1458 if (obd->obd_recovering) {
1459 LCONSOLE_WARN("OST %s now serving %s, but will be in recovery "
1460 "until %d %s reconnect, or if no clients "
1461 "reconnect for %d:%.02d; during that time new "
1462 "clients will not be allowed to connect. "
1463 "Recovery progress can be monitored by watching "
1464 "/proc/fs/lustre/obdfilter/%s/recovery_status.\n",
1466 lustre_cfg_string(lcfg, 1),
1467 obd->obd_recoverable_clients,
1468 (obd->obd_recoverable_clients == 1)
1469 ? "client" : "clients",
1470 (int)(OBD_RECOVERY_TIMEOUT / HZ) / 60,
1471 (int)(OBD_RECOVERY_TIMEOUT / HZ) % 60,
1474 LCONSOLE_INFO("OST %s now serving %s with recovery %s.\n",
1476 lustre_cfg_string(lcfg, 1),
1477 obd->obd_replayable ? "enabled" : "disabled");
1485 fsfilt_put_ops(obd->obd_fsops);
1486 filter_iobuf_pool_done(filter);
1489 server_put_mount(obd->obd_name, mnt);
1500 static int filter_setup(struct obd_device *obd, obd_count len, void *buf)
1502 struct lprocfs_static_vars lvars;
1503 struct lustre_cfg* lcfg = buf;
1507 if (!LUSTRE_CFG_BUFLEN(lcfg, 1) || !LUSTRE_CFG_BUFLEN(lcfg, 2))
1510 /* 2.6.9 selinux wants a full option page for do_kern_mount (bug6471) */
1511 page = get_zeroed_page(GFP_KERNEL);
1515 memcpy((void *)page, lustre_cfg_buf(lcfg, 4),
1516 LUSTRE_CFG_BUFLEN(lcfg, 4));
1517 rc = filter_common_setup(obd, len, buf, (void *)page);
1520 lprocfs_init_vars(filter, &lvars);
1521 if (rc == 0 && lprocfs_obd_setup(obd, lvars.obd_vars) == 0 &&
1522 lprocfs_alloc_obd_stats(obd, LPROC_FILTER_LAST) == 0) {
1523 /* Init obdfilter private stats here */
1524 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_READ_BYTES,
1525 LPROCFS_CNTR_AVGMINMAX,
1526 "read_bytes", "bytes");
1527 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_WRITE_BYTES,
1528 LPROCFS_CNTR_AVGMINMAX,
1529 "write_bytes", "bytes");
1531 lproc_filter_attach_seqstat(obd);
1534 ping_evictor_start();
1539 static struct llog_operations filter_mds_ost_repl_logops /* initialized below*/;
1540 static struct llog_operations filter_size_orig_logops = {
1541 lop_setup: llog_obd_origin_setup,
1542 lop_cleanup: llog_obd_origin_cleanup,
1543 lop_add: llog_obd_origin_add
1546 static int filter_llog_init(struct obd_device *obd, struct obd_device *tgt,
1547 int count, struct llog_catid *catid)
1549 struct llog_ctxt *ctxt;
1553 filter_mds_ost_repl_logops = llog_client_ops;
1554 filter_mds_ost_repl_logops.lop_cancel = llog_obd_repl_cancel;
1555 filter_mds_ost_repl_logops.lop_connect = llog_repl_connect;
1556 filter_mds_ost_repl_logops.lop_sync = llog_obd_repl_sync;
1558 rc = llog_setup(obd, LLOG_MDS_OST_REPL_CTXT, tgt, 0, NULL,
1559 &filter_mds_ost_repl_logops);
1563 /* FIXME - assign unlink_cb for filter's recovery */
1564 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
1565 ctxt->llog_proc_cb = filter_recov_log_mds_ost_cb;
1567 rc = llog_setup(obd, LLOG_SIZE_ORIG_CTXT, tgt, 0, NULL,
1568 &filter_size_orig_logops);
1572 static int filter_llog_finish(struct obd_device *obd, int count)
1574 struct llog_ctxt *ctxt;
1575 int rc = 0, rc2 = 0;
1578 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
1580 rc = llog_cleanup(ctxt);
1582 ctxt = llog_get_context(obd, LLOG_SIZE_ORIG_CTXT);
1584 rc2 = llog_cleanup(ctxt);
1591 static int filter_precleanup(struct obd_device *obd, int stage)
1597 case OBD_CLEANUP_EXPORTS:
1598 target_cleanup_recovery(obd);
1600 case OBD_CLEANUP_SELF_EXP:
1601 rc = filter_llog_finish(obd, 0);
1606 static int filter_cleanup(struct obd_device *obd)
1608 struct filter_obd *filter = &obd->u.filter;
1609 lvfs_sbdev_type save_dev;
1610 int must_relock = 0, must_put = 0;
1614 CERROR("%s: shutting down for failover; client state will"
1615 " be preserved.\n", obd->obd_name);
1617 if (!list_empty(&obd->obd_exports)) {
1618 CERROR("%s: still has clients!\n", obd->obd_name);
1619 class_disconnect_exports(obd);
1620 if (!list_empty(&obd->obd_exports)) {
1621 CERROR("still has exports after forced cleanup?\n");
1626 ping_evictor_stop();
1628 filter_quota_cleanup(filter);
1630 ldlm_namespace_free(obd->obd_namespace, obd->obd_force);
1632 if (filter->fo_sb == NULL)
1634 save_dev = lvfs_sbdev(filter->fo_sb);
1636 lprocfs_free_obd_stats(obd);
1637 lprocfs_obd_cleanup(obd);
1641 shrink_dcache_parent(filter->fo_sb->s_root);
1643 LL_DQUOT_OFF(filter->fo_sb);
1645 if (atomic_read(&filter->fo_vfsmnt->mnt_count) > 1)
1646 CERROR("%s: mount point %p busy, mnt_count: %d\n",
1647 obd->obd_name, filter->fo_vfsmnt,
1648 atomic_read(&filter->fo_vfsmnt->mnt_count));
1650 must_put = server_put_mount(obd->obd_name, filter->fo_vfsmnt);
1651 /* must_put is for old method (l_p_m returns non-0 on err) */
1653 /* We can only unlock kernel if we are in the context of sys_ioctl,
1654 otherwise we never called lock_kernel */
1655 if (kernel_locked()) {
1661 /* In case we didn't mount with lustre_get_mount -- old method*/
1662 mntput(filter->fo_vfsmnt);
1664 filter->fo_sb = NULL;
1666 lvfs_clear_rdonly(save_dev);
1671 fsfilt_put_ops(obd->obd_fsops);
1673 filter_iobuf_pool_done(filter);
1675 LCONSOLE_INFO("OST %s has stopped.\n", obd->obd_name);
1680 static int filter_connect_internal(struct obd_export *exp,
1681 struct obd_connect_data *data)
1684 CDEBUG(D_RPCTRACE, "%s: cli %s/%p ocd_connect_flags: "LPX64
1685 " ocd_version: %x ocd_grant: %d\n",
1686 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
1687 data->ocd_connect_flags, data->ocd_version,
1690 data->ocd_connect_flags &= OST_CONNECT_SUPPORTED;
1691 exp->exp_connect_flags = data->ocd_connect_flags;
1692 data->ocd_version = LUSTRE_VERSION_CODE;
1694 if (exp->exp_connect_flags & OBD_CONNECT_GRANT) {
1695 obd_size left, want;
1697 spin_lock(&exp->exp_obd->obd_osfs_lock);
1698 left = filter_grant_space_left(exp);
1699 want = data->ocd_grant;
1700 data->ocd_grant = filter_grant(exp, 0, want, left);
1701 spin_unlock(&exp->exp_obd->obd_osfs_lock);
1703 CDEBUG(D_CACHE, "%s: cli %s/%p ocd_grant: %d want: "
1704 "%lld left: %lld\n", exp->exp_obd->obd_name,
1705 exp->exp_client_uuid.uuid, exp,
1706 data->ocd_grant, want, left);
1713 static int filter_reconnect(struct obd_export *exp, struct obd_device *obd,
1714 struct obd_uuid *cluuid,
1715 struct obd_connect_data *data)
1720 if (exp == NULL || obd == NULL || cluuid == NULL)
1723 rc = filter_connect_internal(exp, data);
1728 /* nearly identical to mds_connect */
1729 static int filter_connect(struct lustre_handle *conn, struct obd_device *obd,
1730 struct obd_uuid *cluuid,struct obd_connect_data *data)
1732 struct obd_export *exp;
1733 struct filter_export_data *fed;
1734 struct filter_client_data *fcd = NULL;
1735 struct filter_obd *filter = &obd->u.filter;
1739 if (conn == NULL || obd == NULL || cluuid == NULL)
1742 rc = class_connect(conn, obd, cluuid);
1745 exp = class_conn2export(conn);
1746 LASSERT(exp != NULL);
1748 fed = &exp->exp_filter_data;
1749 spin_lock_init(&fed->fed_lock);
1751 if (!obd->obd_replayable)
1752 GOTO(cleanup, rc = 0);
1754 OBD_ALLOC(fcd, sizeof(*fcd));
1756 CERROR("filter: out of memory for client data\n");
1757 GOTO(cleanup, rc = -ENOMEM);
1760 memcpy(fcd->fcd_uuid, cluuid, sizeof(fcd->fcd_uuid));
1763 rc = filter_client_add(obd, filter, fed, -1);
1765 filter_connect_internal(exp, data);
1772 OBD_FREE(fcd, sizeof(*fcd));
1773 fed->fed_fcd = NULL;
1775 class_disconnect(exp);
1777 class_export_put(exp);
1783 /* Do extra sanity checks for grant accounting. We do this at connect,
1784 * disconnect, and statfs RPC time, so it shouldn't be too bad. We can
1785 * always get rid of it or turn it off when we know accounting is good. */
1786 static void filter_grant_sanity_check(struct obd_device *obd, const char *func)
1788 struct filter_export_data *fed;
1789 struct obd_export *exp;
1790 obd_size maxsize = obd->obd_osfs.os_blocks * obd->obd_osfs.os_bsize;
1791 obd_size tot_dirty = 0, tot_pending = 0, tot_granted = 0;
1792 obd_size fo_tot_dirty, fo_tot_pending, fo_tot_granted;
1794 if (list_empty(&obd->obd_exports))
1797 spin_lock(&obd->obd_osfs_lock);
1798 spin_lock(&obd->obd_dev_lock);
1799 list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
1801 fed = &exp->exp_filter_data;
1802 if (fed->fed_grant < 0 || fed->fed_pending < 0 ||
1805 if (maxsize > 0) { /* we may not have done a statfs yet */
1806 LASSERTF(fed->fed_grant + fed->fed_pending <= maxsize,
1807 "%s: cli %s/%p %ld+%ld > "LPU64"\n", func,
1808 exp->exp_client_uuid.uuid, exp,
1809 fed->fed_grant, fed->fed_pending, maxsize);
1810 LASSERTF(fed->fed_dirty <= maxsize,
1811 "%s: cli %s/%p %ld > "LPU64"\n", func,
1812 exp->exp_client_uuid.uuid, exp,
1813 fed->fed_dirty, maxsize);
1816 CERROR("%s: cli %s/%p dirty %ld pend %ld grant %ld\n",
1817 obd->obd_name, exp->exp_client_uuid.uuid, exp,
1818 fed->fed_dirty, fed->fed_pending,fed->fed_grant);
1820 CDEBUG(D_CACHE, "%s: cli %s/%p dirty %ld pend %ld grant %ld\n",
1821 obd->obd_name, exp->exp_client_uuid.uuid, exp,
1822 fed->fed_dirty, fed->fed_pending,fed->fed_grant);
1823 tot_granted += fed->fed_grant + fed->fed_pending;
1824 tot_pending += fed->fed_pending;
1825 tot_dirty += fed->fed_dirty;
1827 fo_tot_granted = obd->u.filter.fo_tot_granted;
1828 fo_tot_pending = obd->u.filter.fo_tot_pending;
1829 fo_tot_dirty = obd->u.filter.fo_tot_dirty;
1830 spin_unlock(&obd->obd_dev_lock);
1831 spin_unlock(&obd->obd_osfs_lock);
1833 /* Do these assertions outside the spinlocks so we don't kill system */
1834 if (tot_granted != fo_tot_granted)
1835 CERROR("%s: tot_granted "LPU64" != fo_tot_granted "LPU64"\n",
1836 func, tot_granted, fo_tot_granted);
1837 if (tot_pending != fo_tot_pending)
1838 CERROR("%s: tot_pending "LPU64" != fo_tot_pending "LPU64"\n",
1839 func, tot_pending, fo_tot_pending);
1840 if (tot_dirty != fo_tot_dirty)
1841 CERROR("%s: tot_dirty "LPU64" != fo_tot_dirty "LPU64"\n",
1842 func, tot_dirty, fo_tot_dirty);
1843 if (tot_pending > tot_granted)
1844 CERROR("%s: tot_pending "LPU64" > tot_granted "LPU64"\n",
1845 func, tot_pending, tot_granted);
1846 if (tot_granted > maxsize)
1847 CERROR("%s: tot_granted "LPU64" > maxsize "LPU64"\n",
1848 func, tot_granted, maxsize);
1849 if (tot_dirty > maxsize)
1850 CERROR("%s: tot_dirty "LPU64" > maxsize "LPU64"\n",
1851 func, tot_dirty, maxsize);
1854 /* Remove this client from the grant accounting totals. We also remove
1855 * the export from the obd device under the osfs and dev locks to ensure
1856 * that the filter_grant_sanity_check() calculations are always valid.
1857 * The client should do something similar when it invalidates its import. */
1858 static void filter_grant_discard(struct obd_export *exp)
1860 struct obd_device *obd = exp->exp_obd;
1861 struct filter_obd *filter = &obd->u.filter;
1862 struct filter_export_data *fed = &exp->exp_filter_data;
1864 spin_lock(&obd->obd_osfs_lock);
1865 spin_lock(&obd->obd_dev_lock);
1866 list_del_init(&exp->exp_obd_chain);
1867 spin_unlock(&obd->obd_dev_lock);
1869 LASSERTF(filter->fo_tot_granted >= fed->fed_grant,
1870 "%s: tot_granted "LPU64" cli %s/%p fed_grant %ld\n",
1871 obd->obd_name, filter->fo_tot_granted,
1872 exp->exp_client_uuid.uuid, exp, fed->fed_grant);
1873 filter->fo_tot_granted -= fed->fed_grant;
1874 LASSERTF(filter->fo_tot_pending >= fed->fed_pending,
1875 "%s: tot_pending "LPU64" cli %s/%p fed_pending %ld\n",
1876 obd->obd_name, filter->fo_tot_pending,
1877 exp->exp_client_uuid.uuid, exp, fed->fed_pending);
1878 LASSERTF(filter->fo_tot_dirty >= fed->fed_dirty,
1879 "%s: tot_dirty "LPU64" cli %s/%p fed_dirty %ld\n",
1880 obd->obd_name, filter->fo_tot_dirty,
1881 exp->exp_client_uuid.uuid, exp, fed->fed_dirty);
1882 filter->fo_tot_dirty -= fed->fed_dirty;
1886 spin_unlock(&obd->obd_osfs_lock);
1889 static int filter_destroy_export(struct obd_export *exp)
1893 if (exp->exp_filter_data.fed_pending)
1894 CERROR("%s: cli %s/%p has %lu pending on destroyed export\n",
1895 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
1896 exp, exp->exp_filter_data.fed_pending);
1898 target_destroy_export(exp);
1900 if (exp->exp_obd->obd_replayable)
1901 filter_client_free(exp);
1903 filter_grant_discard(exp);
1905 if (!(exp->exp_flags & OBD_OPT_FORCE))
1906 filter_grant_sanity_check(exp->exp_obd, __FUNCTION__);
1911 /* also incredibly similar to mds_disconnect */
1912 static int filter_disconnect(struct obd_export *exp)
1914 struct obd_device *obd = exp->exp_obd;
1915 struct llog_ctxt *ctxt;
1920 class_export_get(exp);
1922 if (!(exp->exp_flags & OBD_OPT_FORCE))
1923 filter_grant_sanity_check(obd, __FUNCTION__);
1924 filter_grant_discard(exp);
1926 /* Disconnect early so that clients can't keep using export */
1927 rc = class_disconnect(exp);
1928 ldlm_cancel_locks_for_export(exp);
1930 fsfilt_sync(obd, obd->u.filter.fo_sb);
1932 /* flush any remaining cancel messages out to the target */
1933 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
1934 err = llog_sync(ctxt, exp);
1936 CERROR("error flushing logs to MDS: rc %d\n", err);
1938 class_export_put(exp);
1942 struct dentry *__filter_oa2dentry(struct obd_device *obd,
1943 struct obdo *oa, const char *what, int quiet)
1945 struct dentry *dchild = NULL;
1948 if (oa->o_valid & OBD_MD_FLGROUP)
1951 dchild = filter_fid2dentry(obd, NULL, group, oa->o_id);
1953 if (IS_ERR(dchild)) {
1954 CERROR("%s error looking up object: "LPU64"\n", what, oa->o_id);
1958 if (dchild->d_inode == NULL) {
1960 CERROR("%s: %s on non-existent object: "LPU64"\n",
1961 obd->obd_name, what, oa->o_id);
1963 RETURN(ERR_PTR(-ENOENT));
1969 static int filter_getattr(struct obd_export *exp, struct obdo *oa,
1970 struct lov_stripe_md *md)
1972 struct dentry *dentry = NULL;
1973 struct obd_device *obd;
1977 obd = class_exp2obd(exp);
1979 CDEBUG(D_IOCTL, "invalid client export %p\n", exp);
1983 dentry = filter_oa2dentry(obd, oa);
1985 RETURN(PTR_ERR(dentry));
1987 /* Limit the valid bits in the return data to what we actually use */
1988 oa->o_valid = OBD_MD_FLID;
1989 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
1995 /* this is called from filter_truncate() until we have filter_punch() */
1996 int filter_setattr(struct obd_export *exp, struct obdo *oa,
1997 struct lov_stripe_md *md, struct obd_trans_info *oti)
1999 struct obd_device *obd;
2000 struct lvfs_run_ctxt saved;
2001 struct filter_obd *filter;
2002 struct dentry *dentry;
2006 struct ldlm_res_id res_id = { .name = { oa->o_id } };
2007 struct ldlm_resource *res;
2009 struct llog_cookie *fcc = NULL;
2013 dentry = __filter_oa2dentry(exp->exp_obd, oa, __FUNCTION__, 1);
2015 RETURN(PTR_ERR(dentry));
2018 filter = &obd->u.filter;
2020 iattr_from_obdo(&iattr, oa, oa->o_valid);
2022 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2025 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2026 OBD_ALLOC(fcc, sizeof(*fcc));
2028 memcpy(fcc, obdo_logcookie(oa), sizeof(*fcc));
2031 if (iattr.ia_valid & ATTR_SIZE)
2032 down(&dentry->d_inode->i_sem);
2034 if (iattr.ia_valid & (ATTR_UID | ATTR_GID)) {
2035 orig_uid = dentry->d_inode->i_uid;
2036 orig_gid = dentry->d_inode->i_gid;
2037 handle = fsfilt_start_log(exp->exp_obd, dentry->d_inode,
2038 FSFILT_OP_SETATTR, oti, 1);
2040 handle = fsfilt_start(exp->exp_obd, dentry->d_inode,
2041 FSFILT_OP_SETATTR, oti);
2045 GOTO(out_unlock, rc = PTR_ERR(handle));
2047 if (iattr.ia_valid & ATTR_ATTR_FLAG) {
2048 rc = fsfilt_iocontrol(exp->exp_obd, dentry->d_inode, NULL,
2050 (long)&iattr.ia_attr_flags);
2052 rc = fsfilt_setattr(exp->exp_obd, dentry, handle, &iattr, 1);
2054 /* set cancel cookie callback function */
2055 fsfilt_add_journal_cb(obd, 0, oti ?
2056 oti->oti_handle : handle,
2057 filter_cancel_cookies_cb,
2061 rc = filter_finish_transno(exp, oti, rc);
2062 rc2 = fsfilt_commit(exp->exp_obd, dentry->d_inode, handle, 0);
2064 CERROR("error on commit, err = %d\n", rc2);
2069 res = ldlm_resource_get(exp->exp_obd->obd_namespace, NULL,
2070 res_id, LDLM_EXTENT, 0);
2072 if (res->lr_namespace->ns_lvbo &&
2073 res->lr_namespace->ns_lvbo->lvbo_update)
2074 rc = res->lr_namespace->ns_lvbo->lvbo_update(res, NULL,
2076 ldlm_resource_putref(res);
2077 } else if (iattr.ia_valid & ATTR_SIZE) {
2078 CERROR("!!! resource_get failed for object "LPU64" -- "
2079 "filter_setattr with no lock?\n", oa->o_id);
2082 oa->o_valid = OBD_MD_FLID;
2083 /* Quota release need uid/gid info */
2084 obdo_from_inode(oa, dentry->d_inode,
2085 FILTER_VALID_FLAGS | OBD_MD_FLUID | OBD_MD_FLGID);
2088 if (iattr.ia_valid & ATTR_SIZE)
2089 up(&dentry->d_inode->i_sem);
2091 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2095 /* trigger quota release */
2096 if (rc == 0 && iattr.ia_valid & (ATTR_SIZE | ATTR_UID | ATTR_GID)) {
2097 rc2 = qctxt_adjust_qunit(obd, &filter->fo_quota_ctxt,
2098 oa->o_uid, oa->o_gid, 1);
2100 CERROR("error filter adjust qunit! (rc:%d)\n", rc2);
2101 /* after owner changed, release quota for the original owner */
2102 rc2 = qctxt_adjust_qunit(obd, &filter->fo_quota_ctxt,
2103 orig_uid, orig_gid, 1);
2105 CERROR("error filter adjust qunit! (rc:%d)\n", rc2);
2110 /* XXX identical to osc_unpackmd */
2111 static int filter_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2112 struct lov_mds_md *lmm, int lmm_bytes)
2118 if (lmm_bytes < sizeof (*lmm)) {
2119 CERROR("lov_mds_md too small: %d, need %d\n",
2120 lmm_bytes, (int)sizeof(*lmm));
2123 /* XXX LOV_MAGIC etc check? */
2125 if (lmm->lmm_object_id == cpu_to_le64(0)) {
2126 CERROR("lov_mds_md: zero lmm_object_id\n");
2131 lsm_size = lov_stripe_md_size(1);
2135 if (*lsmp != NULL && lmm == NULL) {
2136 OBD_FREE(*lsmp, lsm_size);
2141 if (*lsmp == NULL) {
2142 OBD_ALLOC(*lsmp, lsm_size);
2146 loi_init((*lsmp)->lsm_oinfo);
2150 /* XXX zero *lsmp? */
2151 (*lsmp)->lsm_object_id = le64_to_cpu (lmm->lmm_object_id);
2152 LASSERT((*lsmp)->lsm_object_id);
2155 (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
2160 static void filter_destroy_precreated(struct obd_export *exp, struct obdo *oa,
2161 struct filter_obd *filter)
2163 struct obdo doa; /* XXX obdo on stack */
2168 memset(&doa, 0, sizeof(doa));
2169 if (oa->o_valid & OBD_MD_FLGROUP) {
2170 doa.o_valid |= OBD_MD_FLGROUP;
2171 doa.o_gr = oa->o_gr;
2175 doa.o_mode = S_IFREG;
2177 filter->fo_destroy_in_progress = 1;
2178 down(&filter->fo_create_lock);
2179 if (!filter->fo_destroy_in_progress) {
2180 CERROR("%s: destroy_in_progress already cleared\n",
2181 exp->exp_obd->obd_name);
2182 up(&filter->fo_create_lock);
2187 last = filter_last_id(filter, &doa);
2188 CWARN("%s: deleting orphan objects from "LPU64" to "LPU64"\n",
2189 exp->exp_obd->obd_name, oa->o_id + 1, last);
2190 for (id = oa->o_id + 1; id <= last; id++) {
2192 filter_destroy(exp, &doa, NULL, NULL);
2195 CDEBUG(D_HA, "%s: after destroy: set last_objids["LPU64"] = "LPU64"\n",
2196 exp->exp_obd->obd_name, doa.o_gr, oa->o_id);
2198 spin_lock(&filter->fo_objidlock);
2199 filter->fo_last_objids[doa.o_gr] = oa->o_id;
2200 spin_unlock(&filter->fo_objidlock);
2202 filter->fo_destroy_in_progress = 0;
2203 up(&filter->fo_create_lock);
2208 /* returns a negative error or a nonnegative number of files to create */
2209 static int filter_should_precreate(struct obd_export *exp, struct obdo *oa,
2212 struct obd_device *obd = exp->exp_obd;
2213 struct filter_obd *filter = &obd->u.filter;
2217 diff = oa->o_id - filter_last_id(filter, oa);
2218 CDEBUG(D_INFO, "filter_last_id() = "LPU64" -> diff = %d\n",
2219 filter_last_id(filter, oa), diff);
2221 /* delete orphans request */
2222 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2223 (oa->o_flags & OBD_FL_DELORPHAN)) {
2226 if (-diff > OST_MAX_PRECREATE) {
2227 CERROR("%s: ignoring bogus orphan destroy request: "
2228 "obdid "LPU64" last_id "LPU64"\n", obd->obd_name,
2229 oa->o_id, filter_last_id(filter, oa));
2232 filter_destroy_precreated(exp, oa, filter);
2233 rc = filter_update_last_objid(obd, group, 0);
2235 CERROR("%s: unable to write lastobjid, but orphans"
2236 "were deleted\n", obd->obd_name);
2239 /* only precreate if group == 0 and o_id is specfied */
2240 if (!(oa->o_valid & OBD_FL_DELORPHAN) &&
2241 (group != 0 || oa->o_id == 0))
2244 LASSERTF(diff >= 0,"%s: "LPU64" - "LPU64" = %d\n",obd->obd_name,
2245 oa->o_id, filter_last_id(filter, oa), diff);
2250 static int filter_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2251 unsigned long max_age)
2253 struct filter_obd *filter = &obd->u.filter;
2254 int blockbits = filter->fo_sb->s_blocksize_bits;
2258 /* at least try to account for cached pages. its still racey and
2259 * might be under-reporting if clients haven't announced their
2260 * caches with brw recently */
2261 spin_lock(&obd->obd_osfs_lock);
2262 rc = fsfilt_statfs(obd, filter->fo_sb, max_age);
2263 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
2264 spin_unlock(&obd->obd_osfs_lock);
2266 CDEBUG(D_SUPER | D_CACHE, "blocks cached "LPU64" granted "LPU64
2267 " pending "LPU64" free "LPU64" avail "LPU64"\n",
2268 filter->fo_tot_dirty, filter->fo_tot_granted,
2269 filter->fo_tot_pending,
2270 osfs->os_bfree << blockbits, osfs->os_bavail << blockbits);
2272 filter_grant_sanity_check(obd, __FUNCTION__);
2274 osfs->os_bavail -= min(osfs->os_bavail, GRANT_FOR_LLOG(obd) +
2275 ((filter->fo_tot_dirty + filter->fo_tot_pending +
2276 osfs->os_bsize - 1) >> blockbits));
2280 /* We rely on the fact that only one thread will be creating files in a given
2281 * group at a time, which is why we don't need an atomic filter_get_new_id.
2282 * Even if we had that atomic function, the following race would exist:
2284 * thread 1: gets id x from filter_next_id
2285 * thread 2: gets id (x + 1) from filter_next_id
2286 * thread 2: creates object (x + 1)
2287 * thread 1: tries to create object x, gets -ENOSPC
2289 static int filter_precreate(struct obd_device *obd, struct obdo *oa,
2290 obd_gr group, int *num)
2292 struct dentry *dchild = NULL, *dparent = NULL;
2293 struct filter_obd *filter;
2294 struct obd_statfs *osfs;
2295 int err = 0, rc = 0, recreate_obj = 0, i;
2296 unsigned long enough_time = jiffies + (obd_timeout * HZ) / 3;
2298 void *handle = NULL;
2301 filter = &obd->u.filter;
2303 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2304 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2307 OBD_ALLOC(osfs, sizeof(*osfs));
2310 rc = filter_statfs(obd, osfs, jiffies - HZ);
2311 if (rc == 0 && osfs->os_bavail < (osfs->os_blocks >> 10)) {
2312 CDEBUG(D_HA, "OST out of space! avail "LPU64"\n",
2313 osfs->os_bavail<<filter->fo_sb->s_blocksize_bits);
2317 OBD_FREE(osfs, sizeof(*osfs));
2323 CDEBUG(D_HA, "%s: precreating %d objects\n", obd->obd_name, *num);
2325 down(&filter->fo_create_lock);
2327 for (i = 0; i < *num && err == 0; i++) {
2328 int cleanup_phase = 0;
2330 if (filter->fo_destroy_in_progress) {
2331 CWARN("%s: precreate aborted by destroy\n",
2339 last_id = filter_last_id(filter, oa);
2340 if (next_id > last_id) {
2341 CERROR("Error: Trying to recreate obj greater"
2342 "than last id "LPD64" > "LPD64"\n",
2344 GOTO(cleanup, rc = -EINVAL);
2347 next_id = filter_last_id(filter, oa) + 1;
2349 CDEBUG(D_INFO, "precreate objid "LPU64"\n", next_id);
2351 dparent = filter_parent_lock(obd, group, next_id);
2352 if (IS_ERR(dparent))
2353 GOTO(cleanup, rc = PTR_ERR(dparent));
2356 dchild = filter_fid2dentry(obd, dparent, group, next_id);
2358 GOTO(cleanup, rc = PTR_ERR(dchild));
2361 if (dchild->d_inode != NULL) {
2362 /* This would only happen if lastobjid was bad on disk*/
2363 /* Could also happen if recreating missing obj but
2367 CERROR("%s: recreating existing object %.*s?\n",
2368 obd->obd_name, dchild->d_name.len,
2369 dchild->d_name.name);
2371 CERROR("%s: Serious error: objid %.*s already "
2372 "exists; is this filesystem corrupt?\n",
2373 obd->obd_name, dchild->d_name.len,
2374 dchild->d_name.name);
2377 GOTO(cleanup, rc = -EEXIST);
2380 handle = fsfilt_start_log(obd, dparent->d_inode,
2381 FSFILT_OP_CREATE, NULL, 1);
2383 GOTO(cleanup, rc = PTR_ERR(handle));
2386 rc = ll_vfs_create(dparent->d_inode, dchild, S_IFREG | 0666, NULL);
2388 CERROR("create failed rc = %d\n", rc);
2392 if (!recreate_obj) {
2393 filter_set_last_id(filter, oa, next_id);
2394 err = filter_update_last_objid(obd, group, 0);
2396 CERROR("unable to write lastobjid "
2397 "but file created\n");
2401 switch(cleanup_phase) {
2403 err = fsfilt_commit(obd, dparent->d_inode, handle, 0);
2405 CERROR("error on commit, err = %d\n", err);
2412 filter_parent_unlock(dparent);
2419 if (time_after(jiffies, enough_time)) {
2420 CDEBUG(D_INODE,"%s: precreate slow - want %d got %d \n",
2421 obd->obd_name, *num, i);
2427 up(&filter->fo_create_lock);
2429 CDEBUG(D_HA, "%s: server last_objid for group "LPU64": "LPU64"\n",
2430 obd->obd_name, group, filter->fo_last_objids[group]);
2432 CDEBUG(D_HA, "%s: filter_precreate() created %d objects\n",
2437 static int filter_create(struct obd_export *exp, struct obdo *oa,
2438 struct lov_stripe_md **ea, struct obd_trans_info *oti)
2440 struct obd_device *obd = NULL;
2441 struct lvfs_run_ctxt saved;
2442 struct lov_stripe_md *lsm = NULL;
2447 if (oa->o_valid & OBD_MD_FLGROUP)
2450 CDEBUG(D_INFO, "filter_create(od->o_gr="LPU64",od->o_id="LPU64")\n",
2455 rc = obd_alloc_memmd(exp, &lsm);
2462 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2464 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2465 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2466 if (oa->o_id > filter_last_id(&obd->u.filter, oa)) {
2467 CERROR("recreate objid "LPU64" > last id "LPU64"\n",
2468 oa->o_id, filter_last_id(&obd->u.filter, oa));
2472 rc = filter_precreate(obd, oa, group, &diff);
2475 diff = filter_should_precreate(exp, oa, group);
2477 oa->o_id = filter_last_id(&obd->u.filter, oa);
2478 rc = filter_precreate(obd, oa, group, &diff);
2479 oa->o_id = filter_last_id(&obd->u.filter, oa);
2480 oa->o_valid = OBD_MD_FLID;
2484 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2485 if (rc && ea != NULL && *ea != lsm) {
2486 obd_free_memmd(exp, &lsm);
2487 } else if (rc == 0 && ea != NULL) {
2488 /* XXX LOV STACKING: the lsm that is passed to us from
2489 * LOV does not have valid lsm_oinfo data structs, so
2490 * don't go touching that. This needs to be fixed in a
2492 lsm->lsm_object_id = oa->o_id;
2499 int filter_destroy(struct obd_export *exp, struct obdo *oa,
2500 struct lov_stripe_md *md, struct obd_trans_info *oti)
2502 struct obd_device *obd;
2503 struct filter_obd *filter;
2504 struct dentry *dchild = NULL, *dparent = NULL;
2505 struct lvfs_run_ctxt saved;
2506 void *handle = NULL;
2507 struct llog_cookie *fcc = NULL;
2508 int rc, rc2, cleanup_phase = 0, have_prepared = 0;
2512 if (oa->o_valid & OBD_MD_FLGROUP)
2516 filter = &obd->u.filter;
2518 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2521 dparent = filter_parent_lock(obd, group, oa->o_id);
2522 if (IS_ERR(dparent))
2523 GOTO(cleanup, rc = PTR_ERR(dparent));
2526 dchild = filter_fid2dentry(obd, dparent, group, oa->o_id);
2528 GOTO(cleanup, rc = PTR_ERR(dchild));
2531 if (dchild->d_inode == NULL) {
2532 CDEBUG(D_INODE, "destroying non-existent object "LPU64"\n",
2534 /* If object already gone, cancel cookie right now */
2535 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2536 fcc = obdo_logcookie(oa);
2537 llog_cancel(llog_get_context(obd, fcc->lgc_subsys + 1),
2540 GOTO(cleanup, rc = -ENOENT);
2543 if (!have_prepared) {
2544 /* If we're really going to destroy the object, get ready
2545 * by getting the clients to discard their cached data.
2547 * We have to drop the parent lock, because
2548 * filter_prepare_destroy will acquire a PW on the object, and
2549 * we don't want to deadlock with an incoming write to the
2550 * object, which has the extent PW and then wants to get the
2551 * parent dentry to do the lookup.
2553 * We dput the child because it's not worth the extra
2554 * complication of condition the above code to skip it on the
2555 * second time through. */
2557 filter_parent_unlock(dparent);
2559 filter_prepare_destroy(obd, oa->o_id);
2564 handle = fsfilt_start_log(obd, dparent->d_inode,FSFILT_OP_UNLINK,oti,1);
2566 GOTO(cleanup, rc = PTR_ERR(handle));
2569 /* Our MDC connection is established by the MDS to us */
2570 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2571 OBD_ALLOC(fcc, sizeof(*fcc));
2573 memcpy(fcc, obdo_logcookie(oa), sizeof(*fcc));
2576 /* Quota release need uid/gid of inode */
2577 obdo_from_inode(oa, dchild->d_inode, OBD_MD_FLUID|OBD_MD_FLGID);
2578 rc = filter_destroy_internal(obd, oa->o_id, dparent, dchild);
2581 switch(cleanup_phase) {
2584 fsfilt_add_journal_cb(obd, 0,
2585 oti ? oti->oti_handle : handle,
2586 filter_cancel_cookies_cb, fcc);
2588 rc = filter_finish_transno(exp, oti, rc);
2589 rc2 = fsfilt_commit(obd, dparent->d_inode, handle, 0);
2591 CERROR("error on commit, err = %d\n", rc2);
2598 filter_parent_unlock(dparent);
2600 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2603 CERROR("invalid cleanup_phase %d\n", cleanup_phase);
2607 /* trigger quota release */
2609 rc2 = qctxt_adjust_qunit(obd, &filter->fo_quota_ctxt,
2610 oa->o_uid, oa->o_gid, 1);
2612 CERROR("error filter adjust qunit! (rc:%d)\n", rc2);
2618 /* NB start and end are used for punch, but not truncate */
2619 static int filter_truncate(struct obd_export *exp, struct obdo *oa,
2620 struct lov_stripe_md *lsm,
2621 obd_off start, obd_off end,
2622 struct obd_trans_info *oti)
2627 if (end != OBD_OBJECT_EOF) {
2628 CERROR("PUNCH not supported, only truncate: end = "LPX64"\n",
2633 CDEBUG(D_INODE, "calling truncate for object "LPU64", valid = "LPX64
2634 ", o_size = "LPD64"\n", oa->o_id, oa->o_valid, start);
2636 error = filter_setattr(exp, oa, NULL, oti);
2640 static int filter_sync(struct obd_export *exp, struct obdo *oa,
2641 struct lov_stripe_md *lsm, obd_off start, obd_off end)
2643 struct lvfs_run_ctxt saved;
2644 struct filter_obd *filter;
2645 struct dentry *dentry;
2646 struct llog_ctxt *ctxt;
2650 filter = &exp->exp_obd->u.filter;
2652 /* an objid of zero is taken to mean "sync whole filesystem" */
2653 if (!oa || !(oa->o_valid & OBD_MD_FLID)) {
2654 rc = fsfilt_sync(exp->exp_obd, filter->fo_sb);
2655 /* flush any remaining cancel messages out to the target */
2656 ctxt = llog_get_context(exp->exp_obd, LLOG_MDS_OST_REPL_CTXT);
2657 llog_sync(ctxt, exp);
2661 dentry = filter_oa2dentry(exp->exp_obd, oa);
2663 RETURN(PTR_ERR(dentry));
2665 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2667 down(&dentry->d_inode->i_sem);
2668 rc = filemap_fdatawrite(dentry->d_inode->i_mapping);
2670 /* just any file to grab fsync method - "file" arg unused */
2671 struct file *file = filter->fo_rcvd_filp;
2673 if (file->f_op && file->f_op->fsync)
2674 rc = file->f_op->fsync(NULL, dentry, 1);
2676 rc2 = filemap_fdatawait(dentry->d_inode->i_mapping);
2680 up(&dentry->d_inode->i_sem);
2682 oa->o_valid = OBD_MD_FLID;
2683 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
2685 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2691 static int filter_get_info(struct obd_export *exp, __u32 keylen,
2692 void *key, __u32 *vallen, void *val)
2694 struct obd_device *obd;
2697 obd = class_exp2obd(exp);
2699 CDEBUG(D_IOCTL, "invalid client export %p\n", exp);
2703 if (keylen == strlen("blocksize") &&
2704 memcmp(key, "blocksize", keylen) == 0) {
2705 __u32 *blocksize = val;
2706 *vallen = sizeof(*blocksize);
2707 *blocksize = obd->u.filter.fo_sb->s_blocksize;
2711 if (keylen == strlen("blocksize_bits") &&
2712 memcmp(key, "blocksize_bits", keylen) == 0) {
2713 __u32 *blocksize_bits = val;
2714 *vallen = sizeof(*blocksize_bits);
2715 *blocksize_bits = obd->u.filter.fo_sb->s_blocksize_bits;
2719 if (keylen >= strlen("last_id") && memcmp(key, "last_id", 7) == 0) {
2720 obd_id *last_id = val;
2721 /* FIXME: object groups */
2722 *last_id = filter_last_id(&obd->u.filter, 0);
2725 CDEBUG(D_IOCTL, "invalid key\n");
2729 static int filter_set_info(struct obd_export *exp, __u32 keylen,
2730 void *key, __u32 vallen, void *val)
2732 struct obd_device *obd;
2733 struct llog_ctxt *ctxt;
2739 CDEBUG(D_IOCTL, "invalid export %p\n", exp);
2743 if (keylen < strlen("mds_conn") ||
2744 memcmp(key, "mds_conn", keylen) != 0)
2747 CWARN("%s: received MDS connection from %s\n", obd->obd_name,
2748 obd_export_nid2str(exp));
2749 obd->u.filter.fo_mdc_conn.cookie = exp->exp_handle.h_cookie;
2751 /* setup llog imports */
2752 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
2753 rc = llog_receptor_accept(ctxt, exp->exp_imp_reverse);
2755 filter_quota_set_info(exp, obd);
2760 int filter_iocontrol(unsigned int cmd, struct obd_export *exp,
2761 int len, void *karg, void *uarg)
2763 struct obd_device *obd = exp->exp_obd;
2764 struct obd_ioctl_data *data = karg;
2768 case OBD_IOC_ABORT_RECOVERY: {
2769 CERROR("aborting recovery for device %s\n", obd->obd_name);
2770 target_abort_recovery(obd);
2774 case OBD_IOC_SYNC: {
2775 CDEBUG(D_HA, "syncing ost %s\n", obd->obd_name);
2776 rc = fsfilt_sync(obd, obd->u.filter.fo_sb);
2780 case OBD_IOC_SET_READONLY: {
2782 struct super_block *sb = obd->u.filter.fo_sb;
2783 struct inode *inode = sb->s_root->d_inode;
2784 BDEVNAME_DECLARE_STORAGE(tmp);
2785 CERROR("*** setting device %s read-only ***\n",
2786 ll_bdevname(sb, tmp));
2788 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
2789 if (!IS_ERR(handle))
2790 rc = fsfilt_commit(obd, inode, handle, 1);
2792 CDEBUG(D_HA, "syncing ost %s\n", obd->obd_name);
2793 rc = fsfilt_sync(obd, obd->u.filter.fo_sb);
2795 lvfs_set_rdonly(lvfs_sbdev(obd->u.filter.fo_sb));
2799 case OBD_IOC_CATLOGLIST: {
2800 rc = llog_catalog_list(obd, 1, data);
2804 case OBD_IOC_LLOG_CANCEL:
2805 case OBD_IOC_LLOG_REMOVE:
2806 case OBD_IOC_LLOG_INFO:
2807 case OBD_IOC_LLOG_PRINT: {
2808 /* FIXME to be finished */
2809 RETURN(-EOPNOTSUPP);
2811 struct llog_ctxt *ctxt = NULL;
2813 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
2814 rc = llog_ioctl(ctxt, cmd, data);
2815 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
2828 static int filter_health_check(struct obd_device *obd)
2830 struct filter_obd *filter = &obd->u.filter;
2834 * health_check to return 0 on healthy
2835 * and 1 on unhealthy.
2837 if (filter->fo_sb->s_flags & MS_RDONLY)
2840 LASSERT(filter->fo_health_check_filp != NULL);
2841 rc |= !!lvfs_check_io_health(obd, filter->fo_health_check_filp);
2846 static struct dentry *filter_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
2849 return filter_fid2dentry(data, NULL, gr, id);
2852 static struct lvfs_callback_ops filter_lvfs_ops = {
2853 l_fid2dentry: filter_lvfs_fid2dentry,
2856 static struct obd_ops filter_obd_ops = {
2857 .o_owner = THIS_MODULE,
2858 .o_get_info = filter_get_info,
2859 .o_set_info = filter_set_info,
2860 .o_setup = filter_setup,
2861 .o_precleanup = filter_precleanup,
2862 .o_cleanup = filter_cleanup,
2863 .o_connect = filter_connect,
2864 .o_reconnect = filter_reconnect,
2865 .o_disconnect = filter_disconnect,
2866 .o_statfs = filter_statfs,
2867 .o_getattr = filter_getattr,
2868 .o_unpackmd = filter_unpackmd,
2869 .o_create = filter_create,
2870 .o_setattr = filter_setattr,
2871 .o_destroy = filter_destroy,
2872 .o_brw = filter_brw,
2873 .o_punch = filter_truncate,
2874 .o_sync = filter_sync,
2875 .o_preprw = filter_preprw,
2876 .o_commitrw = filter_commitrw,
2877 .o_destroy_export = filter_destroy_export,
2878 .o_llog_init = filter_llog_init,
2879 .o_llog_finish = filter_llog_finish,
2880 .o_iocontrol = filter_iocontrol,
2881 .o_quotacheck = filter_quotacheck,
2882 .o_quotactl = filter_quotactl,
2883 .o_health_check = filter_health_check,
2886 static struct obd_ops filter_sanobd_ops = {
2887 .o_owner = THIS_MODULE,
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_reconnect = filter_reconnect,
2895 .o_disconnect = filter_disconnect,
2896 .o_statfs = filter_statfs,
2897 .o_getattr = filter_getattr,
2898 .o_unpackmd = filter_unpackmd,
2899 .o_create = filter_create,
2900 .o_setattr = filter_setattr,
2901 .o_destroy = filter_destroy,
2902 .o_brw = filter_brw,
2903 .o_punch = filter_truncate,
2904 .o_sync = filter_sync,
2905 .o_preprw = filter_preprw,
2906 .o_commitrw = filter_commitrw,
2907 .o_san_preprw = filter_san_preprw,
2908 .o_destroy_export = filter_destroy_export,
2909 .o_llog_init = filter_llog_init,
2910 .o_llog_finish = filter_llog_finish,
2911 .o_iocontrol = filter_iocontrol,
2914 static int __init obdfilter_init(void)
2916 struct lprocfs_static_vars lvars;
2919 printk(KERN_INFO "Lustre: Filtering OBD driver; info@clusterfs.com\n");
2921 lprocfs_init_vars(filter, &lvars);
2923 OBD_ALLOC(obdfilter_created_scratchpad,
2924 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
2925 sizeof(*obdfilter_created_scratchpad));
2926 if (obdfilter_created_scratchpad == NULL)
2929 rc = class_register_type(&filter_obd_ops, lvars.module_vars,
2930 OBD_FILTER_DEVICENAME);
2934 rc = class_register_type(&filter_sanobd_ops, lvars.module_vars,
2935 OBD_FILTER_SAN_DEVICENAME);
2937 class_unregister_type(OBD_FILTER_DEVICENAME);
2939 OBD_FREE(obdfilter_created_scratchpad,
2940 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
2941 sizeof(*obdfilter_created_scratchpad));
2946 static void __exit obdfilter_exit(void)
2948 class_unregister_type(OBD_FILTER_SAN_DEVICENAME);
2949 class_unregister_type(OBD_FILTER_DEVICENAME);
2950 OBD_FREE(obdfilter_created_scratchpad,
2951 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
2952 sizeof(*obdfilter_created_scratchpad));
2955 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2956 MODULE_DESCRIPTION("Lustre Filtering OBD driver");
2957 MODULE_LICENSE("GPL");
2959 module_init(obdfilter_init);
2960 module_exit(obdfilter_exit);