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_mutex 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_mutex 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 <obd_class.h>
52 #include <lustre_dlm.h>
53 #include <lustre_fsfilt.h>
54 #include <lprocfs_status.h>
55 #include <lustre_log.h>
56 #include <lustre_commit_confd.h>
57 #include <libcfs/list.h>
58 #include <lustre_disk.h>
59 #include <lustre_quota.h>
60 #include <linux/slab.h>
61 #include <lustre_param.h>
63 #include "filter_internal.h"
65 static struct lvfs_callback_ops filter_lvfs_ops;
66 kmem_cache_t *ll_fmd_cachep;
68 static void filter_commit_cb(struct obd_device *obd, __u64 transno,
69 void *cb_data, int error)
71 obd_transno_commit_cb(obd, transno, error);
74 /* Assumes caller has already pushed us into the kernel context. */
75 int filter_finish_transno(struct obd_export *exp, struct obd_trans_info *oti,
78 struct filter_obd *filter = &exp->exp_obd->u.filter;
79 struct filter_export_data *fed = &exp->exp_filter_data;
80 struct filter_client_data *fcd = fed->fed_fcd;
83 int err, log_pri = D_HA;
85 /* Propagate error code. */
89 if (!exp->exp_obd->obd_replayable || oti == NULL)
92 /* we don't allocate new transnos for replayed requests */
93 if (oti->oti_transno == 0) {
94 spin_lock(&filter->fo_translock);
95 last_rcvd = le64_to_cpu(filter->fo_fsd->lsd_last_transno) + 1;
96 filter->fo_fsd->lsd_last_transno = cpu_to_le64(last_rcvd);
97 spin_unlock(&filter->fo_translock);
98 oti->oti_transno = last_rcvd;
100 spin_lock(&filter->fo_translock);
101 last_rcvd = oti->oti_transno;
102 if (last_rcvd > le64_to_cpu(filter->fo_fsd->lsd_last_transno))
103 filter->fo_fsd->lsd_last_transno =
104 cpu_to_le64(last_rcvd);
105 spin_unlock(&filter->fo_translock);
107 fcd->fcd_last_rcvd = cpu_to_le64(last_rcvd);
109 /* could get xid from oti, if it's ever needed */
110 fcd->fcd_last_xid = 0;
112 off = fed->fed_lr_off;
114 CERROR("%s: client idx %d is %lld\n", exp->exp_obd->obd_name,
115 fed->fed_lr_idx, fed->fed_lr_off);
118 fsfilt_add_journal_cb(exp->exp_obd, last_rcvd, oti->oti_handle,
119 filter_commit_cb, NULL);
120 err = fsfilt_write_record(exp->exp_obd, filter->fo_rcvd_filp,
121 fcd, sizeof(*fcd), &off,
130 CDEBUG(log_pri, "wrote trans "LPU64" for client %s at #%d: err = %d\n",
131 last_rcvd, fcd->fcd_uuid, fed->fed_lr_idx, err);
136 void f_dput(struct dentry *dentry)
138 /* Can't go inside filter_ddelete because it can block */
139 CDEBUG(D_INODE, "putting %s: %p, count = %d\n",
140 dentry->d_name.name, dentry, atomic_read(&dentry->d_count) - 1);
141 LASSERT(atomic_read(&dentry->d_count) > 0);
146 static void init_brw_stats(struct brw_stats *brw_stats)
149 for (i = 0; i < BRW_LAST; i++)
150 spin_lock_init(&brw_stats->hist[i].oh_lock);
153 /* brw_stats are 2128, ops are 3916, ldlm are 204, so 6248 bytes per client,
154 plus the procfs overhead :( */
155 static int filter_export_stats_init(struct obd_device *obd,
156 struct obd_export *exp)
158 struct filter_export_data *fed = &exp->exp_filter_data;
159 struct proc_dir_entry *brw_entry;
163 init_brw_stats(&fed->fed_brw_stats);
165 rc = lprocfs_exp_setup(exp);
169 /* Create a per export proc entry for brw_stats */
170 brw_entry = create_proc_entry("brw_stats", 0644, exp->exp_proc);
171 if (brw_entry == NULL)
173 brw_entry->proc_fops = &filter_per_export_stats_fops;
174 brw_entry->data = fed;
176 /* Create a per export proc entry for ops stats */
177 num_stats = (sizeof(*obd->obd_type->typ_ops) / sizeof(void *)) +
178 LPROC_FILTER_LAST - 1;
179 exp->exp_ops_stats = lprocfs_alloc_stats(num_stats);
180 if (exp->exp_ops_stats == NULL)
182 lprocfs_init_ops_stats(LPROC_FILTER_LAST, exp->exp_ops_stats);
183 lprocfs_counter_init(exp->exp_ops_stats, LPROC_FILTER_READ_BYTES,
184 LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
185 lprocfs_counter_init(exp->exp_ops_stats, LPROC_FILTER_WRITE_BYTES,
186 LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
187 lprocfs_register_stats(exp->exp_proc, "stats", exp->exp_ops_stats);
191 /* Add client data to the FILTER. We use a bitmap to locate a free space
192 * in the last_rcvd file if cl_idx is -1 (i.e. a new client).
193 * Otherwise, we have just read the data from the last_rcvd file and
194 * we know its offset. */
195 static int filter_client_add(struct obd_device *obd, struct obd_export *exp,
198 struct filter_obd *filter = &obd->u.filter;
199 struct filter_export_data *fed = &exp->exp_filter_data;
200 unsigned long *bitmap = filter->fo_last_rcvd_slots;
201 int new_client = (cl_idx == -1);
205 LASSERT(bitmap != NULL);
206 LASSERTF(cl_idx > -2, "%d\n", cl_idx);
209 if (strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid) == 0) {
210 init_brw_stats(&fed->fed_brw_stats);
214 /* the bitmap operations can handle cl_idx > sizeof(long) * 8, so
215 * there's no need for extra complication here
218 cl_idx = find_first_zero_bit(bitmap, LR_MAX_CLIENTS);
220 if (cl_idx >= LR_MAX_CLIENTS) {
221 CERROR("no room for %u clients - fix LR_MAX_CLIENTS\n",
225 if (test_and_set_bit(cl_idx, bitmap)) {
226 cl_idx = find_next_zero_bit(bitmap, LR_MAX_CLIENTS,
231 if (test_and_set_bit(cl_idx, bitmap)) {
232 CERROR("FILTER client %d: bit already set in bitmap!\n",
238 fed->fed_lr_idx = cl_idx;
239 fed->fed_lr_off = le32_to_cpu(filter->fo_fsd->lsd_client_start) +
240 cl_idx * le16_to_cpu(filter->fo_fsd->lsd_client_size);
241 LASSERTF(fed->fed_lr_off > 0, "fed_lr_off = %llu\n", fed->fed_lr_off);
242 filter_export_stats_init(obd, exp);
244 CDEBUG(D_INFO, "client at index %d (%llu) with UUID '%s' added\n",
245 fed->fed_lr_idx, fed->fed_lr_off, fed->fed_fcd->fcd_uuid);
248 struct lvfs_run_ctxt saved;
249 loff_t off = fed->fed_lr_off;
253 CDEBUG(D_INFO, "writing client fcd at idx %u (%llu) (len %u)\n",
254 fed->fed_lr_idx,off,(unsigned int)sizeof(*fed->fed_fcd));
256 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
257 /* Transaction needed to fix bug 1403 */
258 handle = fsfilt_start(obd,
259 filter->fo_rcvd_filp->f_dentry->d_inode,
260 FSFILT_OP_SETATTR, NULL);
261 if (IS_ERR(handle)) {
262 rc = PTR_ERR(handle);
263 CERROR("unable to start transaction: rc %d\n", rc);
265 rc = fsfilt_add_journal_cb(obd, 0, handle,
266 target_client_add_cb, exp);
268 exp->exp_need_sync = 1;
269 rc = fsfilt_write_record(obd, filter->fo_rcvd_filp,
271 sizeof(*fed->fed_fcd),
272 &off, rc /* sync if no cb */);
274 filter->fo_rcvd_filp->f_dentry->d_inode,
277 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
280 CERROR("error writing %s client idx %u: rc %d\n",
281 LAST_RCVD, fed->fed_lr_idx, rc);
288 static int filter_client_free(struct obd_export *exp)
290 struct filter_export_data *fed = &exp->exp_filter_data;
291 struct filter_obd *filter = &exp->exp_obd->u.filter;
292 struct obd_device *obd = exp->exp_obd;
293 struct filter_client_data zero_fcd;
294 struct lvfs_run_ctxt saved;
299 if (fed->fed_fcd == NULL)
302 /* XXX if fcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
303 if (strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid ) == 0)
306 CDEBUG(D_INFO, "freeing client at idx %u, offset %lld with UUID '%s'\n",
307 fed->fed_lr_idx, off, fed->fed_fcd->fcd_uuid);
309 lprocfs_exp_cleanup(exp);
311 LASSERT(filter->fo_last_rcvd_slots != NULL);
313 off = fed->fed_lr_off;
315 /* Don't clear fed_lr_idx here as it is likely also unset. At worst
316 * we leak a client slot that will be cleaned on the next recovery. */
318 CERROR("%s: client idx %d has med_off %lld\n",
319 obd->obd_name, fed->fed_lr_idx, off);
320 GOTO(free, rc = -EINVAL);
323 /* Clear the bit _after_ zeroing out the client so we don't
324 race with filter_client_add and zero out new clients.*/
325 if (!test_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
326 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
331 if (!(exp->exp_flags & OBD_OPT_FAILOVER)) {
332 memset(&zero_fcd, 0, sizeof zero_fcd);
333 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
334 rc = fsfilt_write_record(obd, filter->fo_rcvd_filp, &zero_fcd,
335 sizeof(zero_fcd), &off,
336 !exp->exp_libclient);
339 /* update server's transno */
340 filter_update_server_data(obd, filter->fo_rcvd_filp,
342 !exp->exp_libclient);
343 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
345 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
346 "zeroing out client %s at idx %u (%llu) in %s rc %d\n",
347 fed->fed_fcd->fcd_uuid, fed->fed_lr_idx, fed->fed_lr_off,
351 if (!test_and_clear_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
352 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
359 OBD_FREE(fed->fed_fcd, sizeof(*fed->fed_fcd));
365 /* drop fmd reference, free it if last ref. must be called with fed_lock held.*/
366 static inline void filter_fmd_put_nolock(struct filter_export_data *fed,
367 struct filter_mod_data *fmd)
369 LASSERT_SPIN_LOCKED(&fed->fed_lock);
370 if (--fmd->fmd_refcount == 0) {
371 /* XXX when we have persistent reservations and the handle
372 * is stored herein we need to drop it here. */
373 fed->fed_mod_count--;
374 list_del(&fmd->fmd_list);
375 OBD_SLAB_FREE(fmd, ll_fmd_cachep, sizeof(*fmd));
379 /* drop fmd reference, free it if last ref */
380 void filter_fmd_put(struct obd_export *exp, struct filter_mod_data *fmd)
382 struct filter_export_data *fed;
387 fed = &exp->exp_filter_data;
388 spin_lock(&fed->fed_lock);
389 filter_fmd_put_nolock(fed, fmd); /* caller reference */
390 spin_unlock(&fed->fed_lock);
393 /* expire entries from the end of the list if there are too many
394 * or they are too old */
395 static void filter_fmd_expire_nolock(struct filter_obd *filter,
396 struct filter_export_data *fed,
397 struct filter_mod_data *keep)
399 struct filter_mod_data *fmd, *tmp;
401 list_for_each_entry_safe(fmd, tmp, &fed->fed_mod_list, fmd_list) {
405 if (time_before(jiffies, fmd->fmd_expire) &&
406 fed->fed_mod_count < filter->fo_fmd_max_num)
409 list_del_init(&fmd->fmd_list);
410 filter_fmd_put_nolock(fed, fmd); /* list reference */
414 void filter_fmd_expire(struct obd_export *exp)
416 spin_lock(&exp->exp_filter_data.fed_lock);
417 filter_fmd_expire_nolock(&exp->exp_obd->u.filter,
418 &exp->exp_filter_data, NULL);
419 spin_unlock(&exp->exp_filter_data.fed_lock);
422 /* find specified objid, group in export fmd list.
423 * caller must hold fed_lock and take fmd reference itself */
424 static struct filter_mod_data *filter_fmd_find_nolock(struct filter_obd *filter,
425 struct filter_export_data *fed,
426 obd_id objid, obd_gr group)
428 struct filter_mod_data *found = NULL, *fmd;
430 LASSERT_SPIN_LOCKED(&fed->fed_lock);
432 list_for_each_entry_reverse(fmd, &fed->fed_mod_list, fmd_list) {
433 if (fmd->fmd_id == objid && fmd->fmd_gr == group) {
435 list_del(&fmd->fmd_list);
436 list_add_tail(&fmd->fmd_list, &fed->fed_mod_list);
437 fmd->fmd_expire = jiffies + filter->fo_fmd_max_age;
442 filter_fmd_expire_nolock(filter, fed, found);
447 /* Find fmd based on objid and group, or return NULL if not found. */
448 struct filter_mod_data *filter_fmd_find(struct obd_export *exp,
449 obd_id objid, obd_gr group)
451 struct filter_mod_data *fmd;
453 spin_lock(&exp->exp_filter_data.fed_lock);
454 fmd = filter_fmd_find_nolock(&exp->exp_obd->u.filter,
455 &exp->exp_filter_data, objid, group);
457 fmd->fmd_refcount++; /* caller reference */
458 spin_unlock(&exp->exp_filter_data.fed_lock);
463 /* Find fmd based on objid and group, or create a new one if none is found.
464 * It is possible for this function to return NULL under memory pressure,
465 * or if objid = 0 is passed (which will only cause old entries to expire).
466 * Currently this is not fatal because any fmd state is transient and
467 * may also be freed when it gets sufficiently old. */
468 struct filter_mod_data *filter_fmd_get(struct obd_export *exp,
469 obd_id objid, obd_gr group)
471 struct filter_export_data *fed = &exp->exp_filter_data;
472 struct filter_mod_data *found = NULL, *fmd_new = NULL;
474 OBD_SLAB_ALLOC(fmd_new, ll_fmd_cachep, SLAB_NOFS, sizeof(*fmd_new));
476 spin_lock(&fed->fed_lock);
477 found = filter_fmd_find_nolock(&exp->exp_obd->u.filter,fed,objid,group);
480 list_add_tail(&fmd_new->fmd_list, &fed->fed_mod_list);
481 fmd_new->fmd_id = objid;
482 fmd_new->fmd_gr = group;
483 fmd_new->fmd_refcount++; /* list reference */
485 fed->fed_mod_count++;
487 OBD_SLAB_FREE(fmd_new, ll_fmd_cachep, sizeof(*fmd_new));
491 found->fmd_refcount++; /* caller reference */
492 found->fmd_expire = jiffies +
493 exp->exp_obd->u.filter.fo_fmd_max_age;
496 spin_unlock(&fed->fed_lock);
502 /* drop fmd list reference so it will disappear when last reference is put.
503 * This isn't so critical because it would in fact only affect the one client
504 * that is doing the unlink and at worst we have an stale entry referencing
505 * an object that should never be used again. */
506 static void filter_fmd_drop(struct obd_export *exp, obd_id objid, obd_gr group)
508 struct filter_mod_data *found = NULL;
510 spin_lock(&exp->exp_filter_data.fed_lock);
511 found = filter_fmd_find_nolock(&exp->exp_filter_data, objid, group);
513 list_del_init(&found->fmd_list);
514 filter_fmd_put_nolock(&exp->exp_filter_data, found);
516 spin_unlock(&exp->exp_filter_data.fed_lock);
519 #define filter_fmd_drop(exp, objid, group)
522 /* remove all entries from fmd list */
523 static void filter_fmd_cleanup(struct obd_export *exp)
525 struct filter_export_data *fed = &exp->exp_filter_data;
526 struct filter_mod_data *fmd = NULL, *tmp;
528 spin_lock(&fed->fed_lock);
529 list_for_each_entry_safe(fmd, tmp, &fed->fed_mod_list, fmd_list) {
530 list_del_init(&fmd->fmd_list);
531 filter_fmd_put_nolock(fed, fmd);
533 spin_unlock(&fed->fed_lock);
536 static int filter_init_export(struct obd_export *exp)
538 spin_lock_init(&exp->exp_filter_data.fed_lock);
539 INIT_LIST_HEAD(&exp->exp_filter_data.fed_mod_list);
540 exp->exp_connecting = 1;
545 static int filter_free_server_data(struct filter_obd *filter)
547 OBD_FREE(filter->fo_fsd, sizeof(*filter->fo_fsd));
548 filter->fo_fsd = NULL;
549 OBD_FREE(filter->fo_last_rcvd_slots, LR_MAX_CLIENTS / 8);
550 filter->fo_last_rcvd_slots = NULL;
554 /* assumes caller is already in kernel ctxt */
555 int filter_update_server_data(struct obd_device *obd, struct file *filp,
556 struct lr_server_data *fsd, int force_sync)
562 CDEBUG(D_INODE, "server uuid : %s\n", fsd->lsd_uuid);
563 CDEBUG(D_INODE, "server last_rcvd : "LPU64"\n",
564 le64_to_cpu(fsd->lsd_last_transno));
565 CDEBUG(D_INODE, "server last_mount: "LPU64"\n",
566 le64_to_cpu(fsd->lsd_mount_count));
568 fsd->lsd_compat14 = fsd->lsd_last_transno;
569 rc = fsfilt_write_record(obd, filp, fsd, sizeof(*fsd), &off,force_sync);
571 CERROR("error writing lr_server_data: rc = %d\n", rc);
576 int filter_update_last_objid(struct obd_device *obd, obd_gr group,
579 struct filter_obd *filter = &obd->u.filter;
585 if (filter->fo_last_objid_files[group] == NULL) {
586 CERROR("Object group "LPU64" not fully setup; not updating "
587 "last_objid\n", group);
591 CDEBUG(D_INODE, "%s: server last_objid for group "LPU64": "LPU64"\n",
592 obd->obd_name, group, filter->fo_last_objids[group]);
594 tmp = cpu_to_le64(filter->fo_last_objids[group]);
595 rc = fsfilt_write_record(obd, filter->fo_last_objid_files[group],
596 &tmp, sizeof(tmp), &off, force_sync);
598 CERROR("error writing group "LPU64" last objid: rc = %d\n",
603 /* assumes caller has already in kernel ctxt */
604 static int filter_init_server_data(struct obd_device *obd, struct file * filp)
606 struct filter_obd *filter = &obd->u.filter;
607 struct lr_server_data *fsd;
608 struct filter_client_data *fcd = NULL;
609 struct inode *inode = filp->f_dentry->d_inode;
610 unsigned long last_rcvd_size = inode->i_size;
616 /* ensure padding in the struct is the correct size */
617 CLASSERT (offsetof(struct lr_server_data, lsd_padding) +
618 sizeof(fsd->lsd_padding) == LR_SERVER_SIZE);
619 CLASSERT (offsetof(struct filter_client_data, fcd_padding) +
620 sizeof(fcd->fcd_padding) == LR_CLIENT_SIZE);
622 OBD_ALLOC(fsd, sizeof(*fsd));
625 filter->fo_fsd = fsd;
627 OBD_ALLOC(filter->fo_last_rcvd_slots, LR_MAX_CLIENTS / 8);
628 if (filter->fo_last_rcvd_slots == NULL) {
629 OBD_FREE(fsd, sizeof(*fsd));
633 if (last_rcvd_size == 0) {
634 LCONSOLE_WARN("%s: new disk, initializing\n", obd->obd_name);
636 memcpy(fsd->lsd_uuid, obd->obd_uuid.uuid,sizeof(fsd->lsd_uuid));
637 fsd->lsd_last_transno = 0;
638 mount_count = fsd->lsd_mount_count = 0;
639 fsd->lsd_server_size = cpu_to_le32(LR_SERVER_SIZE);
640 fsd->lsd_client_start = cpu_to_le32(LR_CLIENT_START);
641 fsd->lsd_client_size = cpu_to_le16(LR_CLIENT_SIZE);
642 fsd->lsd_subdir_count = cpu_to_le16(FILTER_SUBDIR_COUNT);
643 filter->fo_subdir_count = FILTER_SUBDIR_COUNT;
644 fsd->lsd_feature_incompat = cpu_to_le32(OBD_INCOMPAT_OST);
646 rc = fsfilt_read_record(obd, filp, fsd, sizeof(*fsd), &off);
648 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
652 if (strcmp(fsd->lsd_uuid, obd->obd_uuid.uuid) != 0) {
653 LCONSOLE_ERROR("Trying to start OBD %s using the wrong"
654 " disk %s. Were the /dev/ assignments "
656 obd->obd_uuid.uuid, fsd->lsd_uuid);
657 GOTO(err_fsd, rc = -EINVAL);
659 mount_count = le64_to_cpu(fsd->lsd_mount_count);
660 filter->fo_subdir_count = le16_to_cpu(fsd->lsd_subdir_count);
662 /* Assume old last_rcvd format unless I_C_LR is set */
663 if (!(fsd->lsd_feature_incompat &
664 cpu_to_le32(OBD_INCOMPAT_COMMON_LR)))
665 fsd->lsd_last_transno = fsd->lsd_compat14;
669 if (fsd->lsd_feature_incompat & ~cpu_to_le32(FILTER_INCOMPAT_SUPP)) {
670 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
671 obd->obd_name, le32_to_cpu(fsd->lsd_feature_incompat) &
672 ~FILTER_INCOMPAT_SUPP);
673 GOTO(err_fsd, rc = -EINVAL);
675 if (fsd->lsd_feature_rocompat & ~cpu_to_le32(FILTER_ROCOMPAT_SUPP)) {
676 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
677 obd->obd_name, le32_to_cpu(fsd->lsd_feature_rocompat) &
678 ~FILTER_ROCOMPAT_SUPP);
679 /* Do something like remount filesystem read-only */
680 GOTO(err_fsd, rc = -EINVAL);
683 CDEBUG(D_INODE, "%s: server last_transno : "LPU64"\n",
684 obd->obd_name, le64_to_cpu(fsd->lsd_last_transno));
685 CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
686 obd->obd_name, mount_count + 1);
687 CDEBUG(D_INODE, "%s: server data size: %u\n",
688 obd->obd_name, le32_to_cpu(fsd->lsd_server_size));
689 CDEBUG(D_INODE, "%s: per-client data start: %u\n",
690 obd->obd_name, le32_to_cpu(fsd->lsd_client_start));
691 CDEBUG(D_INODE, "%s: per-client data size: %u\n",
692 obd->obd_name, le32_to_cpu(fsd->lsd_client_size));
693 CDEBUG(D_INODE, "%s: server subdir_count: %u\n",
694 obd->obd_name, le16_to_cpu(fsd->lsd_subdir_count));
695 CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
696 last_rcvd_size <= le32_to_cpu(fsd->lsd_client_start) ? 0 :
697 (last_rcvd_size - le32_to_cpu(fsd->lsd_client_start)) /
698 le16_to_cpu(fsd->lsd_client_size));
700 if (!obd->obd_replayable) {
701 CWARN("%s: recovery support OFF\n", obd->obd_name);
705 for (cl_idx = 0, off = le32_to_cpu(fsd->lsd_client_start);
706 off < last_rcvd_size; cl_idx++) {
708 struct obd_export *exp;
709 struct filter_export_data *fed;
712 OBD_ALLOC(fcd, sizeof(*fcd));
714 GOTO(err_client, rc = -ENOMEM);
717 /* Don't assume off is incremented properly by
718 * fsfilt_read_record(), in case sizeof(*fcd)
719 * isn't the same as fsd->lsd_client_size. */
720 off = le32_to_cpu(fsd->lsd_client_start) +
721 cl_idx * le16_to_cpu(fsd->lsd_client_size);
722 rc = fsfilt_read_record(obd, filp, fcd, sizeof(*fcd), &off);
724 CERROR("error reading FILT %s idx %d off %llu: rc %d\n",
725 LAST_RCVD, cl_idx, off, rc);
726 break; /* read error shouldn't cause startup to fail */
729 if (fcd->fcd_uuid[0] == '\0') {
730 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
735 last_rcvd = le64_to_cpu(fcd->fcd_last_rcvd);
737 /* These exports are cleaned up by filter_disconnect(), so they
738 * need to be set up like real exports as filter_connect() does.
740 exp = class_new_export(obd, (struct obd_uuid *)fcd->fcd_uuid);
741 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
742 " srv lr: "LPU64"\n", fcd->fcd_uuid, cl_idx,
743 last_rcvd, le64_to_cpu(fsd->lsd_last_transno));
745 if (PTR_ERR(exp) == -EALREADY) {
746 /* export already exists, zero out this one */
747 CERROR("Zeroing out duplicate export due to "
749 fcd->fcd_uuid[0] = '\0';
751 GOTO(err_client, rc = PTR_ERR(exp));
754 fed = &exp->exp_filter_data;
756 rc = filter_client_add(obd, exp, cl_idx);
757 LASSERTF(rc == 0, "rc = %d\n", rc); /* can't fail existing */
760 exp->exp_replay_needed = 1;
761 exp->exp_connecting = 0;
762 obd->obd_recoverable_clients++;
763 obd->obd_max_recoverable_clients++;
764 class_export_put(exp);
767 /* Need to check last_rcvd even for duplicated exports. */
768 CDEBUG(D_OTHER, "client at idx %d has last_rcvd = "LPU64"\n",
771 if (last_rcvd > le64_to_cpu(fsd->lsd_last_transno))
772 fsd->lsd_last_transno = cpu_to_le64(last_rcvd);
776 OBD_FREE(fcd, sizeof(*fcd));
778 obd->obd_last_committed = le64_to_cpu(fsd->lsd_last_transno);
780 if (obd->obd_recoverable_clients) {
781 CWARN("RECOVERY: service %s, %d recoverable clients, "
782 "last_rcvd "LPU64"\n", obd->obd_name,
783 obd->obd_recoverable_clients,
784 le64_to_cpu(fsd->lsd_last_transno));
785 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
786 obd->obd_recovering = 1;
787 obd->obd_recovery_start = CURRENT_SECONDS;
788 /* Only used for lprocfs_status */
789 obd->obd_recovery_end = obd->obd_recovery_start +
790 OBD_RECOVERY_TIMEOUT;
794 filter->fo_mount_count = mount_count + 1;
795 fsd->lsd_mount_count = cpu_to_le64(filter->fo_mount_count);
797 /* save it, so mount count and last_transno is current */
798 rc = filter_update_server_data(obd, filp, filter->fo_fsd, 1);
800 GOTO(err_client, rc);
805 class_disconnect_exports(obd);
807 filter_free_server_data(filter);
811 static int filter_cleanup_groups(struct obd_device *obd)
813 struct filter_obd *filter = &obd->u.filter;
815 struct dentry *dentry;
819 if (filter->fo_dentry_O_groups != NULL) {
820 for (i = 0; i < FILTER_GROUPS; i++) {
821 dentry = filter->fo_dentry_O_groups[i];
825 OBD_FREE(filter->fo_dentry_O_groups,
826 FILTER_GROUPS * sizeof(*filter->fo_dentry_O_groups));
827 filter->fo_dentry_O_groups = NULL;
829 if (filter->fo_last_objid_files != NULL) {
830 for (i = 0; i < FILTER_GROUPS; i++) {
831 filp = filter->fo_last_objid_files[i];
835 OBD_FREE(filter->fo_last_objid_files,
836 FILTER_GROUPS * sizeof(*filter->fo_last_objid_files));
837 filter->fo_last_objid_files = NULL;
839 if (filter->fo_dentry_O_sub != NULL) {
840 for (i = 0; i < filter->fo_subdir_count; i++) {
841 dentry = filter->fo_dentry_O_sub[i];
845 OBD_FREE(filter->fo_dentry_O_sub,
846 filter->fo_subdir_count *
847 sizeof(*filter->fo_dentry_O_sub));
848 filter->fo_dentry_O_sub = NULL;
850 if (filter->fo_last_objids != NULL) {
851 OBD_FREE(filter->fo_last_objids,
852 FILTER_GROUPS * sizeof(*filter->fo_last_objids));
853 filter->fo_last_objids = NULL;
855 if (filter->fo_dentry_O != NULL) {
856 f_dput(filter->fo_dentry_O);
857 filter->fo_dentry_O = NULL;
862 /* FIXME: object groups */
863 static int filter_prep_groups(struct obd_device *obd)
865 struct filter_obd *filter = &obd->u.filter;
866 struct dentry *dentry, *O_dentry;
868 int i, rc = 0, cleanup_phase = 0;
871 O_dentry = simple_mkdir(current->fs->pwd, "O", 0700, 1);
872 CDEBUG(D_INODE, "got/created O: %p\n", O_dentry);
873 if (IS_ERR(O_dentry)) {
874 rc = PTR_ERR(O_dentry);
875 CERROR("cannot open/create O: rc = %d\n", rc);
878 filter->fo_dentry_O = O_dentry;
879 cleanup_phase = 1; /* O_dentry */
881 OBD_ALLOC(filter->fo_last_objids, FILTER_GROUPS * sizeof(__u64));
882 if (filter->fo_last_objids == NULL)
883 GOTO(cleanup, rc = -ENOMEM);
884 cleanup_phase = 2; /* groups */
886 OBD_ALLOC(filter->fo_dentry_O_groups, FILTER_GROUPS * sizeof(dentry));
887 if (filter->fo_dentry_O_groups == NULL)
888 GOTO(cleanup, rc = -ENOMEM);
889 OBD_ALLOC(filter->fo_last_objid_files, FILTER_GROUPS * sizeof(filp));
890 if (filter->fo_last_objid_files == NULL)
891 GOTO(cleanup, rc = -ENOMEM);
893 for (i = 0; i < FILTER_GROUPS; i++) {
897 sprintf(name, "%d", i);
898 dentry = simple_mkdir(O_dentry, name, 0700, 1);
899 CDEBUG(D_INODE, "got/created O/%s: %p\n", name, dentry);
900 if (IS_ERR(dentry)) {
901 rc = PTR_ERR(dentry);
902 CERROR("cannot lookup/create O/%s: rc = %d\n",
906 filter->fo_dentry_O_groups[i] = dentry;
908 sprintf(name, "O/%d/LAST_ID", i);
909 filp = filp_open(name, O_CREAT | O_RDWR, 0700);
912 CERROR("cannot create %s: rc = %d\n", name, rc);
915 filter->fo_last_objid_files[i] = filp;
917 if (filp->f_dentry->d_inode->i_size == 0) {
918 filter->fo_last_objids[i] = FILTER_INIT_OBJID;
919 rc = filter_update_last_objid(obd, i, 1);
925 rc = fsfilt_read_record(obd, filp, &filter->fo_last_objids[i],
926 sizeof(__u64), &off);
928 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
932 filter->fo_last_objids[i] =
933 le64_to_cpu(filter->fo_last_objids[i]);
934 CDEBUG(D_HA, "%s: server last_objid group %d: "LPU64"\n",
935 obd->obd_name, i, filter->fo_last_objids[i]);
938 if (filter->fo_subdir_count) {
939 O_dentry = filter->fo_dentry_O_groups[0];
940 OBD_ALLOC(filter->fo_dentry_O_sub,
941 filter->fo_subdir_count * sizeof(dentry));
942 if (filter->fo_dentry_O_sub == NULL)
943 GOTO(cleanup, rc = -ENOMEM);
945 for (i = 0; i < filter->fo_subdir_count; i++) {
947 snprintf(dir, sizeof(dir), "d%u", i);
949 dentry = simple_mkdir(O_dentry, dir, 0700, 1);
950 CDEBUG(D_INODE, "got/created O/0/%s: %p\n", dir,dentry);
951 if (IS_ERR(dentry)) {
952 rc = PTR_ERR(dentry);
953 CERROR("can't lookup/create O/0/%s: rc = %d\n",
957 filter->fo_dentry_O_sub[i] = dentry;
963 filter_cleanup_groups(obd);
967 /* setup the object store with correct subdirectories */
968 static int filter_prep(struct obd_device *obd)
970 struct lvfs_run_ctxt saved;
971 struct filter_obd *filter = &obd->u.filter;
977 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
978 file = filp_open(LAST_RCVD, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
979 if (!file || IS_ERR(file)) {
981 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
985 filter->fo_rcvd_filp = file;
986 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
987 CERROR("%s is not a regular file!: mode = %o\n", LAST_RCVD,
988 file->f_dentry->d_inode->i_mode);
989 GOTO(err_filp, rc = -ENOENT);
992 inode = file->f_dentry->d_parent->d_inode;
993 /* We use i_op->unlink directly in filter_vfs_unlink() */
994 if (!inode->i_op || !inode->i_op->create || !inode->i_op->unlink) {
995 CERROR("%s: filesystem does not support create/unlink ops\n",
997 GOTO(err_filp, rc = -EOPNOTSUPP);
1000 rc = filter_init_server_data(obd, file);
1002 CERROR("cannot read %s: rc = %d\n", LAST_RCVD, rc);
1005 /* open and create health check io file*/
1006 file = filp_open(HEALTH_CHECK, O_RDWR | O_CREAT, 0644);
1009 CERROR("OBD filter: cannot open/create %s rc = %d\n",
1013 filter->fo_health_check_filp = file;
1014 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
1015 CERROR("%s is not a regular file!: mode = %o\n", HEALTH_CHECK,
1016 file->f_dentry->d_inode->i_mode);
1017 GOTO(err_health_check, rc = -ENOENT);
1019 rc = lvfs_check_io_health(obd, file);
1021 GOTO(err_health_check, rc);
1023 rc = filter_prep_groups(obd);
1025 GOTO(err_server_data, rc);
1027 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1032 //class_disconnect_exports(obd, 0);
1033 filter_free_server_data(filter);
1035 if (filp_close(filter->fo_health_check_filp, 0))
1036 CERROR("can't close %s after error\n", HEALTH_CHECK);
1037 filter->fo_health_check_filp = NULL;
1039 if (filp_close(filter->fo_rcvd_filp, 0))
1040 CERROR("can't close %s after error\n", LAST_RCVD);
1041 filter->fo_rcvd_filp = NULL;
1045 /* cleanup the filter: write last used object id to status file */
1046 static void filter_post(struct obd_device *obd)
1048 struct lvfs_run_ctxt saved;
1049 struct filter_obd *filter = &obd->u.filter;
1052 /* XXX: filter_update_lastobjid used to call fsync_dev. It might be
1053 * best to start a transaction with h_sync, because we removed this
1056 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1057 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
1060 CERROR("error writing server data: rc = %d\n", rc);
1062 for (i = 0; i < FILTER_GROUPS; i++) {
1063 rc = filter_update_last_objid(obd, i, (i == FILTER_GROUPS - 1));
1065 CERROR("error writing group %d lastobjid: rc = %d\n",
1069 rc = filp_close(filter->fo_rcvd_filp, 0);
1070 filter->fo_rcvd_filp = NULL;
1072 CERROR("error closing %s: rc = %d\n", LAST_RCVD, rc);
1074 rc = filp_close(filter->fo_health_check_filp, 0);
1075 filter->fo_health_check_filp = NULL;
1077 CERROR("error closing %s: rc = %d\n", HEALTH_CHECK, rc);
1079 filter_cleanup_groups(obd);
1080 filter_free_server_data(filter);
1081 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1084 static void filter_set_last_id(struct filter_obd *filter,
1085 obd_id id, obd_gr group)
1087 LASSERT(filter->fo_fsd != NULL);
1088 LASSERT(group <= FILTER_GROUPS);
1090 spin_lock(&filter->fo_objidlock);
1091 filter->fo_last_objids[group] = id;
1092 spin_unlock(&filter->fo_objidlock);
1095 obd_id filter_last_id(struct filter_obd *filter, obd_gr group)
1098 LASSERT(filter->fo_fsd != NULL);
1099 LASSERT(group <= FILTER_GROUPS);
1101 /* FIXME: object groups */
1102 spin_lock(&filter->fo_objidlock);
1103 id = filter->fo_last_objids[group];
1104 spin_unlock(&filter->fo_objidlock);
1109 static int filter_lock_dentry(struct obd_device *obd, struct dentry *dparent)
1111 LOCK_INODE_MUTEX(dparent->d_inode);
1115 /* We never dget the object parent, so DON'T dput it either */
1116 struct dentry *filter_parent(struct obd_device *obd, obd_gr group, obd_id objid)
1118 struct filter_obd *filter = &obd->u.filter;
1119 LASSERT(group < FILTER_GROUPS); /* FIXME: object groups */
1121 if (group > 0 || filter->fo_subdir_count == 0)
1122 return filter->fo_dentry_O_groups[group];
1124 return filter->fo_dentry_O_sub[objid & (filter->fo_subdir_count - 1)];
1127 /* We never dget the object parent, so DON'T dput it either */
1128 struct dentry *filter_parent_lock(struct obd_device *obd, obd_gr group,
1131 unsigned long now = jiffies;
1132 struct dentry *dparent = filter_parent(obd, group, objid);
1135 if (IS_ERR(dparent))
1138 rc = filter_lock_dentry(obd, dparent);
1139 fsfilt_check_slow(obd, now, obd_timeout, "parent lock");
1140 return rc ? ERR_PTR(rc) : dparent;
1143 /* We never dget the object parent, so DON'T dput it either */
1144 static void filter_parent_unlock(struct dentry *dparent)
1146 UNLOCK_INODE_MUTEX(dparent->d_inode);
1149 /* How to get files, dentries, inodes from object id's.
1151 * If dir_dentry is passed, the caller has already locked the parent
1152 * appropriately for this operation (normally a write lock). If
1153 * dir_dentry is NULL, we do a read lock while we do the lookup to
1154 * avoid races with create/destroy and such changing the directory
1155 * internal to the filesystem code. */
1156 struct dentry *filter_fid2dentry(struct obd_device *obd,
1157 struct dentry *dir_dentry,
1158 obd_gr group, obd_id id)
1160 struct dentry *dparent = dir_dentry;
1161 struct dentry *dchild;
1166 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT) &&
1167 !obd->u.filter.fo_destroy_in_progress) {
1168 /* don't fail lookups for orphan recovery, it causes
1169 * later LBUGs when objects still exist during precreate */
1170 CDEBUG(D_INFO, "*** obd_fail_loc=%x ***\n",OBD_FAIL_OST_ENOENT);
1171 RETURN(ERR_PTR(-ENOENT));
1175 CERROR("fatal: invalid object id 0\n");
1176 RETURN(ERR_PTR(-ESTALE));
1179 len = sprintf(name, LPU64, id);
1180 if (dir_dentry == NULL) {
1181 dparent = filter_parent_lock(obd, group, id);
1182 if (IS_ERR(dparent)) {
1183 CERROR("%s: error getting object "LPU64":"LPU64
1184 " parent: rc %ld\n", obd->obd_name,
1185 id, group, PTR_ERR(dparent));
1189 CDEBUG(D_INODE, "looking up object O/%.*s/%s\n",
1190 dparent->d_name.len, dparent->d_name.name, name);
1191 dchild = /*ll_*/lookup_one_len(name, dparent, len);
1192 if (dir_dentry == NULL)
1193 filter_parent_unlock(dparent);
1194 if (IS_ERR(dchild)) {
1195 CERROR("%s: child lookup error %ld\n", obd->obd_name,
1200 if (dchild->d_inode != NULL && is_bad_inode(dchild->d_inode)) {
1201 CERROR("%s: got bad object "LPU64" inode %lu\n",
1202 obd->obd_name, id, dchild->d_inode->i_ino);
1204 RETURN(ERR_PTR(-ENOENT));
1207 CDEBUG(D_INODE, "got child objid %s: %p, count = %d\n",
1208 name, dchild, atomic_read(&dchild->d_count));
1210 LASSERT(atomic_read(&dchild->d_count) > 0);
1215 static int filter_prepare_destroy(struct obd_device *obd, obd_id objid)
1217 struct lustre_handle lockh;
1218 int flags = LDLM_AST_DISCARD_DATA, rc;
1219 struct ldlm_res_id res_id = { .name = { objid } };
1220 ldlm_policy_data_t policy = { .l_extent = { 0, OBD_OBJECT_EOF } };
1223 /* Tell the clients that the object is gone now and that they should
1224 * throw away any cached pages. */
1225 rc = ldlm_cli_enqueue_local(obd->obd_namespace, res_id, LDLM_EXTENT,
1226 &policy, LCK_PW, &flags, ldlm_blocking_ast,
1227 ldlm_completion_ast, NULL, NULL, 0, NULL,
1230 /* We only care about the side-effects, just drop the lock. */
1232 ldlm_lock_decref(&lockh, LCK_PW);
1237 /* This is vfs_unlink() without down(i_sem). If we call regular vfs_unlink()
1238 * we have 2.6 lock ordering issues with filter_commitrw_write() as it takes
1239 * i_sem before starting a handle, while filter_destroy() + vfs_unlink do the
1240 * reverse. Caller must take i_sem before starting the transaction and we
1241 * drop it here before the inode is removed from the dentry. bug 4180/6984 */
1242 int filter_vfs_unlink(struct inode *dir, struct dentry *dentry)
1247 /* don't need dir->i_zombie for 2.4, it is for rename/unlink of dir
1248 * itself we already hold dir->i_mutex for child create/unlink ops */
1249 LASSERT(dentry->d_inode != NULL);
1250 LASSERT(TRYLOCK_INODE_MUTEX(dir) == 0);
1251 LASSERT(TRYLOCK_INODE_MUTEX(dentry->d_inode) == 0);
1255 if (/*!dentry->d_inode ||*/dentry->d_parent->d_inode != dir)
1256 GOTO(out, rc = -ENOENT);
1258 rc = ll_permission(dir, MAY_WRITE | MAY_EXEC, NULL);
1263 GOTO(out, rc = -EPERM);
1265 /* check_sticky() */
1266 if ((dentry->d_inode->i_uid != current->fsuid && !capable(CAP_FOWNER))||
1267 IS_APPEND(dentry->d_inode) || IS_IMMUTABLE(dentry->d_inode))
1268 GOTO(out, rc = -EPERM);
1270 /* NOTE: This might need to go outside i_mutex, though it isn't clear if
1271 * that was done because of journal_start (which is already done
1272 * here) or some other ordering issue. */
1275 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1276 rc = security_inode_unlink(dir, dentry);
1281 rc = dir->i_op->unlink(dir, dentry);
1283 /* need to drop i_mutex before we lose inode reference */
1284 UNLOCK_INODE_MUTEX(dentry->d_inode);
1291 /* Caller must hold LCK_PW on parent and push us into kernel context.
1292 * Caller must hold child i_mutex, we drop it always.
1293 * Caller is also required to ensure that dchild->d_inode exists. */
1294 static int filter_destroy_internal(struct obd_device *obd, obd_id objid,
1295 obd_gr group, struct dentry *dparent,
1296 struct dentry *dchild)
1298 struct inode *inode = dchild->d_inode;
1301 if (inode->i_nlink != 1 || atomic_read(&inode->i_count) != 1) {
1302 CERROR("destroying objid %.*s ino %lu nlink %lu count %d\n",
1303 dchild->d_name.len, dchild->d_name.name, inode->i_ino,
1304 (unsigned long)inode->i_nlink,
1305 atomic_read(&inode->i_count));
1308 rc = filter_vfs_unlink(dparent->d_inode, dchild);
1310 CERROR("error unlinking objid %.*s: rc %d\n",
1311 dchild->d_name.len, dchild->d_name.name, rc);
1315 static int filter_intent_policy(struct ldlm_namespace *ns,
1316 struct ldlm_lock **lockp, void *req_cookie,
1317 ldlm_mode_t mode, int flags, void *data)
1319 struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
1320 struct ptlrpc_request *req = req_cookie;
1321 struct ldlm_lock *lock = *lockp, *l = NULL;
1322 struct ldlm_resource *res = lock->l_resource;
1323 ldlm_processing_policy policy;
1324 struct ost_lvb *res_lvb, *reply_lvb;
1325 struct ldlm_reply *rep;
1326 struct list_head *tmp;
1328 int rc, tmpflags = 0, only_liblustre = 0;
1329 int repsize[3] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body),
1330 [DLM_LOCKREPLY_OFF] = sizeof(*rep),
1331 [DLM_REPLY_REC_OFF] = sizeof(*reply_lvb) };
1334 policy = ldlm_get_processing_policy(res);
1335 LASSERT(policy != NULL);
1336 LASSERT(req != NULL);
1338 rc = lustre_pack_reply(req, 3, repsize, NULL);
1340 RETURN(req->rq_status = rc);
1342 rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, sizeof(*rep));
1343 LASSERT(rep != NULL);
1345 reply_lvb = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF,
1346 sizeof(*reply_lvb));
1347 LASSERT(reply_lvb != NULL);
1349 //fixup_handle_for_resent_req(req, lock, &lockh);
1351 /* If we grant any lock at all, it will be a whole-file read lock.
1352 * Call the extent policy function to see if our request can be
1353 * granted, or is blocked. */
1354 lock->l_policy_data.l_extent.start = 0;
1355 lock->l_policy_data.l_extent.end = OBD_OBJECT_EOF;
1356 lock->l_req_mode = LCK_PR;
1358 LASSERT(ns == res->lr_namespace);
1360 rc = policy(lock, &tmpflags, 0, &err, &rpc_list);
1361 check_res_locked(res);
1363 /* FIXME: we should change the policy function slightly, to not make
1364 * this list at all, since we just turn around and free it */
1365 while (!list_empty(&rpc_list)) {
1366 struct ldlm_lock *wlock =
1367 list_entry(rpc_list.next, struct ldlm_lock, l_cp_ast);
1368 LASSERT((lock->l_flags & LDLM_FL_AST_SENT) == 0);
1369 LASSERT(lock->l_flags & LDLM_FL_CP_REQD);
1370 lock->l_flags &= ~LDLM_FL_CP_REQD;
1371 list_del_init(&wlock->l_cp_ast);
1372 LDLM_LOCK_PUT(wlock);
1375 /* The lock met with no resistance; we're finished. */
1376 if (rc == LDLM_ITER_CONTINUE) {
1377 /* do not grant locks to the liblustre clients: they cannot
1378 * handle ASTs robustly. We need to do this while still
1379 * holding ns_lock to avoid the lock remaining on the res_link
1380 * list (and potentially being added to l_pending_list by an
1381 * AST) when we are going to drop this lock ASAP. */
1382 if (lock->l_export->exp_libclient ||
1383 OBD_FAIL_CHECK(OBD_FAIL_LDLM_GLIMPSE)) {
1384 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_GLIMPSE, 2);
1385 ldlm_resource_unlink_lock(lock);
1386 err = ELDLM_LOCK_ABORTED;
1388 err = ELDLM_LOCK_REPLACED;
1394 /* Do not grant any lock, but instead send GL callbacks. The extent
1395 * policy nicely created a list of all PW locks for us. We will choose
1396 * the highest of those which are larger than the size in the LVB, if
1397 * any, and perform a glimpse callback. */
1398 res_lvb = res->lr_lvb_data;
1399 LASSERT(res_lvb != NULL);
1400 *reply_lvb = *res_lvb;
1402 list_for_each(tmp, &res->lr_granted) {
1403 struct ldlm_lock *tmplock =
1404 list_entry(tmp, struct ldlm_lock, l_res_link);
1406 if (tmplock->l_granted_mode == LCK_PR)
1409 * ->ns_lock guarantees that no new locks are granted, and,
1410 * therefore, that res->lr_lvb_data cannot increase beyond the
1411 * end of already granted lock. As a result, it is safe to
1412 * check against "stale" reply_lvb->lvb_size value without
1415 if (tmplock->l_policy_data.l_extent.end <= reply_lvb->lvb_size)
1418 /* Don't send glimpse ASTs to liblustre clients. They aren't
1419 * listening for them, and they do entirely synchronous I/O
1421 if (tmplock->l_export == NULL ||
1422 tmplock->l_export->exp_libclient == 1) {
1428 l = LDLM_LOCK_GET(tmplock);
1432 if (l->l_policy_data.l_extent.start >
1433 tmplock->l_policy_data.l_extent.start)
1437 l = LDLM_LOCK_GET(tmplock);
1441 /* There were no PW locks beyond the size in the LVB; finished. */
1443 if (only_liblustre) {
1444 /* If we discovered a liblustre client with a PW lock,
1445 * however, the LVB may be out of date! The LVB is
1446 * updated only on glimpse (which we don't do for
1447 * liblustre clients) and cancel (which the client
1448 * obviously has not yet done). So if it has written
1449 * data but kept the lock, the LVB is stale and needs
1450 * to be updated from disk.
1452 * Of course, this will all disappear when we switch to
1453 * taking liblustre locks on the OST. */
1454 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_update)
1455 ns->ns_lvbo->lvbo_update(res, NULL, 0, 1);
1457 RETURN(ELDLM_LOCK_ABORTED);
1461 * This check is for lock taken in filter_prepare_destroy() that does
1462 * not have l_glimpse_ast set. So the logic is: if there is a lock
1463 * with no l_glimpse_ast set, this object is being destroyed already.
1465 * Hence, if you are grabbing DLM locks on the server, always set
1466 * non-NULL glimpse_ast (e.g., ldlm_request.c:ldlm_glimpse_ast()).
1468 if (l->l_glimpse_ast == NULL) {
1469 /* We are racing with unlink(); just return -ENOENT */
1470 rep->lock_policy_res1 = -ENOENT;
1474 LASSERTF(l->l_glimpse_ast != NULL, "l == %p", l);
1475 rc = l->l_glimpse_ast(l, NULL); /* this will update the LVB */
1476 /* Update the LVB from disk if the AST failed (this is a legal race) */
1478 * XXX nikita: situation when ldlm_server_glimpse_ast() failed before
1479 * sending ast is not handled. This can result in lost client writes.
1481 if (rc != 0 && ns->ns_lvbo && ns->ns_lvbo->lvbo_update)
1482 ns->ns_lvbo->lvbo_update(res, NULL, 0, 1);
1485 *reply_lvb = *res_lvb;
1491 RETURN(ELDLM_LOCK_ABORTED);
1495 * per-obd_device iobuf pool.
1497 * To avoid memory deadlocks in low-memory setups, amount of dynamic
1498 * allocations in write-path has to be minimized (see bug 5137).
1500 * Pages, niobuf_local's and niobuf_remote's are pre-allocated and attached to
1501 * OST threads (see ost_thread_{init,done}()).
1503 * "iobuf's" used by filter cannot be attached to OST thread, however, because
1504 * at the OST layer there are only (potentially) multiple obd_device of type
1505 * unknown at the time of OST thread creation.
1507 * Instead array of iobuf's is attached to struct filter_obd (->fo_iobuf_pool
1508 * field). This array has size OST_MAX_THREADS, so that each OST thread uses
1509 * it's very own iobuf.
1513 * filter_kiobuf_pool_init()
1515 * filter_kiobuf_pool_done()
1517 * filter_iobuf_get()
1519 * operate on this array. They are "generic" in a sense that they don't depend
1520 * on actual type of iobuf's (the latter depending on Linux kernel version).
1524 * destroy pool created by filter_iobuf_pool_init
1526 static void filter_iobuf_pool_done(struct filter_obd *filter)
1528 struct filter_iobuf **pool;
1533 pool = filter->fo_iobuf_pool;
1535 for (i = 0; i < filter->fo_iobuf_count; ++ i) {
1536 if (pool[i] != NULL)
1537 filter_free_iobuf(pool[i]);
1539 OBD_FREE(pool, filter->fo_iobuf_count * sizeof pool[0]);
1540 filter->fo_iobuf_pool = NULL;
1546 * pre-allocate pool of iobuf's to be used by filter_{prep,commit}rw_write().
1548 static int filter_iobuf_pool_init(struct filter_obd *filter)
1554 OBD_ALLOC_GFP(filter->fo_iobuf_pool, OSS_THREADS_MAX * sizeof(*pool),
1556 if (filter->fo_iobuf_pool == NULL)
1559 filter->fo_iobuf_count = OSS_THREADS_MAX;
1564 /* Return iobuf allocated for @thread_id. We don't know in advance how
1565 * many threads there will be so we allocate a large empty array and only
1566 * fill in those slots that are actually in use.
1567 * If we haven't allocated a pool entry for this thread before, do so now. */
1568 void *filter_iobuf_get(struct filter_obd *filter, struct obd_trans_info *oti)
1570 int thread_id = oti ? oti->oti_thread_id : -1;
1571 struct filter_iobuf *pool = NULL;
1572 struct filter_iobuf **pool_place = NULL;
1574 if (thread_id >= 0) {
1575 LASSERT(thread_id < filter->fo_iobuf_count);
1576 pool = *(pool_place = &filter->fo_iobuf_pool[thread_id]);
1579 if (unlikely(pool == NULL)) {
1580 pool = filter_alloc_iobuf(filter, OBD_BRW_WRITE,
1581 PTLRPC_MAX_BRW_PAGES);
1582 if (pool_place != NULL)
1589 /* mount the file system (secretly). lustre_cfg parameters are:
1592 * 3 = flags: failover=f, failout=n
1595 int filter_common_setup(struct obd_device *obd, obd_count len, void *buf,
1598 struct lustre_cfg* lcfg = buf;
1599 struct filter_obd *filter = &obd->u.filter;
1600 struct vfsmount *mnt;
1601 struct lustre_mount_info *lmi;
1602 struct obd_uuid uuid;
1609 if (lcfg->lcfg_bufcount < 3 ||
1610 LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
1611 LUSTRE_CFG_BUFLEN(lcfg, 2) < 1)
1614 lmi = server_get_mount(obd->obd_name);
1616 /* We already mounted in lustre_fill_super.
1617 lcfg bufs 1, 2, 4 (device, fstype, mount opts) are ignored.*/
1618 struct lustre_sb_info *lsi = s2lsi(lmi->lmi_sb);
1620 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
1622 /* old path - used by lctl */
1623 CERROR("Using old MDS mount method\n");
1624 mnt = ll_kern_mount(lustre_cfg_string(lcfg, 2),
1625 MS_NOATIME|MS_NODIRATIME,
1626 lustre_cfg_string(lcfg, 1), option);
1629 LCONSOLE_ERROR("Can't mount disk %s (%d)\n",
1630 lustre_cfg_string(lcfg, 1), rc);
1634 obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2));
1636 if (IS_ERR(obd->obd_fsops))
1637 GOTO(err_mntput, rc = PTR_ERR(obd->obd_fsops));
1639 rc = filter_iobuf_pool_init(filter);
1643 LASSERT(!lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb)));
1645 /* failover is the default */
1646 obd->obd_replayable = 1;
1648 if (lcfg->lcfg_bufcount > 3 && LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
1649 str = lustre_cfg_string(lcfg, 3);
1650 if (strchr(str, 'n')) {
1651 CWARN("%s: recovery disabled\n", obd->obd_name);
1652 obd->obd_replayable = 0;
1656 filter->fo_vfsmnt = mnt;
1657 obd->u.obt.obt_sb = mnt->mnt_sb;
1658 filter->fo_fstype = mnt->mnt_sb->s_type->name;
1659 CDEBUG(D_SUPER, "%s: mnt = %p\n", filter->fo_fstype, mnt);
1661 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1662 obd->obd_lvfs_ctxt.pwdmnt = mnt;
1663 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
1664 obd->obd_lvfs_ctxt.fs = get_ds();
1665 obd->obd_lvfs_ctxt.cb_ops = filter_lvfs_ops;
1667 rc = filter_prep(obd);
1671 filter->fo_destroy_in_progress = 0;
1672 sema_init(&filter->fo_create_lock, 1);
1673 spin_lock_init(&filter->fo_translock);
1674 spin_lock_init(&filter->fo_objidlock);
1675 INIT_LIST_HEAD(&filter->fo_export_list);
1676 sema_init(&filter->fo_alloc_lock, 1);
1677 init_brw_stats(&filter->fo_filter_stats);
1678 filter->fo_readcache_max_filesize = FILTER_MAX_CACHE_SIZE;
1679 filter->fo_fmd_max_num = FILTER_FMD_MAX_NUM_DEFAULT;
1680 filter->fo_fmd_max_age = FILTER_FMD_MAX_AGE_DEFAULT;
1682 sprintf(ns_name, "filter-%s", obd->obd_uuid.uuid);
1683 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
1684 if (obd->obd_namespace == NULL)
1685 GOTO(err_post, rc = -ENOMEM);
1686 obd->obd_namespace->ns_lvbp = obd;
1687 obd->obd_namespace->ns_lvbo = &filter_lvbo;
1688 ldlm_register_intent(obd->obd_namespace, filter_intent_policy);
1690 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1691 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
1693 rc = llog_cat_initialize(obd, 1, NULL);
1695 CERROR("failed to setup llogging subsystems\n");
1699 rc = lquota_setup(filter_quota_interface_ref, obd);
1703 uuid_ptr = fsfilt_uuid(obd, obd->u.obt.obt_sb);
1704 if (uuid_ptr != NULL) {
1705 class_uuid_unparse(uuid_ptr, &uuid);
1711 label = fsfilt_get_label(obd, obd->u.obt.obt_sb);
1713 if (obd->obd_recovering) {
1714 LCONSOLE_WARN("OST %s now serving %s (%s%s%s), but will be in "
1715 "recovery until %d %s reconnect, or if no clients"
1716 " reconnect for %d:%.02d; during that time new "
1717 "clients will not be allowed to connect. "
1718 "Recovery progress can be monitored by watching "
1719 "/proc/fs/lustre/obdfilter/%s/recovery_status.\n",
1720 obd->obd_name, lustre_cfg_string(lcfg, 1),
1721 label ?: "", label ? "/" : "", str,
1722 obd->obd_recoverable_clients,
1723 (obd->obd_recoverable_clients == 1)
1724 ? "client" : "clients",
1725 (int)(OBD_RECOVERY_TIMEOUT) / 60,
1726 (int)(OBD_RECOVERY_TIMEOUT) % 60,
1729 LCONSOLE_INFO("OST %s now serving %s (%s%s%s) with recovery "
1730 "%s\n", obd->obd_name, lustre_cfg_string(lcfg, 1),
1731 label ?: "", label ? "/" : "", str,
1732 obd->obd_replayable ? "enabled" : "disabled");
1740 fsfilt_put_ops(obd->obd_fsops);
1741 filter_iobuf_pool_done(filter);
1743 server_put_mount(obd->obd_name, mnt);
1744 obd->u.obt.obt_sb = 0;
1748 static int filter_setup(struct obd_device *obd, obd_count len, void *buf)
1750 struct lprocfs_static_vars lvars;
1751 struct lustre_cfg* lcfg = buf;
1755 CLASSERT(offsetof(struct obd_device, u.obt) ==
1756 offsetof(struct obd_device, u.filter.fo_obt));
1758 if (!LUSTRE_CFG_BUFLEN(lcfg, 1) || !LUSTRE_CFG_BUFLEN(lcfg, 2))
1761 /* 2.6.9 selinux wants a full option page for do_kern_mount (bug6471) */
1762 page = get_zeroed_page(GFP_KERNEL);
1766 memcpy((void *)page, lustre_cfg_buf(lcfg, 4),
1767 LUSTRE_CFG_BUFLEN(lcfg, 4));
1768 rc = filter_common_setup(obd, len, buf, (void *)page);
1771 lprocfs_init_vars(filter, &lvars);
1772 if (rc == 0 && lprocfs_obd_setup(obd, lvars.obd_vars) == 0 &&
1773 lprocfs_alloc_obd_stats(obd, LPROC_FILTER_LAST) == 0) {
1774 /* Init obdfilter private stats here */
1775 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_READ_BYTES,
1776 LPROCFS_CNTR_AVGMINMAX,
1777 "read_bytes", "bytes");
1778 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_WRITE_BYTES,
1779 LPROCFS_CNTR_AVGMINMAX,
1780 "write_bytes", "bytes");
1781 lproc_filter_attach_seqstat(obd);
1782 obd->obd_proc_exports = proc_mkdir("exports",
1783 obd->obd_proc_entry);
1789 static struct llog_operations filter_mds_ost_repl_logops /* initialized below*/;
1790 static struct llog_operations filter_size_orig_logops = {
1791 lop_setup: llog_obd_origin_setup,
1792 lop_cleanup: llog_obd_origin_cleanup,
1793 lop_add: llog_obd_origin_add
1796 static int filter_llog_init(struct obd_device *obd, struct obd_device *tgt,
1797 int count, struct llog_catid *catid,
1798 struct obd_uuid *uuid)
1800 struct llog_ctxt *ctxt;
1804 filter_mds_ost_repl_logops = llog_client_ops;
1805 filter_mds_ost_repl_logops.lop_cancel = llog_obd_repl_cancel;
1806 filter_mds_ost_repl_logops.lop_connect = llog_repl_connect;
1807 filter_mds_ost_repl_logops.lop_sync = llog_obd_repl_sync;
1809 rc = llog_setup(obd, LLOG_MDS_OST_REPL_CTXT, tgt, 0, NULL,
1810 &filter_mds_ost_repl_logops);
1814 /* FIXME - assign unlink_cb for filter's recovery */
1815 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
1816 ctxt->llog_proc_cb = filter_recov_log_mds_ost_cb;
1818 rc = llog_setup(obd, LLOG_SIZE_ORIG_CTXT, tgt, 0, NULL,
1819 &filter_size_orig_logops);
1823 static int filter_llog_finish(struct obd_device *obd, int count)
1825 struct llog_ctxt *ctxt;
1826 int rc = 0, rc2 = 0;
1829 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
1831 rc = llog_cleanup(ctxt);
1833 ctxt = llog_get_context(obd, LLOG_SIZE_ORIG_CTXT);
1835 rc2 = llog_cleanup(ctxt);
1842 static int filter_precleanup(struct obd_device *obd,
1843 enum obd_cleanup_stage stage)
1849 case OBD_CLEANUP_EARLY:
1851 case OBD_CLEANUP_EXPORTS:
1852 target_cleanup_recovery(obd);
1854 case OBD_CLEANUP_SELF_EXP:
1855 rc = filter_llog_finish(obd, 0);
1857 case OBD_CLEANUP_OBD:
1863 static int filter_cleanup(struct obd_device *obd)
1865 struct filter_obd *filter = &obd->u.filter;
1869 LCONSOLE_WARN("%s: shutting down for failover; client state "
1870 "will be preserved.\n", obd->obd_name);
1872 if (!list_empty(&obd->obd_exports)) {
1873 CERROR("%s: still has clients!\n", obd->obd_name);
1874 class_disconnect_exports(obd);
1875 if (!list_empty(&obd->obd_exports)) {
1876 CERROR("still has exports after forced cleanup?\n");
1881 lprocfs_obd_cleanup(obd);
1882 lprocfs_free_obd_stats(obd);
1884 lquota_cleanup(filter_quota_interface_ref, obd);
1886 ldlm_namespace_free(obd->obd_namespace, obd->obd_force);
1888 if (obd->u.obt.obt_sb == NULL)
1893 shrink_dcache_parent(obd->u.obt.obt_sb->s_root);
1895 LL_DQUOT_OFF(obd->u.obt.obt_sb);
1897 server_put_mount(obd->obd_name, filter->fo_vfsmnt);
1898 obd->u.obt.obt_sb = NULL;
1900 fsfilt_put_ops(obd->obd_fsops);
1902 filter_iobuf_pool_done(filter);
1904 LCONSOLE_INFO("OST %s has stopped.\n", obd->obd_name);
1909 static int filter_connect_internal(struct obd_export *exp,
1910 struct obd_connect_data *data)
1915 CDEBUG(D_RPCTRACE, "%s: cli %s/%p ocd_connect_flags: "LPX64
1916 " ocd_version: %x ocd_grant: %d ocd_index: %u\n",
1917 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
1918 data->ocd_connect_flags, data->ocd_version,
1919 data->ocd_grant, data->ocd_index);
1921 data->ocd_connect_flags &= OST_CONNECT_SUPPORTED;
1922 exp->exp_connect_flags = data->ocd_connect_flags;
1923 data->ocd_version = LUSTRE_VERSION_CODE;
1925 if (exp->exp_connect_flags & OBD_CONNECT_GRANT) {
1926 obd_size left, want;
1928 spin_lock(&exp->exp_obd->obd_osfs_lock);
1929 left = filter_grant_space_left(exp);
1930 want = data->ocd_grant;
1931 data->ocd_grant = filter_grant(exp, 0, want, left);
1932 spin_unlock(&exp->exp_obd->obd_osfs_lock);
1934 CDEBUG(D_CACHE, "%s: cli %s/%p ocd_grant: %d want: "
1935 LPU64" left: "LPU64"\n", exp->exp_obd->obd_name,
1936 exp->exp_client_uuid.uuid, exp,
1937 data->ocd_grant, want, left);
1940 if (data->ocd_connect_flags & OBD_CONNECT_INDEX) {
1941 struct filter_obd *filter = &exp->exp_obd->u.filter;
1942 struct lr_server_data *lsd = filter->fo_fsd;
1943 int index = le32_to_cpu(lsd->lsd_ost_index);
1945 if (!(lsd->lsd_feature_compat &
1946 cpu_to_le32(OBD_COMPAT_OST))) {
1947 /* this will only happen on the first connect */
1948 lsd->lsd_ost_index = cpu_to_le32(data->ocd_index);
1949 lsd->lsd_feature_compat |= cpu_to_le32(OBD_COMPAT_OST);
1950 filter_update_server_data(exp->exp_obd,
1951 filter->fo_rcvd_filp, lsd, 1);
1952 } else if (index != data->ocd_index) {
1953 LCONSOLE_ERROR("Connection from %s to index %u doesn't "
1954 "match actual OST index %u in last_rcvd "
1955 "file, bad configuration?\n",
1956 obd_export_nid2str(exp), index,
1962 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_SIZE)) {
1963 data->ocd_brw_size = 65536;
1964 } else if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
1965 data->ocd_brw_size = min(data->ocd_brw_size,
1966 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
1967 LASSERT(data->ocd_brw_size);
1970 /* FIXME: Do the same with the MDS UUID and fsd_peeruuid.
1971 * FIXME: We don't strictly need the COMPAT flag for that,
1972 * FIXME: as fsd_peeruuid[0] will tell us if that is set.
1973 * FIXME: We needed it for the index, as index 0 is valid. */
1978 static int filter_reconnect(struct obd_export *exp, struct obd_device *obd,
1979 struct obd_uuid *cluuid,
1980 struct obd_connect_data *data)
1985 if (exp == NULL || obd == NULL || cluuid == NULL)
1988 rc = filter_connect_internal(exp, data);
1993 /* nearly identical to mds_connect */
1994 static int filter_connect(struct lustre_handle *conn, struct obd_device *obd,
1995 struct obd_uuid *cluuid,
1996 struct obd_connect_data *data)
1998 struct obd_export *exp;
1999 struct filter_export_data *fed;
2000 struct filter_client_data *fcd = NULL;
2004 if (conn == NULL || obd == NULL || cluuid == NULL)
2007 rc = class_connect(conn, obd, cluuid);
2010 exp = class_conn2export(conn);
2011 LASSERT(exp != NULL);
2013 fed = &exp->exp_filter_data;
2015 rc = filter_connect_internal(exp, data);
2019 if (!obd->obd_replayable)
2020 GOTO(cleanup, rc = 0);
2022 OBD_ALLOC(fcd, sizeof(*fcd));
2024 CERROR("filter: out of memory for client data\n");
2025 GOTO(cleanup, rc = -ENOMEM);
2028 memcpy(fcd->fcd_uuid, cluuid, sizeof(fcd->fcd_uuid));
2031 rc = filter_client_add(obd, exp, -1);
2038 OBD_FREE(fcd, sizeof(*fcd));
2039 fed->fed_fcd = NULL;
2041 class_disconnect(exp);
2043 class_export_put(exp);
2049 /* Do extra sanity checks for grant accounting. We do this at connect,
2050 * disconnect, and statfs RPC time, so it shouldn't be too bad. We can
2051 * always get rid of it or turn it off when we know accounting is good. */
2052 static void filter_grant_sanity_check(struct obd_device *obd, const char *func)
2054 struct filter_export_data *fed;
2055 struct obd_export *exp;
2056 obd_size maxsize = obd->obd_osfs.os_blocks * obd->obd_osfs.os_bsize;
2057 obd_size tot_dirty = 0, tot_pending = 0, tot_granted = 0;
2058 obd_size fo_tot_dirty, fo_tot_pending, fo_tot_granted;
2060 if (list_empty(&obd->obd_exports))
2063 spin_lock(&obd->obd_osfs_lock);
2064 spin_lock(&obd->obd_dev_lock);
2065 list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
2067 fed = &exp->exp_filter_data;
2068 if (fed->fed_grant < 0 || fed->fed_pending < 0 ||
2071 if (maxsize > 0) { /* we may not have done a statfs yet */
2072 LASSERTF(fed->fed_grant + fed->fed_pending <= maxsize,
2073 "%s: cli %s/%p %ld+%ld > "LPU64"\n", func,
2074 exp->exp_client_uuid.uuid, exp,
2075 fed->fed_grant, fed->fed_pending, maxsize);
2076 LASSERTF(fed->fed_dirty <= maxsize,
2077 "%s: cli %s/%p %ld > "LPU64"\n", func,
2078 exp->exp_client_uuid.uuid, exp,
2079 fed->fed_dirty, maxsize);
2082 CERROR("%s: cli %s/%p dirty %ld pend %ld grant %ld\n",
2083 obd->obd_name, exp->exp_client_uuid.uuid, exp,
2084 fed->fed_dirty, fed->fed_pending,fed->fed_grant);
2086 CDEBUG(D_CACHE, "%s: cli %s/%p dirty %ld pend %ld grant %ld\n",
2087 obd->obd_name, exp->exp_client_uuid.uuid, exp,
2088 fed->fed_dirty, fed->fed_pending,fed->fed_grant);
2089 tot_granted += fed->fed_grant + fed->fed_pending;
2090 tot_pending += fed->fed_pending;
2091 tot_dirty += fed->fed_dirty;
2093 fo_tot_granted = obd->u.filter.fo_tot_granted;
2094 fo_tot_pending = obd->u.filter.fo_tot_pending;
2095 fo_tot_dirty = obd->u.filter.fo_tot_dirty;
2096 spin_unlock(&obd->obd_dev_lock);
2097 spin_unlock(&obd->obd_osfs_lock);
2099 /* Do these assertions outside the spinlocks so we don't kill system */
2100 if (tot_granted != fo_tot_granted)
2101 CERROR("%s: tot_granted "LPU64" != fo_tot_granted "LPU64"\n",
2102 func, tot_granted, fo_tot_granted);
2103 if (tot_pending != fo_tot_pending)
2104 CERROR("%s: tot_pending "LPU64" != fo_tot_pending "LPU64"\n",
2105 func, tot_pending, fo_tot_pending);
2106 if (tot_dirty != fo_tot_dirty)
2107 CERROR("%s: tot_dirty "LPU64" != fo_tot_dirty "LPU64"\n",
2108 func, tot_dirty, fo_tot_dirty);
2109 if (tot_pending > tot_granted)
2110 CERROR("%s: tot_pending "LPU64" > tot_granted "LPU64"\n",
2111 func, tot_pending, tot_granted);
2112 if (tot_granted > maxsize)
2113 CERROR("%s: tot_granted "LPU64" > maxsize "LPU64"\n",
2114 func, tot_granted, maxsize);
2115 if (tot_dirty > maxsize)
2116 CERROR("%s: tot_dirty "LPU64" > maxsize "LPU64"\n",
2117 func, tot_dirty, maxsize);
2120 /* Remove this client from the grant accounting totals. We also remove
2121 * the export from the obd device under the osfs and dev locks to ensure
2122 * that the filter_grant_sanity_check() calculations are always valid.
2123 * The client should do something similar when it invalidates its import. */
2124 static void filter_grant_discard(struct obd_export *exp)
2126 struct obd_device *obd = exp->exp_obd;
2127 struct filter_obd *filter = &obd->u.filter;
2128 struct filter_export_data *fed = &exp->exp_filter_data;
2130 spin_lock(&obd->obd_osfs_lock);
2131 spin_lock(&obd->obd_dev_lock);
2132 list_del_init(&exp->exp_obd_chain);
2133 spin_unlock(&obd->obd_dev_lock);
2135 LASSERTF(filter->fo_tot_granted >= fed->fed_grant,
2136 "%s: tot_granted "LPU64" cli %s/%p fed_grant %ld\n",
2137 obd->obd_name, filter->fo_tot_granted,
2138 exp->exp_client_uuid.uuid, exp, fed->fed_grant);
2139 filter->fo_tot_granted -= fed->fed_grant;
2140 LASSERTF(filter->fo_tot_pending >= fed->fed_pending,
2141 "%s: tot_pending "LPU64" cli %s/%p fed_pending %ld\n",
2142 obd->obd_name, filter->fo_tot_pending,
2143 exp->exp_client_uuid.uuid, exp, fed->fed_pending);
2144 /* fo_tot_pending is handled in filter_grant_commit as bulk finishes */
2145 LASSERTF(filter->fo_tot_dirty >= fed->fed_dirty,
2146 "%s: tot_dirty "LPU64" cli %s/%p fed_dirty %ld\n",
2147 obd->obd_name, filter->fo_tot_dirty,
2148 exp->exp_client_uuid.uuid, exp, fed->fed_dirty);
2149 filter->fo_tot_dirty -= fed->fed_dirty;
2153 spin_unlock(&obd->obd_osfs_lock);
2156 static int filter_destroy_export(struct obd_export *exp)
2160 if (exp->exp_filter_data.fed_pending)
2161 CERROR("%s: cli %s/%p has %lu pending on destroyed export\n",
2162 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
2163 exp, exp->exp_filter_data.fed_pending);
2165 target_destroy_export(exp);
2167 if (obd_uuid_equals(&exp->exp_client_uuid, &exp->exp_obd->obd_uuid))
2170 if (exp->exp_obd->obd_replayable)
2171 filter_client_free(exp);
2173 fsfilt_sync(exp->exp_obd, exp->exp_obd->u.obt.obt_sb);
2175 filter_grant_discard(exp);
2176 filter_fmd_cleanup(exp);
2178 if (!(exp->exp_flags & OBD_OPT_FORCE))
2179 filter_grant_sanity_check(exp->exp_obd, __FUNCTION__);
2184 /* also incredibly similar to mds_disconnect */
2185 static int filter_disconnect(struct obd_export *exp)
2187 struct obd_device *obd = exp->exp_obd;
2188 struct llog_ctxt *ctxt;
2193 class_export_get(exp);
2195 if (!(exp->exp_flags & OBD_OPT_FORCE))
2196 filter_grant_sanity_check(obd, __FUNCTION__);
2197 filter_grant_discard(exp);
2199 /* Disconnect early so that clients can't keep using export */
2200 rc = class_disconnect(exp);
2201 if (exp->exp_obd->obd_namespace != NULL)
2202 ldlm_cancel_locks_for_export(exp);
2204 /* flush any remaining cancel messages out to the target */
2205 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
2206 err = llog_sync(ctxt, exp);
2208 CERROR("error flushing logs to MDS: rc %d\n", err);
2210 class_export_put(exp);
2214 static int filter_ping(struct obd_export *exp)
2216 filter_fmd_expire(exp);
2221 struct dentry *__filter_oa2dentry(struct obd_device *obd, struct obdo *oa,
2222 const char *what, int quiet)
2224 struct dentry *dchild = NULL;
2226 if (!(oa->o_valid & OBD_MD_FLGROUP))
2229 dchild = filter_fid2dentry(obd, NULL, oa->o_gr, oa->o_id);
2231 if (IS_ERR(dchild)) {
2232 CERROR("%s error looking up object: "LPU64"\n",
2237 if (dchild->d_inode == NULL) {
2239 CERROR("%s: %s on non-existent object: "LPU64"\n",
2240 obd->obd_name, what, oa->o_id);
2242 RETURN(ERR_PTR(-ENOENT));
2248 static int filter_getattr(struct obd_export *exp, struct obd_info *oinfo)
2250 struct dentry *dentry = NULL;
2251 struct obd_device *obd;
2255 obd = class_exp2obd(exp);
2257 CDEBUG(D_IOCTL, "invalid client export %p\n", exp);
2261 dentry = filter_oa2dentry(obd, oinfo->oi_oa);
2263 RETURN(PTR_ERR(dentry));
2265 /* Limit the valid bits in the return data to what we actually use */
2266 oinfo->oi_oa->o_valid = OBD_MD_FLID;
2267 obdo_from_inode(oinfo->oi_oa, dentry->d_inode, FILTER_VALID_FLAGS);
2273 /* this should be enabled/disabled in condition to enabled/disabled large
2274 * inodes (fast EAs) in backing store FS. */
2275 int filter_update_fidea(struct obd_export *exp, struct inode *inode,
2276 void *handle, struct obdo *oa)
2278 struct obd_device *obd = exp->exp_obd;
2282 if (oa->o_valid & OBD_MD_FLFID) {
2283 struct filter_fid ff;
2285 if (!(oa->o_valid & OBD_MD_FLGROUP))
2288 /* packing fid and converting it to LE for storing into EA.
2289 * Here ->o_stripe_idx should be filled by LOV and rest of
2290 * fields - by client. */
2291 ff.ff_fid.id = cpu_to_le64(oa->o_fid);
2292 ff.ff_fid.f_type = cpu_to_le32(oa->o_stripe_idx);
2293 ff.ff_fid.generation = cpu_to_le32(oa->o_generation);
2294 ff.ff_objid = cpu_to_le64(oa->o_id);
2295 ff.ff_group = cpu_to_le64(oa->o_gr);
2297 CDEBUG(D_INODE, "storing filter fid EA ("LPU64"/%u/%u"
2298 LPU64"/"LPU64")\n", oa->o_fid, oa->o_stripe_idx,
2299 oa->o_generation, oa->o_id, oa->o_gr);
2301 rc = fsfilt_set_md(obd, inode, handle, &ff, sizeof(ff), "fid");
2303 CERROR("store fid in object failed! rc: %d\n", rc);
2305 CDEBUG(D_HA, "OSS object without fid info!\n");
2311 /* this is called from filter_truncate() until we have filter_punch() */
2312 int filter_setattr_internal(struct obd_export *exp, struct dentry *dentry,
2313 struct obdo *oa, struct obd_trans_info *oti)
2315 unsigned int orig_ids[MAXQUOTAS] = {0, 0};
2316 struct llog_cookie *fcc = NULL;
2317 struct filter_obd *filter;
2318 int rc, err, locked = 0;
2319 unsigned int ia_valid;
2320 struct inode *inode;
2325 LASSERT(dentry != NULL);
2326 LASSERT(!IS_ERR(dentry));
2328 inode = dentry->d_inode;
2329 LASSERT(inode != NULL);
2331 filter = &exp->exp_obd->u.filter;
2332 iattr_from_obdo(&iattr, oa, oa->o_valid);
2333 ia_valid = iattr.ia_valid;
2335 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2336 OBD_ALLOC(fcc, sizeof(*fcc));
2338 memcpy(fcc, obdo_logcookie(oa), sizeof(*fcc));
2341 if (ia_valid & ATTR_SIZE || ia_valid & (ATTR_UID | ATTR_GID)) {
2343 LOCK_INODE_MUTEX(inode);
2347 /* If the inode still has SUID+SGID bits set (see filter_precreate())
2348 * then we will accept the UID+GID sent by the client during write for
2349 * initializing the ownership of this inode. We only allow this to
2350 * happen once so clear these bits in setattr. In 2.6 kernels it is
2351 * possible to get ATTR_UID and ATTR_GID separately, so we only clear
2352 * the flags that are actually being set. */
2353 if (ia_valid & (ATTR_UID | ATTR_GID)) {
2354 CDEBUG(D_INODE, "update UID/GID to %lu/%lu\n",
2355 (unsigned long)oa->o_uid, (unsigned long)oa->o_gid);
2357 if ((inode->i_mode & S_ISUID) && (ia_valid & ATTR_UID)) {
2358 if (!(ia_valid & ATTR_MODE)) {
2359 iattr.ia_mode = inode->i_mode;
2360 iattr.ia_valid |= ATTR_MODE;
2362 iattr.ia_mode &= ~S_ISUID;
2364 if ((inode->i_mode & S_ISGID) && (ia_valid & ATTR_GID)) {
2365 if (!(iattr.ia_valid & ATTR_MODE)) {
2366 iattr.ia_mode = inode->i_mode;
2367 iattr.ia_valid |= ATTR_MODE;
2369 iattr.ia_mode &= ~S_ISGID;
2372 orig_ids[USRQUOTA] = inode->i_uid;
2373 orig_ids[GRPQUOTA] = inode->i_gid;
2374 handle = fsfilt_start_log(exp->exp_obd, inode,
2375 FSFILT_OP_SETATTR, oti, 1);
2377 /* update inode EA only once when inode is suid bit marked. As
2378 * on 2.6.x UID and GID may be set separately, we check here
2379 * only one of them to avoid double setting. */
2380 if (inode->i_mode & S_ISUID)
2381 filter_update_fidea(exp, inode, handle, oa);
2383 handle = fsfilt_start(exp->exp_obd, inode,
2384 FSFILT_OP_SETATTR, oti);
2388 GOTO(out_unlock, rc = PTR_ERR(handle));
2390 if (oa->o_valid & OBD_MD_FLFLAGS) {
2391 rc = fsfilt_iocontrol(exp->exp_obd, inode, NULL,
2392 EXT3_IOC_SETFLAGS, (long)&oa->o_flags);
2394 rc = fsfilt_setattr(exp->exp_obd, dentry, handle, &iattr, 1);
2396 /* set cancel cookie callback function */
2397 if (fsfilt_add_journal_cb(exp->exp_obd, 0, handle,
2398 filter_cancel_cookies_cb,
2400 exp->exp_need_sync = 1;
2406 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_CREDITS))
2407 fsfilt_extend(exp->exp_obd, inode, 0, handle);
2409 /* The truncate might have used up our transaction credits. Make
2410 * sure we have one left for the last_rcvd update. */
2411 err = fsfilt_extend(exp->exp_obd, inode, 1, handle);
2412 rc = filter_finish_transno(exp, oti, rc);
2414 err = fsfilt_commit(exp->exp_obd, inode, handle, 0);
2416 CERROR("error on commit, err = %d\n", err);
2422 /* Let's flush truncated page on disk immediately, then we can
2423 * avoid need to search for page aliases before directio writes
2424 * and this sort of stuff at expense of somewhat slower
2425 * truncates not on a page boundary. I believe this is the only
2426 * place in filter code that can lead to pages getting to
2427 * pagecache so far. */
2428 filter_clear_truncated_page(inode);
2429 UNLOCK_INODE_MUTEX(inode);
2436 UNLOCK_INODE_MUTEX(inode);
2439 OBD_FREE(fcc, sizeof(*fcc));
2441 /* trigger quota release */
2442 if (ia_valid & (ATTR_SIZE | ATTR_UID | ATTR_GID)) {
2443 unsigned int cur_ids[MAXQUOTAS] = {oa->o_uid, oa->o_gid};
2444 int rc2 = lquota_adjust(filter_quota_interface_ref, exp->exp_obd, cur_ids,
2445 orig_ids, rc, FSFILT_OP_SETATTR);
2446 CDEBUG(rc2 ? D_ERROR : D_QUOTA,
2447 "filter adjust qunit. (rc:%d)\n", rc2);
2452 /* this is called from filter_truncate() until we have filter_punch() */
2453 int filter_setattr(struct obd_export *exp, struct obd_info *oinfo,
2454 struct obd_trans_info *oti)
2456 struct ldlm_res_id res_id = { .name = { oinfo->oi_oa->o_id } };
2457 struct ldlm_valblock_ops *ns_lvbo;
2458 struct filter_mod_data *fmd;
2459 struct lvfs_run_ctxt saved;
2460 struct filter_obd *filter;
2461 struct ldlm_resource *res;
2462 struct dentry *dentry;
2466 dentry = __filter_oa2dentry(exp->exp_obd, oinfo->oi_oa,
2469 RETURN(PTR_ERR(dentry));
2471 filter = &exp->exp_obd->u.filter;
2472 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2475 if (oinfo->oi_oa->o_valid &
2476 (OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME)) {
2477 fmd = filter_fmd_get(exp,oinfo->oi_oa->o_id,oinfo->oi_oa->o_gr);
2478 if (fmd && fmd->fmd_mactime_xid < oti->oti_xid)
2479 fmd->fmd_mactime_xid = oti->oti_xid;
2480 filter_fmd_put(exp, fmd);
2483 /* setting objects attributes (including owner/group) */
2484 rc = filter_setattr_internal(exp, dentry, oinfo->oi_oa, oti);
2486 GOTO(out_unlock, rc);
2488 res = ldlm_resource_get(exp->exp_obd->obd_namespace, NULL,
2489 res_id, LDLM_EXTENT, 0);
2492 ns_lvbo = res->lr_namespace->ns_lvbo;
2493 if (ns_lvbo && ns_lvbo->lvbo_update)
2494 rc = ns_lvbo->lvbo_update(res, NULL, 0, 0);
2495 ldlm_resource_putref(res);
2498 oinfo->oi_oa->o_valid = OBD_MD_FLID;
2500 /* Quota release need uid/gid info */
2501 obdo_from_inode(oinfo->oi_oa, dentry->d_inode,
2502 FILTER_VALID_FLAGS | OBD_MD_FLUID | OBD_MD_FLGID);
2508 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2512 /* XXX identical to osc_unpackmd */
2513 static int filter_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2514 struct lov_mds_md *lmm, int lmm_bytes)
2520 if (lmm_bytes < sizeof (*lmm)) {
2521 CERROR("lov_mds_md too small: %d, need %d\n",
2522 lmm_bytes, (int)sizeof(*lmm));
2525 /* XXX LOV_MAGIC etc check? */
2527 if (lmm->lmm_object_id == cpu_to_le64(0)) {
2528 CERROR("lov_mds_md: zero lmm_object_id\n");
2533 lsm_size = lov_stripe_md_size(1);
2537 if (*lsmp != NULL && lmm == NULL) {
2538 OBD_FREE((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
2539 OBD_FREE(*lsmp, lsm_size);
2544 if (*lsmp == NULL) {
2545 OBD_ALLOC(*lsmp, lsm_size);
2548 OBD_ALLOC((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
2549 if ((*lsmp)->lsm_oinfo[0] == NULL) {
2550 OBD_FREE(*lsmp, lsm_size);
2553 loi_init((*lsmp)->lsm_oinfo[0]);
2557 /* XXX zero *lsmp? */
2558 (*lsmp)->lsm_object_id = le64_to_cpu (lmm->lmm_object_id);
2559 LASSERT((*lsmp)->lsm_object_id);
2562 (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
2567 /* caller must hold fo_create_lock */
2568 static int filter_destroy_precreated(struct obd_export *exp, struct obdo *oa,
2569 struct filter_obd *filter)
2571 struct obdo doa; /* XXX obdo on stack */
2577 LASSERT(down_trylock(&filter->fo_create_lock) != 0);
2579 memset(&doa, 0, sizeof(doa));
2580 if (oa->o_valid & OBD_MD_FLGROUP) {
2581 doa.o_valid |= OBD_MD_FLGROUP;
2582 doa.o_gr = oa->o_gr;
2586 doa.o_mode = S_IFREG;
2588 if (!filter->fo_destroy_in_progress) {
2589 CERROR("%s: destroy_in_progress already cleared\n",
2590 exp->exp_obd->obd_name);
2594 last = filter_last_id(filter, doa.o_gr);
2595 CWARN("%s: deleting orphan objects from "LPU64" to "LPU64"\n",
2596 exp->exp_obd->obd_name, oa->o_id + 1, last);
2597 for (id = last; id > oa->o_id; id--) {
2599 rc = filter_destroy(exp, &doa, NULL, NULL, NULL);
2600 if (rc && rc != -ENOENT) /* this is pretty fatal... */
2601 CEMERG("error destroying precreate objid "LPU64": %d\n",
2603 filter_set_last_id(filter, id - 1, doa.o_gr);
2604 /* update last_id on disk periodically so that if we restart
2605 * we don't need to re-scan all of the just-deleted objects. */
2606 if ((id & 511) == 0)
2607 filter_update_last_objid(exp->exp_obd, doa.o_gr, 0);
2610 CDEBUG(D_HA, "%s: after destroy: set last_objids["LPU64"] = "LPU64"\n",
2611 exp->exp_obd->obd_name, doa.o_gr, oa->o_id);
2613 rc = filter_update_last_objid(exp->exp_obd, doa.o_gr, 1);
2614 filter->fo_destroy_in_progress = 0;
2619 static int filter_precreate(struct obd_device *obd, struct obdo *oa,
2620 obd_gr group, int *num);
2621 /* returns a negative error or a nonnegative number of files to create */
2622 static int filter_handle_precreate(struct obd_export *exp, struct obdo *oa,
2623 obd_gr group, struct obd_trans_info *oti)
2625 struct obd_device *obd = exp->exp_obd;
2626 struct filter_obd *filter = &obd->u.filter;
2630 /* delete orphans request */
2631 if ((oa->o_valid & OBD_MD_FLFLAGS) && (oa->o_flags & OBD_FL_DELORPHAN)){
2632 if (oti->oti_conn_cnt < exp->exp_conn_cnt) {
2633 CERROR("%s: dropping old orphan cleanup request\n",
2638 /* This causes inflight precreates to abort and drop lock */
2639 filter->fo_destroy_in_progress = 1;
2640 down(&filter->fo_create_lock);
2641 diff = oa->o_id - filter_last_id(filter, group);
2642 CDEBUG(D_HA, "filter_last_id() = "LPU64" -> diff = %d\n",
2643 filter_last_id(filter, group), diff);
2645 if (-diff > OST_MAX_PRECREATE) {
2646 CERROR("%s: ignoring bogus orphan destroy request: "
2647 "obdid "LPU64" last_id "LPU64"\n", obd->obd_name,
2648 oa->o_id, filter_last_id(filter, group));
2649 /* FIXME: should reset precreate_next_id on MDS */
2650 GOTO(out, rc = -EINVAL);
2653 rc = filter_destroy_precreated(exp, oa, filter);
2655 CERROR("%s: unable to write lastobjid, but "
2656 "orphans were deleted\n", obd->obd_name);
2659 /*XXX used by MDS for the first time! */
2660 filter->fo_destroy_in_progress = 0;
2663 down(&filter->fo_create_lock);
2664 if (oti->oti_conn_cnt < exp->exp_conn_cnt) {
2665 CERROR("%s: dropping old precreate request\n",
2669 /* only precreate if group == 0 and o_id is specfied */
2670 if (group != 0 || oa->o_id == 0)
2673 diff = oa->o_id - filter_last_id(filter, group);
2674 CDEBUG(D_HA, "filter_last_id() = "LPU64" -> diff = %d\n",
2675 filter_last_id(filter, group), diff);
2677 LASSERTF(diff >= 0,"%s: "LPU64" - "LPU64" = %d\n",obd->obd_name,
2678 oa->o_id, filter_last_id(filter, group), diff);
2682 oa->o_id = filter_last_id(&obd->u.filter, group);
2683 rc = filter_precreate(obd, oa, group, &diff);
2684 oa->o_id = filter_last_id(&obd->u.filter, group);
2685 oa->o_valid = OBD_MD_FLID;
2688 /* else diff == 0 */
2691 up(&filter->fo_create_lock);
2695 static int filter_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2698 struct filter_obd *filter = &obd->u.filter;
2699 int blockbits = obd->u.obt.obt_sb->s_blocksize_bits;
2703 /* at least try to account for cached pages. its still racey and
2704 * might be under-reporting if clients haven't announced their
2705 * caches with brw recently */
2706 spin_lock(&obd->obd_osfs_lock);
2707 rc = fsfilt_statfs(obd, obd->u.obt.obt_sb, max_age);
2708 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
2709 spin_unlock(&obd->obd_osfs_lock);
2711 CDEBUG(D_SUPER | D_CACHE, "blocks cached "LPU64" granted "LPU64
2712 " pending "LPU64" free "LPU64" avail "LPU64"\n",
2713 filter->fo_tot_dirty, filter->fo_tot_granted,
2714 filter->fo_tot_pending,
2715 osfs->os_bfree << blockbits, osfs->os_bavail << blockbits);
2717 filter_grant_sanity_check(obd, __FUNCTION__);
2719 osfs->os_bavail -= min(osfs->os_bavail, GRANT_FOR_LLOG(obd) +
2720 ((filter->fo_tot_dirty + filter->fo_tot_pending +
2721 osfs->os_bsize - 1) >> blockbits));
2723 /* set EROFS to state field if FS is mounted as RDONLY. The goal is to
2724 * stop creating files on MDS if OST is not good shape to create
2726 osfs->os_state = (filter->fo_obt.obt_sb->s_flags & MS_RDONLY) ?
2731 /* We rely on the fact that only one thread will be creating files in a given
2732 * group at a time, which is why we don't need an atomic filter_get_new_id.
2733 * Even if we had that atomic function, the following race would exist:
2735 * thread 1: gets id x from filter_next_id
2736 * thread 2: gets id (x + 1) from filter_next_id
2737 * thread 2: creates object (x + 1)
2738 * thread 1: tries to create object x, gets -ENOSPC
2740 * Caller must hold fo_create_lock
2742 static int filter_precreate(struct obd_device *obd, struct obdo *oa,
2743 obd_gr group, int *num)
2745 struct dentry *dchild = NULL, *dparent = NULL;
2746 struct filter_obd *filter;
2747 int err = 0, rc = 0, recreate_obj = 0, i;
2748 unsigned long enough_time = jiffies + min(obd_timeout * HZ / 4, 10U*HZ);
2750 void *handle = NULL;
2753 filter = &obd->u.filter;
2755 LASSERT(down_trylock(&filter->fo_create_lock) != 0);
2757 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2758 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2761 struct obd_statfs *osfs;
2763 OBD_ALLOC(osfs, sizeof(*osfs));
2766 rc = filter_statfs(obd, osfs, cfs_time_current_64() - HZ);
2767 if (rc == 0 && osfs->os_bavail < (osfs->os_blocks >> 10)) {
2768 CDEBUG(D_HA,"%s: not enough space for create "LPU64"\n",
2769 obd->obd_name, osfs->os_bavail <<
2770 filter->fo_vfsmnt->mnt_sb->s_blocksize_bits);
2774 OBD_FREE(osfs, sizeof(*osfs));
2779 CDEBUG(D_HA, "%s: precreating %d objects in group "LPU64" at "LPU64"\n",
2780 obd->obd_name, *num, group, oa->o_id);
2782 for (i = 0; i < *num && err == 0; i++) {
2783 int cleanup_phase = 0;
2785 if (filter->fo_destroy_in_progress) {
2786 CWARN("%s: precreate aborted by destroy\n",
2795 last_id = filter_last_id(filter, group);
2796 if (next_id > last_id) {
2797 CERROR("Error: Trying to recreate obj greater"
2798 "than last id "LPD64" > "LPD64"\n",
2800 GOTO(cleanup, rc = -EINVAL);
2803 next_id = filter_last_id(filter, group) + 1;
2805 CDEBUG(D_INFO, "precreate objid "LPU64"\n", next_id);
2807 dparent = filter_parent_lock(obd, group, next_id);
2808 if (IS_ERR(dparent))
2809 GOTO(cleanup, rc = PTR_ERR(dparent));
2812 dchild = filter_fid2dentry(obd, dparent, group, next_id);
2814 GOTO(cleanup, rc = PTR_ERR(dchild));
2817 if (dchild->d_inode != NULL) {
2818 /* This would only happen if lastobjid was bad on disk*/
2819 /* Could also happen if recreating missing obj but
2823 CERROR("%s: recreating existing object %.*s?\n",
2824 obd->obd_name, dchild->d_name.len,
2825 dchild->d_name.name);
2827 CERROR("%s: Serious error: objid %.*s already "
2828 "exists; is this filesystem corrupt?\n",
2829 obd->obd_name, dchild->d_name.len,
2830 dchild->d_name.name);
2833 GOTO(cleanup, rc = -EEXIST);
2836 handle = fsfilt_start_log(obd, dparent->d_inode,
2837 FSFILT_OP_CREATE, NULL, 1);
2839 GOTO(cleanup, rc = PTR_ERR(handle));
2842 /* We mark object SUID+SGID to flag it for accepting UID+GID
2843 * from client on first write. Currently the permission bits
2844 * on the OST are never used, so this is OK. */
2845 rc = ll_vfs_create(dparent->d_inode, dchild,
2846 S_IFREG | S_ISUID | S_ISGID | 0666, NULL);
2848 CERROR("create failed rc = %d\n", rc);
2852 if (!recreate_obj) {
2853 filter_set_last_id(filter, next_id, group);
2854 err = filter_update_last_objid(obd, group, 0);
2856 CERROR("unable to write lastobjid "
2857 "but file created\n");
2861 switch(cleanup_phase) {
2863 err = fsfilt_commit(obd, dparent->d_inode, handle, 0);
2865 CERROR("error on commit, err = %d\n", err);
2872 filter_parent_unlock(dparent);
2879 if (time_after(jiffies, enough_time)) {
2880 CDEBUG(D_HA, "%s: precreate slow - want %d got %d \n",
2881 obd->obd_name, *num, i);
2887 CDEBUG(D_HA, "%s: created %d objects for group "LPU64": "LPU64" rc %d\n",
2888 obd->obd_name, i, group, filter->fo_last_objids[group], rc);
2893 static int filter_create(struct obd_export *exp, struct obdo *oa,
2894 struct lov_stripe_md **ea, struct obd_trans_info *oti)
2896 struct obd_device *obd = NULL;
2897 struct lvfs_run_ctxt saved;
2898 struct lov_stripe_md *lsm = NULL;
2902 if (!(oa->o_valid & OBD_MD_FLGROUP))
2905 CDEBUG(D_INFO, "filter_create(od->o_gr="LPU64",od->o_id="LPU64")\n",
2906 oa->o_gr, oa->o_id);
2910 rc = obd_alloc_memmd(exp, &lsm);
2917 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2919 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2920 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2921 if (oa->o_id > filter_last_id(&obd->u.filter, oa->o_gr)) {
2922 CERROR("recreate objid "LPU64" > last id "LPU64"\n",
2923 oa->o_id, filter_last_id(&obd->u.filter,
2927 struct filter_obd *filter = &obd->u.filter;
2930 down(&filter->fo_create_lock);
2931 rc = filter_precreate(obd, oa, oa->o_gr, &diff);
2932 up(&filter->fo_create_lock);
2935 rc = filter_handle_precreate(exp, oa, oa->o_gr, oti);
2938 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2939 if (rc && ea != NULL && *ea != lsm) {
2940 obd_free_memmd(exp, &lsm);
2941 } else if (rc == 0 && ea != NULL) {
2942 /* XXX LOV STACKING: the lsm that is passed to us from
2943 * LOV does not have valid lsm_oinfo data structs, so
2944 * don't go touching that. This needs to be fixed in a
2946 lsm->lsm_object_id = oa->o_id;
2953 int filter_destroy(struct obd_export *exp, struct obdo *oa,
2954 struct lov_stripe_md *md, struct obd_trans_info *oti,
2955 struct obd_export *md_exp)
2957 unsigned int qcids[MAXQUOTAS] = {0, 0};
2958 struct obd_device *obd;
2959 struct filter_obd *filter;
2960 struct dentry *dchild = NULL, *dparent = NULL;
2961 struct lvfs_run_ctxt saved;
2962 void *handle = NULL;
2963 struct llog_cookie *fcc = NULL;
2964 int rc, rc2, cleanup_phase = 0;
2968 if (!(oa->o_valid & OBD_MD_FLGROUP))
2972 filter = &obd->u.filter;
2974 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2977 dchild = filter_fid2dentry(obd, NULL, oa->o_gr, oa->o_id);
2979 GOTO(cleanup, rc = PTR_ERR(dchild));
2982 if (dchild->d_inode == NULL) {
2983 CDEBUG(D_INODE, "destroying non-existent object "LPU64"\n",
2985 /* If object already gone, cancel cookie right now */
2986 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2987 fcc = obdo_logcookie(oa);
2988 llog_cancel(llog_get_context(obd, fcc->lgc_subsys + 1),
2990 fcc = NULL; /* we didn't allocate fcc, don't free it */
2992 GOTO(cleanup, rc = -ENOENT);
2995 filter_prepare_destroy(obd, oa->o_id);
2997 /* Our MDC connection is established by the MDS to us */
2998 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2999 OBD_ALLOC(fcc, sizeof(*fcc));
3001 memcpy(fcc, obdo_logcookie(oa), sizeof(*fcc));
3003 DQUOT_INIT(dchild->d_inode);
3005 /* we're gonna truncate it first in order to avoid possible deadlock:
3007 * open trasaction open transaction
3008 * down(i_zombie) down(i_zombie)
3009 * restart transaction
3010 * (see BUG 4180) -bzzz
3012 LOCK_INODE_MUTEX(dchild->d_inode);
3013 handle = fsfilt_start_log(obd, dchild->d_inode, FSFILT_OP_SETATTR,
3015 if (IS_ERR(handle)) {
3016 UNLOCK_INODE_MUTEX(dchild->d_inode);
3017 GOTO(cleanup, rc = PTR_ERR(handle));
3020 iattr.ia_valid = ATTR_SIZE;
3022 rc = fsfilt_setattr(obd, dchild, handle, &iattr, 1);
3023 rc2 = fsfilt_commit(obd, dchild->d_inode, handle, 0);
3024 UNLOCK_INODE_MUTEX(dchild->d_inode);
3028 GOTO(cleanup, rc = rc2);
3030 /* We don't actually need to lock the parent until we are unlinking
3031 * here, and not while truncating above. That avoids holding the
3032 * parent lock for a long time during truncate, which can block other
3033 * threads from doing anything to objects in that directory. bug 7171 */
3034 dparent = filter_parent_lock(obd, oa->o_gr, oa->o_id);
3035 if (IS_ERR(dparent))
3036 GOTO(cleanup, rc = PTR_ERR(dparent));
3037 cleanup_phase = 3; /* filter_parent_unlock */
3039 LOCK_INODE_MUTEX(dchild->d_inode);
3040 handle = fsfilt_start_log(obd, dparent->d_inode,FSFILT_OP_UNLINK,oti,1);
3041 if (IS_ERR(handle)) {
3042 UNLOCK_INODE_MUTEX(dchild->d_inode);
3043 GOTO(cleanup, rc = PTR_ERR(handle));
3045 cleanup_phase = 4; /* fsfilt_commit */
3047 /* Quota release need uid/gid of inode */
3048 obdo_from_inode(oa, dchild->d_inode, OBD_MD_FLUID|OBD_MD_FLGID);
3050 filter_fmd_drop(exp, oa->o_id, oa->o_gr);
3052 /* this drops dchild->d_inode->i_mutex unconditionally */
3053 rc = filter_destroy_internal(obd, oa->o_id, oa->o_gr, dparent, dchild);
3057 switch(cleanup_phase) {
3060 if (fsfilt_add_journal_cb(obd, 0, oti ?
3061 oti->oti_handle : handle,
3062 filter_cancel_cookies_cb,
3066 rc = filter_finish_transno(exp, oti, rc);
3067 rc2 = fsfilt_commit(obd, dparent->d_inode, handle, 0);
3069 CERROR("error on commit, err = %d\n", rc2);
3074 filter_parent_unlock(dparent);
3078 OBD_FREE(fcc, sizeof(*fcc));
3080 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3083 CERROR("invalid cleanup_phase %d\n", cleanup_phase);
3087 /* trigger quota release */
3088 qcids[USRQUOTA] = oa->o_uid;
3089 qcids[GRPQUOTA] = oa->o_gid;
3090 rc2 = lquota_adjust(filter_quota_interface_ref, obd, qcids, NULL, rc,
3092 CDEBUG(rc2 ? D_ERROR : D_QUOTA,
3093 "filter adjust qunit! (rc:%d)\n", rc2);
3097 /* NB start and end are used for punch, but not truncate */
3098 static int filter_truncate(struct obd_export *exp, struct obd_info *oinfo,
3099 struct obd_trans_info *oti,
3100 struct ptlrpc_request_set *rqset)
3105 if (oinfo->oi_policy.l_extent.end != OBD_OBJECT_EOF) {
3106 CERROR("PUNCH not supported, only truncate: end = "LPX64"\n",
3107 oinfo->oi_policy.l_extent.end);
3111 CDEBUG(D_INODE, "calling truncate for object "LPU64", valid = "LPX64
3112 ", o_size = "LPD64"\n", oinfo->oi_oa->o_id,
3113 oinfo->oi_oa->o_valid, oinfo->oi_policy.l_extent.start);
3115 oinfo->oi_oa->o_size = oinfo->oi_policy.l_extent.start;
3116 rc = filter_setattr(exp, oinfo, oti);
3120 static int filter_sync(struct obd_export *exp, struct obdo *oa,
3121 struct lov_stripe_md *lsm, obd_off start, obd_off end)
3123 struct lvfs_run_ctxt saved;
3124 struct filter_obd *filter;
3125 struct dentry *dentry;
3126 struct llog_ctxt *ctxt;
3130 filter = &exp->exp_obd->u.filter;
3132 /* an objid of zero is taken to mean "sync whole filesystem" */
3133 if (!oa || !(oa->o_valid & OBD_MD_FLID)) {
3134 rc = fsfilt_sync(exp->exp_obd, filter->fo_obt.obt_sb);
3135 /* flush any remaining cancel messages out to the target */
3136 ctxt = llog_get_context(exp->exp_obd, LLOG_MDS_OST_REPL_CTXT);
3137 llog_sync(ctxt, exp);
3141 dentry = filter_oa2dentry(exp->exp_obd, oa);
3143 RETURN(PTR_ERR(dentry));
3145 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
3147 LOCK_INODE_MUTEX(dentry->d_inode);
3149 rc = filemap_fdatawrite(dentry->d_inode->i_mapping);
3151 /* just any file to grab fsync method - "file" arg unused */
3152 struct file *file = filter->fo_rcvd_filp;
3154 if (file->f_op && file->f_op->fsync)
3155 rc = file->f_op->fsync(NULL, dentry, 1);
3157 rc2 = filemap_fdatawait(dentry->d_inode->i_mapping);
3161 UNLOCK_INODE_MUTEX(dentry->d_inode);
3163 oa->o_valid = OBD_MD_FLID;
3164 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
3166 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
3172 static int filter_get_info(struct obd_export *exp, __u32 keylen,
3173 void *key, __u32 *vallen, void *val)
3175 struct obd_device *obd;
3178 obd = class_exp2obd(exp);
3180 CDEBUG(D_IOCTL, "invalid client export %p\n", exp);
3184 if (keylen == strlen("blocksize") &&
3185 memcmp(key, "blocksize", keylen) == 0) {
3186 __u32 *blocksize = val;
3187 *vallen = sizeof(*blocksize);
3188 *blocksize = obd->u.obt.obt_sb->s_blocksize;
3192 if (keylen == strlen("blocksize_bits") &&
3193 memcmp(key, "blocksize_bits", keylen) == 0) {
3194 __u32 *blocksize_bits = val;
3195 *vallen = sizeof(*blocksize_bits);
3196 *blocksize_bits = obd->u.obt.obt_sb->s_blocksize_bits;
3200 if (keylen >= strlen("last_id") && memcmp(key, "last_id", 7) == 0) {
3201 obd_id *last_id = val;
3202 /* FIXME: object groups */
3203 *last_id = filter_last_id(&obd->u.filter, 0);
3206 CDEBUG(D_IOCTL, "invalid key\n");
3210 static int filter_set_info_async(struct obd_export *exp, __u32 keylen,
3211 void *key, __u32 vallen, void *val,
3212 struct ptlrpc_request_set *set)
3214 struct obd_device *obd;
3215 struct llog_ctxt *ctxt;
3221 CDEBUG(D_IOCTL, "invalid export %p\n", exp);
3225 if (keylen < strlen(KEY_MDS_CONN) ||
3226 memcmp(key, KEY_MDS_CONN, keylen) != 0)
3229 LCONSOLE_WARN("%s: received MDS connection from %s\n", obd->obd_name,
3230 obd_export_nid2str(exp));
3231 obd->u.filter.fo_mdc_conn.cookie = exp->exp_handle.h_cookie;
3233 /* setup llog imports */
3234 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
3235 rc = llog_receptor_accept(ctxt, exp->exp_imp_reverse);
3237 lquota_setinfo(filter_quota_interface_ref, exp, obd);
3242 int filter_iocontrol(unsigned int cmd, struct obd_export *exp,
3243 int len, void *karg, void *uarg)
3245 struct obd_device *obd = exp->exp_obd;
3246 struct obd_ioctl_data *data = karg;
3250 case OBD_IOC_ABORT_RECOVERY: {
3251 CERROR("aborting recovery for device %s\n", obd->obd_name);
3252 target_abort_recovery(obd);
3256 case OBD_IOC_SYNC: {
3257 CDEBUG(D_HA, "syncing ost %s\n", obd->obd_name);
3258 rc = fsfilt_sync(obd, obd->u.obt.obt_sb);
3262 case OBD_IOC_SET_READONLY: {
3264 struct super_block *sb = obd->u.obt.obt_sb;
3265 struct inode *inode = sb->s_root->d_inode;
3266 BDEVNAME_DECLARE_STORAGE(tmp);
3267 CERROR("*** setting device %s read-only ***\n",
3268 ll_bdevname(sb, tmp));
3270 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
3271 if (!IS_ERR(handle))
3272 rc = fsfilt_commit(obd, inode, handle, 1);
3274 CDEBUG(D_HA, "syncing ost %s\n", obd->obd_name);
3275 rc = fsfilt_sync(obd, obd->u.obt.obt_sb);
3277 lvfs_set_rdonly(obd, obd->u.obt.obt_sb);
3281 case OBD_IOC_CATLOGLIST: {
3282 rc = llog_catalog_list(obd, 1, data);
3286 case OBD_IOC_LLOG_CANCEL:
3287 case OBD_IOC_LLOG_REMOVE:
3288 case OBD_IOC_LLOG_INFO:
3289 case OBD_IOC_LLOG_PRINT: {
3290 /* FIXME to be finished */
3291 RETURN(-EOPNOTSUPP);
3293 struct llog_ctxt *ctxt = NULL;
3295 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
3296 rc = llog_ioctl(ctxt, cmd, data);
3297 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
3310 static int filter_health_check(struct obd_device *obd)
3312 struct filter_obd *filter = &obd->u.filter;
3316 * health_check to return 0 on healthy
3317 * and 1 on unhealthy.
3319 if (obd->u.obt.obt_sb->s_flags & MS_RDONLY)
3322 LASSERT(filter->fo_health_check_filp != NULL);
3323 rc |= !!lvfs_check_io_health(obd, filter->fo_health_check_filp);
3328 static struct dentry *filter_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
3331 return filter_fid2dentry(data, NULL, gr, id);
3334 static int filter_process_config(struct obd_device *obd, obd_count len, void *buf)
3336 struct lustre_cfg *lcfg = buf;
3337 struct lprocfs_static_vars lvars;
3340 lprocfs_init_vars(filter, &lvars);
3342 rc = class_process_proc_param(PARAM_OST, lvars.obd_vars, lcfg, obd);
3347 static struct lvfs_callback_ops filter_lvfs_ops = {
3348 l_fid2dentry: filter_lvfs_fid2dentry,
3351 static struct obd_ops filter_obd_ops = {
3352 .o_owner = THIS_MODULE,
3353 .o_get_info = filter_get_info,
3354 .o_set_info_async = filter_set_info_async,
3355 .o_setup = filter_setup,
3356 .o_precleanup = filter_precleanup,
3357 .o_cleanup = filter_cleanup,
3358 .o_connect = filter_connect,
3359 .o_reconnect = filter_reconnect,
3360 .o_disconnect = filter_disconnect,
3361 .o_ping = filter_ping,
3362 .o_init_export = filter_init_export,
3363 .o_destroy_export = filter_destroy_export,
3364 .o_statfs = filter_statfs,
3365 .o_getattr = filter_getattr,
3366 .o_unpackmd = filter_unpackmd,
3367 .o_create = filter_create,
3368 .o_setattr = filter_setattr,
3369 .o_destroy = filter_destroy,
3370 .o_brw = filter_brw,
3371 .o_punch = filter_truncate,
3372 .o_sync = filter_sync,
3373 .o_preprw = filter_preprw,
3374 .o_commitrw = filter_commitrw,
3375 .o_llog_init = filter_llog_init,
3376 .o_llog_finish = filter_llog_finish,
3377 .o_iocontrol = filter_iocontrol,
3378 .o_health_check = filter_health_check,
3379 .o_process_config = filter_process_config,
3382 quota_interface_t *filter_quota_interface_ref;
3383 extern quota_interface_t filter_quota_interface;
3385 static int __init obdfilter_init(void)
3387 struct lprocfs_static_vars lvars;
3390 printk(KERN_INFO "Lustre: Filtering OBD driver; info@clusterfs.com\n");
3392 lprocfs_init_vars(filter, &lvars);
3394 request_module("lquota");
3395 OBD_ALLOC(obdfilter_created_scratchpad,
3396 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
3397 sizeof(*obdfilter_created_scratchpad));
3398 if (obdfilter_created_scratchpad == NULL)
3401 ll_fmd_cachep = kmem_cache_create("ll_fmd_cache",
3402 sizeof(struct filter_mod_data),
3405 GOTO(out, rc = -ENOMEM);
3407 filter_quota_interface_ref = PORTAL_SYMBOL_GET(filter_quota_interface);
3408 init_obd_quota_ops(filter_quota_interface_ref, &filter_obd_ops);
3410 rc = class_register_type(&filter_obd_ops, lvars.module_vars,
3415 err = kmem_cache_destroy(ll_fmd_cachep);
3416 LASSERTF(err == 0, "Cannot destroy ll_fmd_cachep: rc %d\n",err);
3417 ll_fmd_cachep = NULL;
3419 if (filter_quota_interface_ref)
3420 PORTAL_SYMBOL_PUT(filter_quota_interface);
3422 OBD_FREE(obdfilter_created_scratchpad,
3423 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
3424 sizeof(*obdfilter_created_scratchpad));
3430 static void __exit obdfilter_exit(void)
3432 if (filter_quota_interface_ref)
3433 PORTAL_SYMBOL_PUT(filter_quota_interface);
3435 if (ll_fmd_cachep) {
3436 int rc = kmem_cache_destroy(ll_fmd_cachep);
3437 LASSERTF(rc == 0, "Cannot destroy ll_fmd_cachep: rc %d\n", rc);
3438 ll_fmd_cachep = NULL;
3441 class_unregister_type(LUSTRE_OST_NAME);
3442 OBD_FREE(obdfilter_created_scratchpad,
3443 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
3444 sizeof(*obdfilter_created_scratchpad));
3447 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
3448 MODULE_DESCRIPTION("Lustre Filtering OBD driver");
3449 MODULE_LICENSE("GPL");
3451 module_init(obdfilter_init);
3452 module_exit(obdfilter_exit);