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 <lustre_ver.h>
61 #include <linux/slab.h>
62 #include <lustre_param.h>
64 #include "filter_internal.h"
66 static struct lvfs_callback_ops filter_lvfs_ops;
67 kmem_cache_t *ll_fmd_cachep;
69 static void filter_commit_cb(struct obd_device *obd, __u64 transno,
70 void *cb_data, int error)
72 obd_transno_commit_cb(obd, transno, error);
75 /* Assumes caller has already pushed us into the kernel context. */
76 int filter_finish_transno(struct obd_export *exp, struct obd_trans_info *oti,
79 struct filter_obd *filter = &exp->exp_obd->u.filter;
80 struct filter_export_data *fed = &exp->exp_filter_data;
81 struct filter_client_data *fcd = fed->fed_fcd;
84 int err, log_pri = D_HA;
86 /* Propagate error code. */
90 if (!exp->exp_obd->obd_replayable || oti == NULL)
93 /* we don't allocate new transnos for replayed requests */
94 if (oti->oti_transno == 0) {
95 spin_lock(&filter->fo_translock);
96 last_rcvd = le64_to_cpu(filter->fo_fsd->lsd_last_transno) + 1;
97 filter->fo_fsd->lsd_last_transno = cpu_to_le64(last_rcvd);
98 spin_unlock(&filter->fo_translock);
99 oti->oti_transno = last_rcvd;
101 spin_lock(&filter->fo_translock);
102 last_rcvd = oti->oti_transno;
103 if (last_rcvd > le64_to_cpu(filter->fo_fsd->lsd_last_transno))
104 filter->fo_fsd->lsd_last_transno =
105 cpu_to_le64(last_rcvd);
106 spin_unlock(&filter->fo_translock);
108 fcd->fcd_last_rcvd = cpu_to_le64(last_rcvd);
110 /* could get xid from oti, if it's ever needed */
111 fcd->fcd_last_xid = 0;
113 off = fed->fed_lr_off;
115 CERROR("%s: client idx %d is %lld\n", exp->exp_obd->obd_name,
116 fed->fed_lr_idx, fed->fed_lr_off);
119 fsfilt_add_journal_cb(exp->exp_obd, last_rcvd, oti->oti_handle,
120 filter_commit_cb, NULL);
121 err = fsfilt_write_record(exp->exp_obd, filter->fo_rcvd_filp,
122 fcd, sizeof(*fcd), &off, 0);
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 /* Add client data to the FILTER. We use a bitmap to locate a free space
147 * in the last_rcvd file if cl_idx is -1 (i.e. a new client).
148 * Otherwise, we have just read the data from the last_rcvd file and
149 * we know its offset. */
150 static int filter_client_add(struct obd_device *obd, struct filter_obd *filter,
151 struct filter_export_data *fed, int cl_idx)
153 unsigned long *bitmap = filter->fo_last_rcvd_slots;
154 int new_client = (cl_idx == -1);
157 LASSERT(bitmap != NULL);
158 LASSERTF(cl_idx > -2, "%d\n", cl_idx);
160 /* XXX if fcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
161 if (!strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid))
164 /* the bitmap operations can handle cl_idx > sizeof(long) * 8, so
165 * there's no need for extra complication here
168 cl_idx = find_first_zero_bit(bitmap, LR_MAX_CLIENTS);
170 if (cl_idx >= LR_MAX_CLIENTS) {
171 CERROR("no client slots - fix LR_MAX_CLIENTS\n");
174 if (test_and_set_bit(cl_idx, bitmap)) {
175 cl_idx = find_next_zero_bit(bitmap, LR_MAX_CLIENTS,
180 if (test_and_set_bit(cl_idx, bitmap)) {
181 CERROR("FILTER client %d: bit already set in bitmap!\n",
187 fed->fed_lr_idx = cl_idx;
188 fed->fed_lr_off = le32_to_cpu(filter->fo_fsd->lsd_client_start) +
189 cl_idx * le16_to_cpu(filter->fo_fsd->lsd_client_size);
190 LASSERTF(fed->fed_lr_off > 0, "fed_lr_off = %llu\n", fed->fed_lr_off);
192 CDEBUG(D_INFO, "client at index %d (%llu) with UUID '%s' added\n",
193 fed->fed_lr_idx, fed->fed_lr_off, fed->fed_fcd->fcd_uuid);
196 struct lvfs_run_ctxt saved;
197 loff_t off = fed->fed_lr_off;
201 CDEBUG(D_INFO, "writing client fcd at idx %u (%llu) (len %u)\n",
202 fed->fed_lr_idx,off,(unsigned int)sizeof(*fed->fed_fcd));
204 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
205 /* Transaction needed to fix bug 1403 */
206 handle = fsfilt_start(obd,
207 filter->fo_rcvd_filp->f_dentry->d_inode,
208 FSFILT_OP_SETATTR, NULL);
209 if (IS_ERR(handle)) {
210 err = PTR_ERR(handle);
211 CERROR("unable to start transaction: rc %d\n", err);
213 err = fsfilt_write_record(obd, filter->fo_rcvd_filp,
215 sizeof(*fed->fed_fcd),
218 filter->fo_rcvd_filp->f_dentry->d_inode,
221 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
224 CERROR("error writing %s client idx %u: rc %d\n",
225 LAST_RCVD, fed->fed_lr_idx, err);
232 static int filter_client_free(struct obd_export *exp)
234 struct filter_export_data *fed = &exp->exp_filter_data;
235 struct filter_obd *filter = &exp->exp_obd->u.filter;
236 struct obd_device *obd = exp->exp_obd;
237 struct filter_client_data zero_fcd;
238 struct lvfs_run_ctxt saved;
243 if (fed->fed_fcd == NULL)
246 /* XXX if fcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
247 if (strcmp(fed->fed_fcd->fcd_uuid, obd->obd_uuid.uuid ) == 0)
250 CDEBUG(D_INFO, "freeing client at idx %u, offset %lld with UUID '%s'\n",
251 fed->fed_lr_idx, off, fed->fed_fcd->fcd_uuid);
253 LASSERT(filter->fo_last_rcvd_slots != NULL);
255 off = fed->fed_lr_off;
257 /* Don't clear fed_lr_idx here as it is likely also unset. At worst
258 * we leak a client slot that will be cleaned on the next recovery. */
260 CERROR("%s: client idx %d has med_off %lld\n",
261 obd->obd_name, fed->fed_lr_idx, off);
262 GOTO(free, rc = -EINVAL);
265 /* Clear the bit _after_ zeroing out the client so we don't
266 race with filter_client_add and zero out new clients.*/
267 if (!test_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
268 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
273 if (!(exp->exp_flags & OBD_OPT_FAILOVER)) {
274 memset(&zero_fcd, 0, sizeof zero_fcd);
275 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
276 rc = fsfilt_write_record(obd, filter->fo_rcvd_filp, &zero_fcd,
277 sizeof(zero_fcd), &off, 0);
280 /* update server's transno */
281 filter_update_server_data(obd, filter->fo_rcvd_filp,
283 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
285 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
286 "zeroing out client %s at idx %u (%llu) in %s rc %d\n",
287 fed->fed_fcd->fcd_uuid, fed->fed_lr_idx, fed->fed_lr_off,
291 if (!test_and_clear_bit(fed->fed_lr_idx, filter->fo_last_rcvd_slots)) {
292 CERROR("FILTER client %u: bit already clear in bitmap!!\n",
299 OBD_FREE(fed->fed_fcd, sizeof(*fed->fed_fcd));
305 /* drop fmd reference, free it if last ref. must be called with fed_lock held.*/
306 static inline void filter_fmd_put_nolock(struct filter_export_data *fed,
307 struct filter_mod_data *fmd)
309 LASSERT_SPIN_LOCKED(&fed->fed_lock);
310 if (--fmd->fmd_refcount == 0) {
311 /* XXX when we have persistent reservations and the handle
312 * is stored herein we need to drop it here. */
313 fed->fed_mod_count--;
314 list_del(&fmd->fmd_list);
315 OBD_SLAB_FREE(fmd, ll_fmd_cachep, sizeof(*fmd));
319 /* drop fmd reference, free it if last ref */
320 void filter_fmd_put(struct obd_export *exp, struct filter_mod_data *fmd)
322 struct filter_export_data *fed;
327 fed = &exp->exp_filter_data;
328 spin_lock(&fed->fed_lock);
329 filter_fmd_put_nolock(fed, fmd); /* caller reference */
330 spin_unlock(&fed->fed_lock);
333 /* expire entries from the end of the list if there are too many
334 * or they are too old */
335 static void filter_fmd_expire_nolock(struct filter_obd *filter,
336 struct filter_export_data *fed,
337 struct filter_mod_data *keep)
339 struct filter_mod_data *fmd, *tmp;
341 list_for_each_entry_safe(fmd, tmp, &fed->fed_mod_list, fmd_list) {
345 if (time_before(jiffies, fmd->fmd_expire) &&
346 fed->fed_mod_count < filter->fo_fmd_max_num)
349 list_del_init(&fmd->fmd_list);
350 filter_fmd_put_nolock(fed, fmd); /* list reference */
354 void filter_fmd_expire(struct obd_export *exp)
356 spin_lock(&exp->exp_filter_data.fed_lock);
357 filter_fmd_expire_nolock(&exp->exp_obd->u.filter,
358 &exp->exp_filter_data, NULL);
359 spin_unlock(&exp->exp_filter_data.fed_lock);
362 /* find specified objid, group in export fmd list.
363 * caller must hold fed_lock and take fmd reference itself */
364 static struct filter_mod_data *filter_fmd_find_nolock(struct filter_obd *filter,
365 struct filter_export_data *fed,
366 obd_id objid, obd_gr group)
368 struct filter_mod_data *found = NULL, *fmd;
370 LASSERT_SPIN_LOCKED(&fed->fed_lock);
372 list_for_each_entry_reverse(fmd, &fed->fed_mod_list, fmd_list) {
373 if (fmd->fmd_id == objid && fmd->fmd_gr == group) {
375 list_del(&fmd->fmd_list);
376 list_add_tail(&fmd->fmd_list, &fed->fed_mod_list);
377 fmd->fmd_expire = jiffies + filter->fo_fmd_max_age;
382 filter_fmd_expire_nolock(filter, fed, found);
387 /* Find fmd based on objid and group, or return NULL if not found. */
388 struct filter_mod_data *filter_fmd_find(struct obd_export *exp,
389 obd_id objid, obd_gr group)
391 struct filter_mod_data *fmd;
393 spin_lock(&exp->exp_filter_data.fed_lock);
394 fmd = filter_fmd_find_nolock(&exp->exp_obd->u.filter,
395 &exp->exp_filter_data, objid, group);
397 fmd->fmd_refcount++; /* caller reference */
398 spin_unlock(&exp->exp_filter_data.fed_lock);
403 /* Find fmd based on objid and group, or create a new one if none is found.
404 * It is possible for this function to return NULL under memory pressure,
405 * or if objid = 0 is passed (which will only cause old entries to expire).
406 * Currently this is not fatal because any fmd state is transient and
407 * may also be freed when it gets sufficiently old. */
408 struct filter_mod_data *filter_fmd_get(struct obd_export *exp,
409 obd_id objid, obd_gr group)
411 struct filter_export_data *fed = &exp->exp_filter_data;
412 struct filter_mod_data *found = NULL, *fmd_new = NULL;
414 OBD_SLAB_ALLOC(fmd_new, ll_fmd_cachep, SLAB_NOFS, sizeof(*fmd_new));
416 spin_lock(&fed->fed_lock);
417 found = filter_fmd_find_nolock(&exp->exp_obd->u.filter,fed,objid,group);
420 list_add_tail(&fmd_new->fmd_list, &fed->fed_mod_list);
421 fmd_new->fmd_id = objid;
422 fmd_new->fmd_gr = group;
423 fmd_new->fmd_refcount++; /* list reference */
425 fed->fed_mod_count++;
427 OBD_SLAB_FREE(fmd_new, ll_fmd_cachep, sizeof(*fmd_new));
431 found->fmd_refcount++; /* caller reference */
432 found->fmd_expire = jiffies +
433 exp->exp_obd->u.filter.fo_fmd_max_age;
436 spin_unlock(&fed->fed_lock);
442 /* drop fmd list reference so it will disappear when last reference is put.
443 * This isn't so critical because it would in fact only affect the one client
444 * that is doing the unlink and at worst we have an stale entry referencing
445 * an object that should never be used again. */
446 static void filter_fmd_drop(struct obd_export *exp, obd_id objid, obd_gr group)
448 struct filter_mod_data *found = NULL;
450 spin_lock(&exp->exp_filter_data.fed_lock);
451 found = filter_fmd_find_nolock(&exp->exp_filter_data, objid, group);
453 list_del_init(&found->fmd_list);
454 filter_fmd_put_nolock(&exp->exp_filter_data, found);
456 spin_unlock(&exp->exp_filter_data.fed_lock);
459 #define filter_fmd_drop(exp, objid, group)
462 /* remove all entries from fmd list */
463 static void filter_fmd_cleanup(struct obd_export *exp)
465 struct filter_export_data *fed = &exp->exp_filter_data;
466 struct filter_mod_data *fmd = NULL, *tmp;
468 spin_lock(&fed->fed_lock);
469 list_for_each_entry_safe(fmd, tmp, &fed->fed_mod_list, fmd_list) {
470 list_del_init(&fmd->fmd_list);
471 filter_fmd_put_nolock(fed, fmd);
473 spin_unlock(&fed->fed_lock);
476 static int filter_init_export(struct obd_export *exp)
478 spin_lock_init(&exp->exp_filter_data.fed_lock);
479 INIT_LIST_HEAD(&exp->exp_filter_data.fed_mod_list);
480 exp->exp_connecting = 1;
485 static int filter_free_server_data(struct filter_obd *filter)
487 OBD_FREE(filter->fo_fsd, sizeof(*filter->fo_fsd));
488 filter->fo_fsd = NULL;
489 OBD_FREE(filter->fo_last_rcvd_slots, LR_MAX_CLIENTS / 8);
490 filter->fo_last_rcvd_slots = NULL;
494 /* assumes caller is already in kernel ctxt */
495 int filter_update_server_data(struct obd_device *obd, struct file *filp,
496 struct lr_server_data *fsd, int force_sync)
502 CDEBUG(D_INODE, "server uuid : %s\n", fsd->lsd_uuid);
503 CDEBUG(D_INODE, "server last_rcvd : "LPU64"\n",
504 le64_to_cpu(fsd->lsd_last_transno));
505 CDEBUG(D_INODE, "server last_mount: "LPU64"\n",
506 le64_to_cpu(fsd->lsd_mount_count));
508 fsd->lsd_compat14 = fsd->lsd_last_transno;
509 rc = fsfilt_write_record(obd, filp, fsd, sizeof(*fsd), &off,force_sync);
511 CERROR("error writing lr_server_data: rc = %d\n", rc);
516 int filter_update_last_objid(struct obd_device *obd, obd_gr group,
519 struct filter_obd *filter = &obd->u.filter;
525 if (filter->fo_last_objid_files[group] == NULL) {
526 CERROR("Object group "LPU64" not fully setup; not updating "
527 "last_objid\n", group);
531 CDEBUG(D_INODE, "%s: server last_objid for group "LPU64": "LPU64"\n",
532 obd->obd_name, group, filter->fo_last_objids[group]);
534 tmp = cpu_to_le64(filter->fo_last_objids[group]);
535 rc = fsfilt_write_record(obd, filter->fo_last_objid_files[group],
536 &tmp, sizeof(tmp), &off, force_sync);
538 CERROR("error writing group "LPU64" last objid: rc = %d\n",
543 /* assumes caller has already in kernel ctxt */
544 static int filter_init_server_data(struct obd_device *obd, struct file * filp)
546 struct filter_obd *filter = &obd->u.filter;
547 struct lr_server_data *fsd;
548 struct filter_client_data *fcd = NULL;
549 struct inode *inode = filp->f_dentry->d_inode;
550 unsigned long last_rcvd_size = inode->i_size;
556 /* ensure padding in the struct is the correct size */
557 CLASSERT (offsetof(struct lr_server_data, lsd_padding) +
558 sizeof(fsd->lsd_padding) == LR_SERVER_SIZE);
559 CLASSERT (offsetof(struct filter_client_data, fcd_padding) +
560 sizeof(fcd->fcd_padding) == LR_CLIENT_SIZE);
562 OBD_ALLOC(fsd, sizeof(*fsd));
565 filter->fo_fsd = fsd;
567 OBD_ALLOC(filter->fo_last_rcvd_slots, LR_MAX_CLIENTS / 8);
568 if (filter->fo_last_rcvd_slots == NULL) {
569 OBD_FREE(fsd, sizeof(*fsd));
573 if (last_rcvd_size == 0) {
574 LCONSOLE_WARN("%s: new disk, initializing\n", obd->obd_name);
576 memcpy(fsd->lsd_uuid, obd->obd_uuid.uuid,sizeof(fsd->lsd_uuid));
577 fsd->lsd_last_transno = 0;
578 mount_count = fsd->lsd_mount_count = 0;
579 fsd->lsd_server_size = cpu_to_le32(LR_SERVER_SIZE);
580 fsd->lsd_client_start = cpu_to_le32(LR_CLIENT_START);
581 fsd->lsd_client_size = cpu_to_le16(LR_CLIENT_SIZE);
582 fsd->lsd_subdir_count = cpu_to_le16(FILTER_SUBDIR_COUNT);
583 filter->fo_subdir_count = FILTER_SUBDIR_COUNT;
584 fsd->lsd_feature_incompat = cpu_to_le32(OBD_INCOMPAT_OST);
586 rc = fsfilt_read_record(obd, filp, fsd, sizeof(*fsd), &off);
588 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
592 if (strcmp(fsd->lsd_uuid, obd->obd_uuid.uuid) != 0) {
593 LCONSOLE_ERROR("Trying to start OBD %s using the wrong"
594 " disk %s. Were the /dev/ assignments "
596 obd->obd_uuid.uuid, fsd->lsd_uuid);
597 GOTO(err_fsd, rc = -EINVAL);
599 mount_count = le64_to_cpu(fsd->lsd_mount_count);
600 filter->fo_subdir_count = le16_to_cpu(fsd->lsd_subdir_count);
602 /* Assume old last_rcvd format unless I_C_LR is set */
603 if (!(fsd->lsd_feature_incompat &
604 cpu_to_le32(OBD_INCOMPAT_COMMON_LR)))
605 fsd->lsd_last_transno = fsd->lsd_compat14;
609 if (fsd->lsd_feature_incompat & ~cpu_to_le32(FILTER_INCOMPAT_SUPP)) {
610 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
611 obd->obd_name, le32_to_cpu(fsd->lsd_feature_incompat) &
612 ~FILTER_INCOMPAT_SUPP);
613 GOTO(err_fsd, rc = -EINVAL);
615 if (fsd->lsd_feature_rocompat & ~cpu_to_le32(FILTER_ROCOMPAT_SUPP)) {
616 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
617 obd->obd_name, le32_to_cpu(fsd->lsd_feature_rocompat) &
618 ~FILTER_ROCOMPAT_SUPP);
619 /* Do something like remount filesystem read-only */
620 GOTO(err_fsd, rc = -EINVAL);
623 CDEBUG(D_INODE, "%s: server last_transno : "LPU64"\n",
624 obd->obd_name, le64_to_cpu(fsd->lsd_last_transno));
625 CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
626 obd->obd_name, mount_count + 1);
627 CDEBUG(D_INODE, "%s: server data size: %u\n",
628 obd->obd_name, le32_to_cpu(fsd->lsd_server_size));
629 CDEBUG(D_INODE, "%s: per-client data start: %u\n",
630 obd->obd_name, le32_to_cpu(fsd->lsd_client_start));
631 CDEBUG(D_INODE, "%s: per-client data size: %u\n",
632 obd->obd_name, le32_to_cpu(fsd->lsd_client_size));
633 CDEBUG(D_INODE, "%s: server subdir_count: %u\n",
634 obd->obd_name, le16_to_cpu(fsd->lsd_subdir_count));
635 CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
636 last_rcvd_size <= le32_to_cpu(fsd->lsd_client_start) ? 0 :
637 (last_rcvd_size - le32_to_cpu(fsd->lsd_client_start)) /
638 le16_to_cpu(fsd->lsd_client_size));
640 if (!obd->obd_replayable) {
641 CWARN("%s: recovery support OFF\n", obd->obd_name);
645 for (cl_idx = 0, off = le32_to_cpu(fsd->lsd_client_start);
646 off < last_rcvd_size; cl_idx++) {
648 struct obd_export *exp;
649 struct filter_export_data *fed;
652 OBD_ALLOC(fcd, sizeof(*fcd));
654 GOTO(err_client, rc = -ENOMEM);
657 /* Don't assume off is incremented properly by
658 * fsfilt_read_record(), in case sizeof(*fcd)
659 * isn't the same as fsd->lsd_client_size. */
660 off = le32_to_cpu(fsd->lsd_client_start) +
661 cl_idx * le16_to_cpu(fsd->lsd_client_size);
662 rc = fsfilt_read_record(obd, filp, fcd, sizeof(*fcd), &off);
664 CERROR("error reading FILT %s idx %d off %llu: rc %d\n",
665 LAST_RCVD, cl_idx, off, rc);
666 break; /* read error shouldn't cause startup to fail */
669 if (fcd->fcd_uuid[0] == '\0') {
670 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
675 last_rcvd = le64_to_cpu(fcd->fcd_last_rcvd);
677 /* These exports are cleaned up by filter_disconnect(), so they
678 * need to be set up like real exports as filter_connect() does.
680 exp = class_new_export(obd, (struct obd_uuid *)fcd->fcd_uuid);
681 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
682 " srv lr: "LPU64"\n", fcd->fcd_uuid, cl_idx,
683 last_rcvd, le64_to_cpu(fsd->lsd_last_transno));
685 if (PTR_ERR(exp) == -EALREADY) {
686 /* export already exists, zero out this one */
687 CERROR("Zeroing out duplicate export due to "
689 fcd->fcd_uuid[0] = '\0';
691 GOTO(err_client, rc = PTR_ERR(exp));
694 fed = &exp->exp_filter_data;
696 rc = filter_client_add(obd, filter, fed, cl_idx);
697 LASSERTF(rc == 0, "rc = %d\n", rc); /* can't fail existing */
700 exp->exp_replay_needed = 1;
701 exp->exp_connecting = 0;
702 obd->obd_recoverable_clients++;
703 obd->obd_max_recoverable_clients++;
704 class_export_put(exp);
707 /* Need to check last_rcvd even for duplicated exports. */
708 CDEBUG(D_OTHER, "client at idx %d has last_rcvd = "LPU64"\n",
711 if (last_rcvd > le64_to_cpu(fsd->lsd_last_transno))
712 fsd->lsd_last_transno = cpu_to_le64(last_rcvd);
716 OBD_FREE(fcd, sizeof(*fcd));
718 obd->obd_last_committed = le64_to_cpu(fsd->lsd_last_transno);
720 if (obd->obd_recoverable_clients) {
721 CWARN("RECOVERY: service %s, %d recoverable clients, "
722 "last_rcvd "LPU64"\n", obd->obd_name,
723 obd->obd_recoverable_clients,
724 le64_to_cpu(fsd->lsd_last_transno));
725 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
726 obd->obd_recovering = 1;
727 obd->obd_recovery_start = CURRENT_SECONDS;
728 /* Only used for lprocfs_status */
729 obd->obd_recovery_end = obd->obd_recovery_start +
730 OBD_RECOVERY_TIMEOUT;
734 filter->fo_mount_count = mount_count + 1;
735 fsd->lsd_mount_count = cpu_to_le64(filter->fo_mount_count);
737 /* save it, so mount count and last_transno is current */
738 rc = filter_update_server_data(obd, filp, filter->fo_fsd, 1);
740 GOTO(err_client, rc);
745 class_disconnect_exports(obd);
747 filter_free_server_data(filter);
751 static int filter_cleanup_groups(struct obd_device *obd)
753 struct filter_obd *filter = &obd->u.filter;
755 struct dentry *dentry;
759 if (filter->fo_dentry_O_groups != NULL) {
760 for (i = 0; i < FILTER_GROUPS; i++) {
761 dentry = filter->fo_dentry_O_groups[i];
765 OBD_FREE(filter->fo_dentry_O_groups,
766 FILTER_GROUPS * sizeof(*filter->fo_dentry_O_groups));
767 filter->fo_dentry_O_groups = NULL;
769 if (filter->fo_last_objid_files != NULL) {
770 for (i = 0; i < FILTER_GROUPS; i++) {
771 filp = filter->fo_last_objid_files[i];
775 OBD_FREE(filter->fo_last_objid_files,
776 FILTER_GROUPS * sizeof(*filter->fo_last_objid_files));
777 filter->fo_last_objid_files = NULL;
779 if (filter->fo_dentry_O_sub != NULL) {
780 for (i = 0; i < filter->fo_subdir_count; i++) {
781 dentry = filter->fo_dentry_O_sub[i];
785 OBD_FREE(filter->fo_dentry_O_sub,
786 filter->fo_subdir_count *
787 sizeof(*filter->fo_dentry_O_sub));
788 filter->fo_dentry_O_sub = NULL;
790 if (filter->fo_last_objids != NULL) {
791 OBD_FREE(filter->fo_last_objids,
792 FILTER_GROUPS * sizeof(*filter->fo_last_objids));
793 filter->fo_last_objids = NULL;
795 if (filter->fo_dentry_O != NULL) {
796 f_dput(filter->fo_dentry_O);
797 filter->fo_dentry_O = NULL;
802 /* FIXME: object groups */
803 static int filter_prep_groups(struct obd_device *obd)
805 struct filter_obd *filter = &obd->u.filter;
806 struct dentry *dentry, *O_dentry;
808 int i, rc = 0, cleanup_phase = 0;
811 O_dentry = simple_mkdir(current->fs->pwd, "O", 0700, 1);
812 CDEBUG(D_INODE, "got/created O: %p\n", O_dentry);
813 if (IS_ERR(O_dentry)) {
814 rc = PTR_ERR(O_dentry);
815 CERROR("cannot open/create O: rc = %d\n", rc);
818 filter->fo_dentry_O = O_dentry;
819 cleanup_phase = 1; /* O_dentry */
821 /* Lookup "R" to tell if we're on an old OST FS and need to convert
822 * from O/R/<dir>/<objid> to O/0/<dir>/<objid>. This can be removed
823 * some time post 1.0 when all old-style OSTs have converted along
824 * with the init_objid hack. */
825 dentry = ll_lookup_one_len("R", O_dentry, 1);
827 GOTO(cleanup, rc = PTR_ERR(dentry));
828 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) {
829 struct dentry *O0_dentry = lookup_one_len("0", O_dentry, 1);
832 CWARN("converting OST to new object layout\n");
833 if (IS_ERR(O0_dentry)) {
834 rc = PTR_ERR(O0_dentry);
835 CERROR("error looking up O/0: rc %d\n", rc);
839 if (O0_dentry->d_inode) {
840 CERROR("Both O/R and O/0 exist. Fix manually.\n");
841 GOTO(cleanup_O0, rc = -EEXIST);
844 LOCK_INODE_MUTEX(O_dentry->d_inode);
845 rc = vfs_rename(O_dentry->d_inode, dentry,
846 O_dentry->d_inode, O0_dentry);
847 UNLOCK_INODE_MUTEX(O_dentry->d_inode);
850 CERROR("error renaming O/R to O/0: rc %d\n", rc);
851 GOTO(cleanup_O0, rc);
853 filter->fo_fsd->lsd_feature_incompat |=
854 cpu_to_le32(OBD_INCOMPAT_GROUPS);
855 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
857 GOTO(cleanup_O0, rc);
869 OBD_ALLOC(filter->fo_last_objids, FILTER_GROUPS * sizeof(__u64));
870 if (filter->fo_last_objids == NULL)
871 GOTO(cleanup, rc = -ENOMEM);
872 cleanup_phase = 2; /* groups */
874 OBD_ALLOC(filter->fo_dentry_O_groups, FILTER_GROUPS * sizeof(dentry));
875 if (filter->fo_dentry_O_groups == NULL)
876 GOTO(cleanup, rc = -ENOMEM);
877 OBD_ALLOC(filter->fo_last_objid_files, FILTER_GROUPS * sizeof(filp));
878 if (filter->fo_last_objid_files == NULL)
879 GOTO(cleanup, rc = -ENOMEM);
881 for (i = 0; i < FILTER_GROUPS; i++) {
885 sprintf(name, "%d", i);
886 dentry = simple_mkdir(O_dentry, name, 0700, 1);
887 CDEBUG(D_INODE, "got/created O/%s: %p\n", name, dentry);
888 if (IS_ERR(dentry)) {
889 rc = PTR_ERR(dentry);
890 CERROR("cannot lookup/create O/%s: rc = %d\n",
894 filter->fo_dentry_O_groups[i] = dentry;
896 sprintf(name, "O/%d/LAST_ID", i);
897 filp = filp_open(name, O_CREAT | O_RDWR, 0700);
900 CERROR("cannot create %s: rc = %d\n", name, rc);
903 filter->fo_last_objid_files[i] = filp;
905 if (filp->f_dentry->d_inode->i_size == 0) {
906 filter->fo_last_objids[i] = FILTER_INIT_OBJID;
907 rc = filter_update_last_objid(obd, i, 1);
913 rc = fsfilt_read_record(obd, filp, &filter->fo_last_objids[i],
914 sizeof(__u64), &off);
916 CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",
920 filter->fo_last_objids[i] =
921 le64_to_cpu(filter->fo_last_objids[i]);
922 CDEBUG(D_HA, "%s: server last_objid group %d: "LPU64"\n",
923 obd->obd_name, i, filter->fo_last_objids[i]);
926 if (filter->fo_subdir_count) {
927 O_dentry = filter->fo_dentry_O_groups[0];
928 OBD_ALLOC(filter->fo_dentry_O_sub,
929 filter->fo_subdir_count * sizeof(dentry));
930 if (filter->fo_dentry_O_sub == NULL)
931 GOTO(cleanup, rc = -ENOMEM);
933 for (i = 0; i < filter->fo_subdir_count; i++) {
935 snprintf(dir, sizeof(dir), "d%u", i);
937 dentry = simple_mkdir(O_dentry, dir, 0700, 1);
938 CDEBUG(D_INODE, "got/created O/0/%s: %p\n", dir,dentry);
939 if (IS_ERR(dentry)) {
940 rc = PTR_ERR(dentry);
941 CERROR("can't lookup/create O/0/%s: rc = %d\n",
945 filter->fo_dentry_O_sub[i] = dentry;
951 filter_cleanup_groups(obd);
955 /* setup the object store with correct subdirectories */
956 static int filter_prep(struct obd_device *obd)
958 struct lvfs_run_ctxt saved;
959 struct filter_obd *filter = &obd->u.filter;
965 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
966 file = filp_open(LAST_RCVD, O_RDWR | O_CREAT | O_LARGEFILE, 0700);
967 if (!file || IS_ERR(file)) {
969 CERROR("OBD filter: cannot open/create %s: rc = %d\n",
973 filter->fo_rcvd_filp = file;
974 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
975 CERROR("%s is not a regular file!: mode = %o\n", LAST_RCVD,
976 file->f_dentry->d_inode->i_mode);
977 GOTO(err_filp, rc = -ENOENT);
980 inode = file->f_dentry->d_parent->d_inode;
981 /* We use i_op->unlink directly in filter_vfs_unlink() */
982 if (!inode->i_op || !inode->i_op->create || !inode->i_op->unlink) {
983 CERROR("%s: filesystem does not support create/unlink ops\n",
985 GOTO(err_filp, rc = -EOPNOTSUPP);
988 rc = filter_init_server_data(obd, file);
990 CERROR("cannot read %s: rc = %d\n", LAST_RCVD, rc);
993 /* open and create health check io file*/
994 file = filp_open(HEALTH_CHECK, O_RDWR | O_CREAT, 0644);
997 CERROR("OBD filter: cannot open/create %s rc = %d\n",
1001 filter->fo_health_check_filp = file;
1002 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
1003 CERROR("%s is not a regular file!: mode = %o\n", HEALTH_CHECK,
1004 file->f_dentry->d_inode->i_mode);
1005 GOTO(err_health_check, rc = -ENOENT);
1007 rc = lvfs_check_io_health(obd, file);
1009 GOTO(err_health_check, rc);
1011 rc = filter_prep_groups(obd);
1013 GOTO(err_server_data, rc);
1015 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1020 //class_disconnect_exports(obd, 0);
1021 filter_free_server_data(filter);
1023 if (filp_close(filter->fo_health_check_filp, 0))
1024 CERROR("can't close %s after error\n", HEALTH_CHECK);
1025 filter->fo_health_check_filp = NULL;
1027 if (filp_close(filter->fo_rcvd_filp, 0))
1028 CERROR("can't close %s after error\n", LAST_RCVD);
1029 filter->fo_rcvd_filp = NULL;
1033 /* cleanup the filter: write last used object id to status file */
1034 static void filter_post(struct obd_device *obd)
1036 struct lvfs_run_ctxt saved;
1037 struct filter_obd *filter = &obd->u.filter;
1040 /* XXX: filter_update_lastobjid used to call fsync_dev. It might be
1041 * best to start a transaction with h_sync, because we removed this
1044 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1045 rc = filter_update_server_data(obd, filter->fo_rcvd_filp,
1048 CERROR("error writing server data: rc = %d\n", rc);
1050 for (i = 0; i < FILTER_GROUPS; i++) {
1051 rc = filter_update_last_objid(obd, i, (i == FILTER_GROUPS - 1));
1053 CERROR("error writing group %d lastobjid: rc = %d\n",
1057 rc = filp_close(filter->fo_rcvd_filp, 0);
1058 filter->fo_rcvd_filp = NULL;
1060 CERROR("error closing %s: rc = %d\n", LAST_RCVD, rc);
1062 rc = filp_close(filter->fo_health_check_filp, 0);
1063 filter->fo_health_check_filp = NULL;
1065 CERROR("error closing %s: rc = %d\n", HEALTH_CHECK, rc);
1067 filter_cleanup_groups(obd);
1068 filter_free_server_data(filter);
1069 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1072 static void filter_set_last_id(struct filter_obd *filter,
1073 obd_id id, obd_gr group)
1075 LASSERT(filter->fo_fsd != NULL);
1076 LASSERT(group <= FILTER_GROUPS);
1078 spin_lock(&filter->fo_objidlock);
1079 filter->fo_last_objids[group] = id;
1080 spin_unlock(&filter->fo_objidlock);
1083 obd_id filter_last_id(struct filter_obd *filter, obd_gr group)
1086 LASSERT(filter->fo_fsd != NULL);
1087 LASSERT(group <= FILTER_GROUPS);
1089 /* FIXME: object groups */
1090 spin_lock(&filter->fo_objidlock);
1091 id = filter->fo_last_objids[group];
1092 spin_unlock(&filter->fo_objidlock);
1097 static int filter_lock_dentry(struct obd_device *obd, struct dentry *dparent)
1099 LOCK_INODE_MUTEX(dparent->d_inode);
1103 /* We never dget the object parent, so DON'T dput it either */
1104 struct dentry *filter_parent(struct obd_device *obd, obd_gr group, obd_id objid)
1106 struct filter_obd *filter = &obd->u.filter;
1107 LASSERT(group < FILTER_GROUPS); /* FIXME: object groups */
1109 if (group > 0 || filter->fo_subdir_count == 0)
1110 return filter->fo_dentry_O_groups[group];
1112 return filter->fo_dentry_O_sub[objid & (filter->fo_subdir_count - 1)];
1115 /* We never dget the object parent, so DON'T dput it either */
1116 struct dentry *filter_parent_lock(struct obd_device *obd, obd_gr group,
1119 unsigned long now = jiffies;
1120 struct dentry *dparent = filter_parent(obd, group, objid);
1123 if (IS_ERR(dparent))
1126 rc = filter_lock_dentry(obd, dparent);
1127 fsfilt_check_slow(obd, now, obd_timeout, "parent lock");
1128 return rc ? ERR_PTR(rc) : dparent;
1131 /* We never dget the object parent, so DON'T dput it either */
1132 static void filter_parent_unlock(struct dentry *dparent)
1134 UNLOCK_INODE_MUTEX(dparent->d_inode);
1137 /* How to get files, dentries, inodes from object id's.
1139 * If dir_dentry is passed, the caller has already locked the parent
1140 * appropriately for this operation (normally a write lock). If
1141 * dir_dentry is NULL, we do a read lock while we do the lookup to
1142 * avoid races with create/destroy and such changing the directory
1143 * internal to the filesystem code. */
1144 struct dentry *filter_fid2dentry(struct obd_device *obd,
1145 struct dentry *dir_dentry,
1146 obd_gr group, obd_id id)
1148 struct dentry *dparent = dir_dentry;
1149 struct dentry *dchild;
1154 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
1155 RETURN(ERR_PTR(-ENOENT));
1158 CERROR("fatal: invalid object id 0\n");
1159 RETURN(ERR_PTR(-ESTALE));
1162 len = sprintf(name, LPU64, id);
1163 if (dir_dentry == NULL) {
1164 dparent = filter_parent_lock(obd, group, id);
1165 if (IS_ERR(dparent)) {
1166 CERROR("%s: error getting object "LPU64":"LPU64
1167 " parent: rc %ld\n", obd->obd_name,
1168 id, group, PTR_ERR(dparent));
1172 CDEBUG(D_INODE, "looking up object O/%.*s/%s\n",
1173 dparent->d_name.len, dparent->d_name.name, name);
1174 dchild = /*ll_*/lookup_one_len(name, dparent, len);
1175 if (dir_dentry == NULL)
1176 filter_parent_unlock(dparent);
1177 if (IS_ERR(dchild)) {
1178 CERROR("%s: child lookup error %ld\n", obd->obd_name,
1183 if (dchild->d_inode != NULL && is_bad_inode(dchild->d_inode)) {
1184 CERROR("%s: got bad object "LPU64" inode %lu\n",
1185 obd->obd_name, id, dchild->d_inode->i_ino);
1187 RETURN(ERR_PTR(-ENOENT));
1190 CDEBUG(D_INODE, "got child objid %s: %p, count = %d\n",
1191 name, dchild, atomic_read(&dchild->d_count));
1193 LASSERT(atomic_read(&dchild->d_count) > 0);
1198 static int filter_prepare_destroy(struct obd_device *obd, obd_id objid)
1200 struct lustre_handle lockh;
1201 int flags = LDLM_AST_DISCARD_DATA, rc;
1202 struct ldlm_res_id res_id = { .name = { objid } };
1203 ldlm_policy_data_t policy = { .l_extent = { 0, OBD_OBJECT_EOF } };
1206 /* Tell the clients that the object is gone now and that they should
1207 * throw away any cached pages. */
1208 rc = ldlm_cli_enqueue_local(obd->obd_namespace, res_id, LDLM_EXTENT,
1209 &policy, LCK_PW, &flags, ldlm_blocking_ast,
1210 ldlm_completion_ast, NULL, NULL, 0, NULL,
1213 /* We only care about the side-effects, just drop the lock. */
1215 ldlm_lock_decref(&lockh, LCK_PW);
1220 /* This is vfs_unlink() without down(i_sem). If we call regular vfs_unlink()
1221 * we have 2.6 lock ordering issues with filter_commitrw_write() as it takes
1222 * i_sem before starting a handle, while filter_destroy() + vfs_unlink do the
1223 * reverse. Caller must take i_sem before starting the transaction and we
1224 * drop it here before the inode is removed from the dentry. bug 4180/6984 */
1225 int filter_vfs_unlink(struct inode *dir, struct dentry *dentry)
1230 /* don't need dir->i_zombie for 2.4, it is for rename/unlink of dir
1231 * itself we already hold dir->i_mutex for child create/unlink ops */
1232 LASSERT(dentry->d_inode != NULL);
1233 LASSERT(TRYLOCK_INODE_MUTEX(dir) == 0);
1234 LASSERT(TRYLOCK_INODE_MUTEX(dentry->d_inode) == 0);
1238 if (/*!dentry->d_inode ||*/dentry->d_parent->d_inode != dir)
1239 GOTO(out, rc = -ENOENT);
1241 rc = ll_permission(dir, MAY_WRITE | MAY_EXEC, NULL);
1246 GOTO(out, rc = -EPERM);
1248 /* check_sticky() */
1249 if ((dentry->d_inode->i_uid != current->fsuid && !capable(CAP_FOWNER))||
1250 IS_APPEND(dentry->d_inode) || IS_IMMUTABLE(dentry->d_inode))
1251 GOTO(out, rc = -EPERM);
1253 /* NOTE: This might need to go outside i_mutex, though it isn't clear if
1254 * that was done because of journal_start (which is already done
1255 * here) or some other ordering issue. */
1258 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1259 rc = security_inode_unlink(dir, dentry);
1264 rc = dir->i_op->unlink(dir, dentry);
1266 /* need to drop i_mutex before we lose inode reference */
1267 UNLOCK_INODE_MUTEX(dentry->d_inode);
1274 /* Caller must hold LCK_PW on parent and push us into kernel context.
1275 * Caller must hold child i_mutex, we drop it always.
1276 * Caller is also required to ensure that dchild->d_inode exists. */
1277 static int filter_destroy_internal(struct obd_device *obd, obd_id objid,
1278 obd_gr group, struct dentry *dparent,
1279 struct dentry *dchild)
1281 struct inode *inode = dchild->d_inode;
1284 if (inode->i_nlink != 1 || atomic_read(&inode->i_count) != 1) {
1285 CERROR("destroying objid %.*s ino %lu nlink %lu count %d\n",
1286 dchild->d_name.len, dchild->d_name.name, inode->i_ino,
1287 (unsigned long)inode->i_nlink,
1288 atomic_read(&inode->i_count));
1291 rc = filter_vfs_unlink(dparent->d_inode, dchild);
1293 CERROR("error unlinking objid %.*s: rc %d\n",
1294 dchild->d_name.len, dchild->d_name.name, rc);
1298 static int filter_intent_policy(struct ldlm_namespace *ns,
1299 struct ldlm_lock **lockp, void *req_cookie,
1300 ldlm_mode_t mode, int flags, void *data)
1302 struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
1303 struct ptlrpc_request *req = req_cookie;
1304 struct ldlm_lock *lock = *lockp, *l = NULL;
1305 struct ldlm_resource *res = lock->l_resource;
1306 ldlm_processing_policy policy;
1307 struct ost_lvb *res_lvb, *reply_lvb;
1308 struct ldlm_reply *rep;
1309 struct list_head *tmp;
1311 int rc, tmpflags = 0, only_liblustre = 0;
1312 int repsize[3] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body),
1313 [DLM_LOCKREPLY_OFF] = sizeof(*rep),
1314 [DLM_REPLY_REC_OFF] = sizeof(*reply_lvb) };
1317 policy = ldlm_get_processing_policy(res);
1318 LASSERT(policy != NULL);
1319 LASSERT(req != NULL);
1321 rc = lustre_pack_reply(req, 3, repsize, NULL);
1323 RETURN(req->rq_status = rc);
1325 rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, sizeof(*rep));
1326 LASSERT(rep != NULL);
1328 reply_lvb = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF,
1329 sizeof(*reply_lvb));
1330 LASSERT(reply_lvb != NULL);
1332 //fixup_handle_for_resent_req(req, lock, &lockh);
1334 /* If we grant any lock at all, it will be a whole-file read lock.
1335 * Call the extent policy function to see if our request can be
1336 * granted, or is blocked. */
1337 lock->l_policy_data.l_extent.start = 0;
1338 lock->l_policy_data.l_extent.end = OBD_OBJECT_EOF;
1339 lock->l_req_mode = LCK_PR;
1341 LASSERT(ns == res->lr_namespace);
1343 rc = policy(lock, &tmpflags, 0, &err, &rpc_list);
1344 check_res_locked(res);
1346 /* FIXME: we should change the policy function slightly, to not make
1347 * this list at all, since we just turn around and free it */
1348 while (!list_empty(&rpc_list)) {
1349 struct ldlm_lock *wlock =
1350 list_entry(rpc_list.next, struct ldlm_lock, l_cp_ast);
1351 LASSERT((lock->l_flags & LDLM_FL_AST_SENT) == 0);
1352 LASSERT(lock->l_flags & LDLM_FL_CP_REQD);
1353 lock->l_flags &= ~LDLM_FL_CP_REQD;
1354 list_del_init(&wlock->l_cp_ast);
1355 LDLM_LOCK_PUT(wlock);
1358 /* The lock met with no resistance; we're finished. */
1359 if (rc == LDLM_ITER_CONTINUE) {
1362 * do not grant locks to the liblustre clients: they cannot
1363 * handle ASTs robustly.
1365 if (lock->l_export->exp_libclient) {
1366 ldlm_resource_unlink_lock(lock);
1367 RETURN(ELDLM_LOCK_ABORTED);
1369 RETURN(ELDLM_LOCK_REPLACED);
1372 /* Do not grant any lock, but instead send GL callbacks. The extent
1373 * policy nicely created a list of all PW locks for us. We will choose
1374 * the highest of those which are larger than the size in the LVB, if
1375 * any, and perform a glimpse callback. */
1376 res_lvb = res->lr_lvb_data;
1377 LASSERT(res_lvb != NULL);
1378 *reply_lvb = *res_lvb;
1380 list_for_each(tmp, &res->lr_granted) {
1381 struct ldlm_lock *tmplock =
1382 list_entry(tmp, struct ldlm_lock, l_res_link);
1384 if (tmplock->l_granted_mode == LCK_PR)
1387 * ->ns_lock guarantees that no new locks are granted, and,
1388 * therefore, that res->lr_lvb_data cannot increase beyond the
1389 * end of already granted lock. As a result, it is safe to
1390 * check against "stale" reply_lvb->lvb_size value without
1393 if (tmplock->l_policy_data.l_extent.end <= reply_lvb->lvb_size)
1396 /* Don't send glimpse ASTs to liblustre clients. They aren't
1397 * listening for them, and they do entirely synchronous I/O
1399 if (tmplock->l_export == NULL ||
1400 tmplock->l_export->exp_libclient == 1) {
1406 l = LDLM_LOCK_GET(tmplock);
1410 if (l->l_policy_data.l_extent.start >
1411 tmplock->l_policy_data.l_extent.start)
1415 l = LDLM_LOCK_GET(tmplock);
1419 /* There were no PW locks beyond the size in the LVB; finished. */
1421 if (only_liblustre) {
1422 /* If we discovered a liblustre client with a PW lock,
1423 * however, the LVB may be out of date! The LVB is
1424 * updated only on glimpse (which we don't do for
1425 * liblustre clients) and cancel (which the client
1426 * obviously has not yet done). So if it has written
1427 * data but kept the lock, the LVB is stale and needs
1428 * to be updated from disk.
1430 * Of course, this will all disappear when we switch to
1431 * taking liblustre locks on the OST. */
1432 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_update)
1433 ns->ns_lvbo->lvbo_update(res, NULL, 0, 1);
1435 RETURN(ELDLM_LOCK_ABORTED);
1439 * This check is for lock taken in filter_prepare_destroy() that does
1440 * not have l_glimpse_ast set. So the logic is: if there is a lock
1441 * with no l_glimpse_ast set, this object is being destroyed already.
1443 * Hence, if you are grabbing DLM locks on the server, always set
1444 * non-NULL glimpse_ast (e.g., ldlm_request.c:ldlm_glimpse_ast()).
1446 if (l->l_glimpse_ast == NULL) {
1447 /* We are racing with unlink(); just return -ENOENT */
1448 rep->lock_policy_res1 = -ENOENT;
1452 LASSERTF(l->l_glimpse_ast != NULL, "l == %p", l);
1453 rc = l->l_glimpse_ast(l, NULL); /* this will update the LVB */
1454 /* Update the LVB from disk if the AST failed (this is a legal race) */
1456 * XXX nikita: situation when ldlm_server_glimpse_ast() failed before
1457 * sending ast is not handled. This can result in lost client writes.
1459 if (rc != 0 && ns->ns_lvbo && ns->ns_lvbo->lvbo_update)
1460 ns->ns_lvbo->lvbo_update(res, NULL, 0, 1);
1463 *reply_lvb = *res_lvb;
1469 RETURN(ELDLM_LOCK_ABORTED);
1473 * per-obd_device iobuf pool.
1475 * To avoid memory deadlocks in low-memory setups, amount of dynamic
1476 * allocations in write-path has to be minimized (see bug 5137).
1478 * Pages, niobuf_local's and niobuf_remote's are pre-allocated and attached to
1479 * OST threads (see ost_thread_{init,done}()).
1481 * "iobuf's" used by filter cannot be attached to OST thread, however, because
1482 * at the OST layer there are only (potentially) multiple obd_device of type
1483 * unknown at the time of OST thread creation.
1485 * Instead array of iobuf's is attached to struct filter_obd (->fo_iobuf_pool
1486 * field). This array has size OST_MAX_THREADS, so that each OST thread uses
1487 * it's very own iobuf.
1491 * filter_kiobuf_pool_init()
1493 * filter_kiobuf_pool_done()
1495 * filter_iobuf_get()
1497 * operate on this array. They are "generic" in a sense that they don't depend
1498 * on actual type of iobuf's (the latter depending on Linux kernel version).
1502 * destroy pool created by filter_iobuf_pool_init
1504 static void filter_iobuf_pool_done(struct filter_obd *filter)
1506 struct filter_iobuf **pool;
1511 pool = filter->fo_iobuf_pool;
1513 for (i = 0; i < filter->fo_iobuf_count; ++ i) {
1514 if (pool[i] != NULL)
1515 filter_free_iobuf(pool[i]);
1517 OBD_FREE(pool, filter->fo_iobuf_count * sizeof pool[0]);
1518 filter->fo_iobuf_pool = NULL;
1524 * pre-allocate pool of iobuf's to be used by filter_{prep,commit}rw_write().
1526 static int filter_iobuf_pool_init(struct filter_obd *filter)
1532 OBD_ALLOC_GFP(filter->fo_iobuf_pool, OST_MAX_THREADS * sizeof(*pool),
1534 if (filter->fo_iobuf_pool == NULL)
1537 filter->fo_iobuf_count = OST_MAX_THREADS;
1542 /* Return iobuf allocated for @thread_id. We don't know in advance how
1543 * many threads there will be so we allocate a large empty array and only
1544 * fill in those slots that are actually in use.
1545 * If we haven't allocated a pool entry for this thread before, do so now. */
1546 void *filter_iobuf_get(struct filter_obd *filter, struct obd_trans_info *oti)
1548 int thread_id = oti ? oti->oti_thread_id : -1;
1549 struct filter_iobuf *pool = NULL;
1550 struct filter_iobuf **pool_place = NULL;
1552 if (thread_id >= 0) {
1553 LASSERT(thread_id < filter->fo_iobuf_count);
1554 pool = *(pool_place = &filter->fo_iobuf_pool[thread_id]);
1557 if (unlikely(pool == NULL)) {
1558 pool = filter_alloc_iobuf(filter, OBD_BRW_WRITE,
1559 PTLRPC_MAX_BRW_PAGES);
1560 if (pool_place != NULL)
1567 /* mount the file system (secretly). lustre_cfg parameters are:
1570 * 3 = flags: failover=f, failout=n
1573 int filter_common_setup(struct obd_device *obd, struct lustre_cfg* lcfg,
1576 struct filter_obd *filter = &obd->u.filter;
1577 struct vfsmount *mnt;
1578 struct lustre_mount_info *lmi;
1579 struct obd_uuid uuid;
1586 if (lcfg->lcfg_bufcount < 3 ||
1587 LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
1588 LUSTRE_CFG_BUFLEN(lcfg, 2) < 1)
1591 lmi = server_get_mount(obd->obd_name);
1593 /* We already mounted in lustre_fill_super.
1594 lcfg bufs 1, 2, 4 (device, fstype, mount opts) are ignored.*/
1595 struct lustre_sb_info *lsi = s2lsi(lmi->lmi_sb);
1597 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
1599 /* old path - used by lctl */
1600 CERROR("Using old MDS mount method\n");
1601 mnt = do_kern_mount(lustre_cfg_string(lcfg, 2),
1602 MS_NOATIME|MS_NODIRATIME,
1603 lustre_cfg_string(lcfg, 1), option);
1606 LCONSOLE_ERROR("Can't mount disk %s (%d)\n",
1607 lustre_cfg_string(lcfg, 1), rc);
1611 obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2));
1613 if (IS_ERR(obd->obd_fsops))
1614 GOTO(err_mntput, rc = PTR_ERR(obd->obd_fsops));
1616 rc = filter_iobuf_pool_init(filter);
1620 LASSERT(!lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb)));
1622 /* failover is the default */
1623 obd->obd_replayable = 1;
1625 if (lcfg->lcfg_bufcount > 3 && LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
1626 str = lustre_cfg_string(lcfg, 3);
1627 if (strchr(str, 'n')) {
1628 CWARN("%s: recovery disabled\n", obd->obd_name);
1629 obd->obd_replayable = 0;
1633 filter->fo_vfsmnt = mnt;
1634 obd->u.obt.obt_sb = mnt->mnt_sb;
1635 filter->fo_fstype = mnt->mnt_sb->s_type->name;
1636 CDEBUG(D_SUPER, "%s: mnt = %p\n", filter->fo_fstype, mnt);
1638 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1639 obd->obd_lvfs_ctxt.pwdmnt = mnt;
1640 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
1641 obd->obd_lvfs_ctxt.fs = get_ds();
1642 obd->obd_lvfs_ctxt.cb_ops = filter_lvfs_ops;
1644 rc = filter_prep(obd);
1648 filter->fo_destroy_in_progress = 0;
1649 sema_init(&filter->fo_create_lock, 1);
1650 spin_lock_init(&filter->fo_translock);
1651 spin_lock_init(&filter->fo_objidlock);
1652 INIT_LIST_HEAD(&filter->fo_export_list);
1653 sema_init(&filter->fo_alloc_lock, 1);
1654 spin_lock_init(&filter->fo_r_pages.oh_lock);
1655 spin_lock_init(&filter->fo_w_pages.oh_lock);
1656 spin_lock_init(&filter->fo_read_rpc_hist.oh_lock);
1657 spin_lock_init(&filter->fo_write_rpc_hist.oh_lock);
1658 spin_lock_init(&filter->fo_r_io_time.oh_lock);
1659 spin_lock_init(&filter->fo_w_io_time.oh_lock);
1660 spin_lock_init(&filter->fo_r_discont_pages.oh_lock);
1661 spin_lock_init(&filter->fo_w_discont_pages.oh_lock);
1662 spin_lock_init(&filter->fo_r_discont_blocks.oh_lock);
1663 spin_lock_init(&filter->fo_w_discont_blocks.oh_lock);
1664 spin_lock_init(&filter->fo_r_disk_iosize.oh_lock);
1665 spin_lock_init(&filter->fo_w_disk_iosize.oh_lock);
1666 spin_lock_init(&filter->fo_r_dio_frags.oh_lock);
1667 spin_lock_init(&filter->fo_w_dio_frags.oh_lock);
1668 filter->fo_readcache_max_filesize = FILTER_MAX_CACHE_SIZE;
1669 filter->fo_fmd_max_num = FILTER_FMD_MAX_NUM_DEFAULT;
1670 filter->fo_fmd_max_age = FILTER_FMD_MAX_AGE_DEFAULT;
1672 sprintf(ns_name, "filter-%s", obd->obd_uuid.uuid);
1673 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
1674 if (obd->obd_namespace == NULL)
1675 GOTO(err_post, rc = -ENOMEM);
1676 obd->obd_namespace->ns_lvbp = obd;
1677 obd->obd_namespace->ns_lvbo = &filter_lvbo;
1678 ldlm_register_intent(obd->obd_namespace, filter_intent_policy);
1680 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1681 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
1683 rc = llog_cat_initialize(obd, 1);
1685 CERROR("failed to setup llogging subsystems\n");
1689 rc = lquota_setup(quota_interface, obd, lcfg);
1693 uuid_ptr = fsfilt_uuid(obd, obd->u.obt.obt_sb);
1694 if (uuid_ptr != NULL) {
1695 class_uuid_unparse(uuid_ptr, &uuid);
1701 label = fsfilt_get_label(obd, obd->u.obt.obt_sb);
1703 if (obd->obd_recovering) {
1704 LCONSOLE_WARN("OST %s now serving %s (%s%s%s), but will be in "
1705 "recovery until %d %s reconnect, or if no clients"
1706 " reconnect for %d:%.02d; during that time new "
1707 "clients will not be allowed to connect. "
1708 "Recovery progress can be monitored by watching "
1709 "/proc/fs/lustre/obdfilter/%s/recovery_status.\n",
1710 obd->obd_name, lustre_cfg_string(lcfg, 1),
1711 label ?: "", label ? "/" : "", str,
1712 obd->obd_recoverable_clients,
1713 (obd->obd_recoverable_clients == 1)
1714 ? "client" : "clients",
1715 (int)(OBD_RECOVERY_TIMEOUT) / 60,
1716 (int)(OBD_RECOVERY_TIMEOUT) % 60,
1719 LCONSOLE_INFO("OST %s now serving %s (%s%s%s) with recovery "
1720 "%s\n", obd->obd_name, lustre_cfg_string(lcfg, 1),
1721 label ?: "", label ? "/" : "", str,
1722 obd->obd_replayable ? "enabled" : "disabled");
1730 fsfilt_put_ops(obd->obd_fsops);
1731 filter_iobuf_pool_done(filter);
1734 server_put_mount(obd->obd_name, mnt);
1741 obd->u.obt.obt_sb = 0;
1745 static int filter_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1747 struct lprocfs_static_vars lvars;
1751 CLASSERT(offsetof(struct obd_device, u.obt) ==
1752 offsetof(struct obd_device, u.filter.fo_obt));
1754 if (!LUSTRE_CFG_BUFLEN(lcfg, 1) || !LUSTRE_CFG_BUFLEN(lcfg, 2))
1757 /* 2.6.9 selinux wants a full option page for do_kern_mount (bug6471) */
1758 page = get_zeroed_page(GFP_KERNEL);
1762 memcpy((void *)page, lustre_cfg_buf(lcfg, 4),
1763 LUSTRE_CFG_BUFLEN(lcfg, 4));
1764 rc = filter_common_setup(obd, lcfg, (void *)page);
1767 lprocfs_init_vars(filter, &lvars);
1768 if (rc == 0 && lprocfs_obd_setup(obd, lvars.obd_vars) == 0 &&
1769 lprocfs_alloc_obd_stats(obd, LPROC_FILTER_LAST) == 0) {
1770 /* Init obdfilter private stats here */
1771 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_READ_BYTES,
1772 LPROCFS_CNTR_AVGMINMAX,
1773 "read_bytes", "bytes");
1774 lprocfs_counter_init(obd->obd_stats, LPROC_FILTER_WRITE_BYTES,
1775 LPROCFS_CNTR_AVGMINMAX,
1776 "write_bytes", "bytes");
1778 lproc_filter_attach_seqstat(obd);
1784 static struct llog_operations filter_mds_ost_repl_logops /* initialized below*/;
1785 static struct llog_operations filter_size_orig_logops = {
1786 lop_setup: llog_obd_origin_setup,
1787 lop_cleanup: llog_obd_origin_cleanup,
1788 lop_add: llog_obd_origin_add
1791 static int filter_llog_init(struct obd_device *obd, struct obd_device *tgt,
1792 int count, struct llog_catid *catid)
1794 struct llog_ctxt *ctxt;
1798 filter_mds_ost_repl_logops = llog_client_ops;
1799 filter_mds_ost_repl_logops.lop_cancel = llog_obd_repl_cancel;
1800 filter_mds_ost_repl_logops.lop_connect = llog_repl_connect;
1801 filter_mds_ost_repl_logops.lop_sync = llog_obd_repl_sync;
1803 rc = llog_setup(obd, LLOG_MDS_OST_REPL_CTXT, tgt, 0, NULL,
1804 &filter_mds_ost_repl_logops);
1808 /* FIXME - assign unlink_cb for filter's recovery */
1809 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
1810 ctxt->llog_proc_cb = filter_recov_log_mds_ost_cb;
1812 rc = llog_setup(obd, LLOG_SIZE_ORIG_CTXT, tgt, 0, NULL,
1813 &filter_size_orig_logops);
1817 static int filter_llog_finish(struct obd_device *obd, int count)
1819 struct llog_ctxt *ctxt;
1820 int rc = 0, rc2 = 0;
1823 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
1825 rc = llog_cleanup(ctxt);
1827 ctxt = llog_get_context(obd, LLOG_SIZE_ORIG_CTXT);
1829 rc2 = llog_cleanup(ctxt);
1836 static int filter_precleanup(struct obd_device *obd,
1837 enum obd_cleanup_stage stage)
1843 case OBD_CLEANUP_EARLY:
1845 case OBD_CLEANUP_EXPORTS:
1846 target_cleanup_recovery(obd);
1848 case OBD_CLEANUP_SELF_EXP:
1849 rc = filter_llog_finish(obd, 0);
1851 case OBD_CLEANUP_OBD:
1857 static int filter_cleanup(struct obd_device *obd)
1859 struct filter_obd *filter = &obd->u.filter;
1860 lvfs_sbdev_type save_dev;
1861 int must_relock = 0, must_put = 0;
1865 LCONSOLE_WARN("%s: shutting down for failover; client state "
1866 "will be preserved.\n", obd->obd_name);
1868 if (!list_empty(&obd->obd_exports)) {
1869 CERROR("%s: still has clients!\n", obd->obd_name);
1870 class_disconnect_exports(obd);
1871 if (!list_empty(&obd->obd_exports)) {
1872 CERROR("still has exports after forced cleanup?\n");
1877 lquota_cleanup(quota_interface, obd);
1879 ldlm_namespace_free(obd->obd_namespace, obd->obd_force);
1881 if (obd->u.obt.obt_sb == NULL)
1883 save_dev = lvfs_sbdev(obd->u.obt.obt_sb);
1885 lprocfs_free_obd_stats(obd);
1886 lprocfs_obd_cleanup(obd);
1890 shrink_dcache_parent(obd->u.obt.obt_sb->s_root);
1892 LL_DQUOT_OFF(obd->u.obt.obt_sb);
1894 must_put = server_put_mount(obd->obd_name, filter->fo_vfsmnt);
1895 /* must_put is for old method (l_p_m returns non-0 on err) */
1897 /* We can only unlock kernel if we are in the context of sys_ioctl,
1898 otherwise we never called lock_kernel */
1899 if (ll_kernel_locked()) {
1905 /* In case we didn't mount with lustre_get_mount -- old method*/
1906 mntput(filter->fo_vfsmnt);
1907 lvfs_clear_rdonly(save_dev);
1909 obd->u.obt.obt_sb = NULL;
1914 fsfilt_put_ops(obd->obd_fsops);
1916 filter_iobuf_pool_done(filter);
1918 LCONSOLE_INFO("OST %s has stopped.\n", obd->obd_name);
1923 static int filter_connect_internal(struct obd_export *exp,
1924 struct obd_connect_data *data)
1929 CDEBUG(D_RPCTRACE, "%s: cli %s/%p ocd_connect_flags: "LPX64
1930 " ocd_version: %x ocd_grant: %d ocd_index: %u\n",
1931 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
1932 data->ocd_connect_flags, data->ocd_version,
1933 data->ocd_grant, data->ocd_index);
1935 data->ocd_connect_flags &= OST_CONNECT_SUPPORTED;
1936 exp->exp_connect_flags = data->ocd_connect_flags;
1937 data->ocd_version = LUSTRE_VERSION_CODE;
1939 if (exp->exp_connect_flags & OBD_CONNECT_GRANT) {
1940 obd_size left, want;
1942 spin_lock(&exp->exp_obd->obd_osfs_lock);
1943 left = filter_grant_space_left(exp);
1944 want = data->ocd_grant;
1945 data->ocd_grant = filter_grant(exp, 0, want, left);
1946 spin_unlock(&exp->exp_obd->obd_osfs_lock);
1948 CDEBUG(D_CACHE, "%s: cli %s/%p ocd_grant: %d want: "
1949 LPU64" left: "LPU64"\n", exp->exp_obd->obd_name,
1950 exp->exp_client_uuid.uuid, exp,
1951 data->ocd_grant, want, left);
1954 if (data->ocd_connect_flags & OBD_CONNECT_INDEX) {
1955 struct filter_obd *filter = &exp->exp_obd->u.filter;
1956 struct lr_server_data *lsd = filter->fo_fsd;
1957 int index = le32_to_cpu(lsd->lsd_ost_index);
1959 if (!(lsd->lsd_feature_compat &
1960 cpu_to_le32(OBD_COMPAT_OST))) {
1961 /* this will only happen on the first connect */
1962 lsd->lsd_ost_index = cpu_to_le32(data->ocd_index);
1963 lsd->lsd_feature_compat |= cpu_to_le32(OBD_COMPAT_OST);
1964 filter_update_server_data(exp->exp_obd,
1965 filter->fo_rcvd_filp, lsd, 1);
1966 } else if (index != data->ocd_index) {
1967 LCONSOLE_ERROR("Connection from %s to index "
1968 "%u doesn't match actual OST "
1969 "index %u, bad configuration?\n",
1970 obd_export_nid2str(exp), index,
1976 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_SIZE)) {
1977 data->ocd_brw_size = 65536;
1978 } else if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
1979 data->ocd_brw_size = min(data->ocd_brw_size,
1980 (__u32)(PTLRPC_MAX_BRW_PAGES << PAGE_SHIFT));
1983 /* FIXME: Do the same with the MDS UUID and fsd_peeruuid.
1984 * FIXME: We don't strictly need the COMPAT flag for that,
1985 * FIXME: as fsd_peeruuid[0] will tell us if that is set.
1986 * FIXME: We needed it for the index, as index 0 is valid. */
1991 static int filter_reconnect(struct obd_export *exp, struct obd_device *obd,
1992 struct obd_uuid *cluuid,
1993 struct obd_connect_data *data)
1998 if (exp == NULL || obd == NULL || cluuid == NULL)
2001 rc = filter_connect_internal(exp, data);
2006 /* nearly identical to mds_connect */
2007 static int filter_connect(const struct lu_context *ctx,
2008 struct lustre_handle *conn, struct obd_device *obd,
2009 struct obd_uuid *cluuid,
2010 struct obd_connect_data *data)
2012 struct obd_export *exp;
2013 struct filter_export_data *fed;
2014 struct filter_client_data *fcd = NULL;
2015 struct filter_obd *filter = &obd->u.filter;
2019 if (conn == NULL || obd == NULL || cluuid == NULL)
2022 rc = class_connect(conn, obd, cluuid);
2025 exp = class_conn2export(conn);
2026 LASSERT(exp != NULL);
2028 fed = &exp->exp_filter_data;
2030 rc = filter_connect_internal(exp, data);
2034 if (!obd->obd_replayable)
2035 GOTO(cleanup, rc = 0);
2037 OBD_ALLOC(fcd, sizeof(*fcd));
2039 CERROR("filter: out of memory for client data\n");
2040 GOTO(cleanup, rc = -ENOMEM);
2043 memcpy(fcd->fcd_uuid, cluuid, sizeof(fcd->fcd_uuid));
2046 rc = filter_client_add(obd, filter, fed, -1);
2053 OBD_FREE(fcd, sizeof(*fcd));
2054 fed->fed_fcd = NULL;
2056 class_disconnect(exp);
2058 class_export_put(exp);
2064 /* Do extra sanity checks for grant accounting. We do this at connect,
2065 * disconnect, and statfs RPC time, so it shouldn't be too bad. We can
2066 * always get rid of it or turn it off when we know accounting is good. */
2067 static void filter_grant_sanity_check(struct obd_device *obd, const char *func)
2069 struct filter_export_data *fed;
2070 struct obd_export *exp;
2071 obd_size maxsize = obd->obd_osfs.os_blocks * obd->obd_osfs.os_bsize;
2072 obd_size tot_dirty = 0, tot_pending = 0, tot_granted = 0;
2073 obd_size fo_tot_dirty, fo_tot_pending, fo_tot_granted;
2075 if (list_empty(&obd->obd_exports))
2078 spin_lock(&obd->obd_osfs_lock);
2079 spin_lock(&obd->obd_dev_lock);
2080 list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
2082 fed = &exp->exp_filter_data;
2083 if (fed->fed_grant < 0 || fed->fed_pending < 0 ||
2086 if (maxsize > 0) { /* we may not have done a statfs yet */
2087 LASSERTF(fed->fed_grant + fed->fed_pending <= maxsize,
2088 "%s: cli %s/%p %ld+%ld > "LPU64"\n", func,
2089 exp->exp_client_uuid.uuid, exp,
2090 fed->fed_grant, fed->fed_pending, maxsize);
2091 LASSERTF(fed->fed_dirty <= maxsize,
2092 "%s: cli %s/%p %ld > "LPU64"\n", func,
2093 exp->exp_client_uuid.uuid, exp,
2094 fed->fed_dirty, maxsize);
2097 CERROR("%s: cli %s/%p dirty %ld pend %ld grant %ld\n",
2098 obd->obd_name, exp->exp_client_uuid.uuid, exp,
2099 fed->fed_dirty, fed->fed_pending,fed->fed_grant);
2101 CDEBUG(D_CACHE, "%s: cli %s/%p dirty %ld pend %ld grant %ld\n",
2102 obd->obd_name, exp->exp_client_uuid.uuid, exp,
2103 fed->fed_dirty, fed->fed_pending,fed->fed_grant);
2104 tot_granted += fed->fed_grant + fed->fed_pending;
2105 tot_pending += fed->fed_pending;
2106 tot_dirty += fed->fed_dirty;
2108 fo_tot_granted = obd->u.filter.fo_tot_granted;
2109 fo_tot_pending = obd->u.filter.fo_tot_pending;
2110 fo_tot_dirty = obd->u.filter.fo_tot_dirty;
2111 spin_unlock(&obd->obd_dev_lock);
2112 spin_unlock(&obd->obd_osfs_lock);
2114 /* Do these assertions outside the spinlocks so we don't kill system */
2115 if (tot_granted != fo_tot_granted)
2116 CERROR("%s: tot_granted "LPU64" != fo_tot_granted "LPU64"\n",
2117 func, tot_granted, fo_tot_granted);
2118 if (tot_pending != fo_tot_pending)
2119 CERROR("%s: tot_pending "LPU64" != fo_tot_pending "LPU64"\n",
2120 func, tot_pending, fo_tot_pending);
2121 if (tot_dirty != fo_tot_dirty)
2122 CERROR("%s: tot_dirty "LPU64" != fo_tot_dirty "LPU64"\n",
2123 func, tot_dirty, fo_tot_dirty);
2124 if (tot_pending > tot_granted)
2125 CERROR("%s: tot_pending "LPU64" > tot_granted "LPU64"\n",
2126 func, tot_pending, tot_granted);
2127 if (tot_granted > maxsize)
2128 CERROR("%s: tot_granted "LPU64" > maxsize "LPU64"\n",
2129 func, tot_granted, maxsize);
2130 if (tot_dirty > maxsize)
2131 CERROR("%s: tot_dirty "LPU64" > maxsize "LPU64"\n",
2132 func, tot_dirty, maxsize);
2135 /* Remove this client from the grant accounting totals. We also remove
2136 * the export from the obd device under the osfs and dev locks to ensure
2137 * that the filter_grant_sanity_check() calculations are always valid.
2138 * The client should do something similar when it invalidates its import. */
2139 static void filter_grant_discard(struct obd_export *exp)
2141 struct obd_device *obd = exp->exp_obd;
2142 struct filter_obd *filter = &obd->u.filter;
2143 struct filter_export_data *fed = &exp->exp_filter_data;
2145 spin_lock(&obd->obd_osfs_lock);
2146 spin_lock(&obd->obd_dev_lock);
2147 list_del_init(&exp->exp_obd_chain);
2148 spin_unlock(&obd->obd_dev_lock);
2150 LASSERTF(filter->fo_tot_granted >= fed->fed_grant,
2151 "%s: tot_granted "LPU64" cli %s/%p fed_grant %ld\n",
2152 obd->obd_name, filter->fo_tot_granted,
2153 exp->exp_client_uuid.uuid, exp, fed->fed_grant);
2154 filter->fo_tot_granted -= fed->fed_grant;
2155 LASSERTF(filter->fo_tot_pending >= fed->fed_pending,
2156 "%s: tot_pending "LPU64" cli %s/%p fed_pending %ld\n",
2157 obd->obd_name, filter->fo_tot_pending,
2158 exp->exp_client_uuid.uuid, exp, fed->fed_pending);
2159 /* fo_tot_pending is handled in filter_grant_commit as bulk finishes */
2160 LASSERTF(filter->fo_tot_dirty >= fed->fed_dirty,
2161 "%s: tot_dirty "LPU64" cli %s/%p fed_dirty %ld\n",
2162 obd->obd_name, filter->fo_tot_dirty,
2163 exp->exp_client_uuid.uuid, exp, fed->fed_dirty);
2164 filter->fo_tot_dirty -= fed->fed_dirty;
2168 spin_unlock(&obd->obd_osfs_lock);
2171 static int filter_destroy_export(struct obd_export *exp)
2175 if (exp->exp_filter_data.fed_pending)
2176 CERROR("%s: cli %s/%p has %lu pending on destroyed export\n",
2177 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
2178 exp, exp->exp_filter_data.fed_pending);
2180 target_destroy_export(exp);
2182 if (obd_uuid_equals(&exp->exp_client_uuid, &exp->exp_obd->obd_uuid))
2185 if (exp->exp_obd->obd_replayable)
2186 filter_client_free(exp);
2188 fsfilt_sync(exp->exp_obd, exp->exp_obd->u.obt.obt_sb);
2190 filter_grant_discard(exp);
2191 filter_fmd_cleanup(exp);
2193 if (!(exp->exp_flags & OBD_OPT_FORCE))
2194 filter_grant_sanity_check(exp->exp_obd, __FUNCTION__);
2199 /* also incredibly similar to mds_disconnect */
2200 static int filter_disconnect(struct obd_export *exp)
2202 struct obd_device *obd = exp->exp_obd;
2203 struct llog_ctxt *ctxt;
2208 class_export_get(exp);
2210 if (!(exp->exp_flags & OBD_OPT_FORCE))
2211 filter_grant_sanity_check(obd, __FUNCTION__);
2212 filter_grant_discard(exp);
2214 /* Disconnect early so that clients can't keep using export */
2215 rc = class_disconnect(exp);
2216 if (exp->exp_obd->obd_namespace != NULL)
2217 ldlm_cancel_locks_for_export(exp);
2219 fsfilt_sync(obd, obd->u.obt.obt_sb);
2221 /* flush any remaining cancel messages out to the target */
2222 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
2223 err = llog_sync(ctxt, exp);
2225 CERROR("error flushing logs to MDS: rc %d\n", err);
2227 class_export_put(exp);
2231 static int filter_ping(struct obd_export *exp)
2233 filter_fmd_expire(exp);
2238 struct dentry *__filter_oa2dentry(struct obd_device *obd, struct obdo *oa,
2239 const char *what, int quiet)
2241 struct dentry *dchild = NULL;
2243 if (!(oa->o_valid & OBD_MD_FLGROUP))
2246 dchild = filter_fid2dentry(obd, NULL, oa->o_gr, oa->o_id);
2248 if (IS_ERR(dchild)) {
2249 CERROR("%s error looking up object: "LPU64"\n",
2254 if (dchild->d_inode == NULL) {
2256 CERROR("%s: %s on non-existent object: "LPU64"\n",
2257 obd->obd_name, what, oa->o_id);
2259 RETURN(ERR_PTR(-ENOENT));
2265 static int filter_getattr(struct obd_export *exp, struct obd_info *oinfo)
2267 struct dentry *dentry = NULL;
2268 struct obd_device *obd;
2272 obd = class_exp2obd(exp);
2274 CDEBUG(D_IOCTL, "invalid client export %p\n", exp);
2278 dentry = filter_oa2dentry(obd, oinfo->oi_oa);
2280 RETURN(PTR_ERR(dentry));
2282 /* Limit the valid bits in the return data to what we actually use */
2283 oinfo->oi_oa->o_valid = OBD_MD_FLID;
2284 obdo_from_inode(oinfo->oi_oa, dentry->d_inode, FILTER_VALID_FLAGS);
2290 /* this should be enabled/disabled in condition to enabled/disabled large
2291 * inodes (fast EAs) in backing store FS. */
2292 int filter_update_fidea(struct obd_export *exp, struct inode *inode,
2293 void *handle, struct obdo *oa)
2295 struct obd_device *obd = exp->exp_obd;
2299 if (oa->o_valid & OBD_MD_FLFID) {
2300 struct filter_fid ff;
2302 if (!(oa->o_valid & OBD_MD_FLGROUP))
2305 /* packing fid and converting it to LE for storing into EA.
2306 * Here ->o_stripe_idx should be filled by LOV and rest of
2307 * fields - by client. */
2308 ff.ff_fid.id = cpu_to_le64(oa->o_fid);
2309 ff.ff_fid.f_type = cpu_to_le32(oa->o_stripe_idx);
2310 ff.ff_fid.generation = cpu_to_le32(oa->o_generation);
2311 ff.ff_objid = cpu_to_le64(oa->o_id);
2312 ff.ff_group = cpu_to_le64(oa->o_gr);
2314 CDEBUG(D_INODE, "storing filter fid EA ("LPU64"/%u/%u"
2315 LPU64"/"LPU64")\n", oa->o_fid, oa->o_stripe_idx,
2316 oa->o_generation, oa->o_id, oa->o_gr);
2318 rc = fsfilt_set_md(obd, inode, handle, &ff, sizeof(ff), "fid");
2320 CERROR("store fid in object failed! rc: %d\n", rc);
2322 CDEBUG(D_HA, "OSS object without fid info!\n");
2328 /* this is called from filter_truncate() until we have filter_punch() */
2329 int filter_setattr_internal(struct obd_export *exp, struct dentry *dentry,
2330 struct obdo *oa, struct obd_trans_info *oti)
2332 unsigned int orig_ids[MAXQUOTAS] = {0, 0};
2333 struct llog_cookie *fcc = NULL;
2334 struct filter_obd *filter;
2335 int rc, err, locked = 0;
2336 unsigned int ia_valid;
2337 struct inode *inode;
2342 LASSERT(dentry != NULL);
2343 LASSERT(!IS_ERR(dentry));
2345 inode = dentry->d_inode;
2346 LASSERT(inode != NULL);
2348 filter = &exp->exp_obd->u.filter;
2349 iattr_from_obdo(&iattr, oa, oa->o_valid);
2350 ia_valid = iattr.ia_valid;
2352 if (oa->o_valid & OBD_MD_FLCOOKIE) {
2353 OBD_ALLOC(fcc, sizeof(*fcc));
2355 memcpy(fcc, obdo_logcookie(oa), sizeof(*fcc));
2358 if (ia_valid & ATTR_SIZE || ia_valid & (ATTR_UID | ATTR_GID)) {
2359 LOCK_INODE_MUTEX(inode);
2363 /* If the inode still has SUID+SGID bits set (see filter_precreate())
2364 * then we will accept the UID+GID sent by the client during write for
2365 * initializing the ownership of this inode. We only allow this to
2366 * happen once so clear these bits in setattr. In 2.6 kernels it is
2367 * possible to get ATTR_UID and ATTR_GID separately, so we only clear
2368 * the flags that are actually being set. */
2369 if (ia_valid & (ATTR_UID | ATTR_GID)) {
2370 CDEBUG(D_INODE, "update UID/GID to %lu/%lu\n",
2371 (unsigned long)oa->o_uid, (unsigned long)oa->o_gid);
2373 if ((inode->i_mode & S_ISUID) && (ia_valid & ATTR_UID)) {
2374 if (!(ia_valid & ATTR_MODE)) {
2375 iattr.ia_mode = inode->i_mode;
2376 iattr.ia_valid |= ATTR_MODE;
2378 iattr.ia_mode &= ~S_ISUID;
2380 if ((inode->i_mode & S_ISGID) && (ia_valid & ATTR_GID)) {
2381 if (!(iattr.ia_valid & ATTR_MODE)) {
2382 iattr.ia_mode = inode->i_mode;
2383 iattr.ia_valid |= ATTR_MODE;
2385 iattr.ia_mode &= ~S_ISGID;
2388 orig_ids[USRQUOTA] = inode->i_uid;
2389 orig_ids[GRPQUOTA] = inode->i_gid;
2390 handle = fsfilt_start_log(exp->exp_obd, inode,
2391 FSFILT_OP_SETATTR, oti, 1);
2393 /* update inode EA only once when inode is suid bit marked. As
2394 * on 2.6.x UID and GID may be set separately, we check here
2395 * only one of them to avoid double setting. */
2396 if (inode->i_mode & S_ISUID)
2397 filter_update_fidea(exp, inode, handle, oa);
2399 handle = fsfilt_start(exp->exp_obd, inode,
2400 FSFILT_OP_SETATTR, oti);
2404 GOTO(out_unlock, rc = PTR_ERR(handle));
2406 if (oa->o_valid & OBD_MD_FLFLAGS) {
2407 rc = fsfilt_iocontrol(exp->exp_obd, inode, NULL,
2408 EXT3_IOC_SETFLAGS, (long)&oa->o_flags);
2410 rc = fsfilt_setattr(exp->exp_obd, dentry, handle, &iattr, 1);
2412 /* set cancel cookie callback function */
2413 fsfilt_add_journal_cb(exp->exp_obd, 0, handle,
2414 filter_cancel_cookies_cb,
2420 rc = filter_finish_transno(exp, oti, rc);
2422 err = fsfilt_commit(exp->exp_obd, inode, handle, 0);
2424 CERROR("error on commit, err = %d\n", err);
2430 /* Let's flush truncated page on disk immediately, then we can
2431 * avoid need to search for page aliases before directio writes
2432 * and this sort of stuff at expense of somewhat slower
2433 * truncates not on a page boundary. I believe this is the only
2434 * place in filter code that can lead to pages getting to
2435 * pagecache so far. */
2436 filter_clear_truncated_page(inode);
2437 UNLOCK_INODE_MUTEX(inode);
2444 UNLOCK_INODE_MUTEX(inode);
2447 OBD_FREE(fcc, sizeof(*fcc));
2449 /* trigger quota release */
2450 if (ia_valid & (ATTR_SIZE | ATTR_UID | ATTR_GID)) {
2451 unsigned int cur_ids[MAXQUOTAS] = {oa->o_uid, oa->o_gid};
2452 int rc2 = lquota_adjust(quota_interface, exp->exp_obd, cur_ids,
2453 orig_ids, rc, FSFILT_OP_SETATTR);
2455 CDEBUG(rc2 ? D_ERROR : D_QUOTA,
2456 "filter adjust qunit. (rc:%d)\n", rc2);
2461 /* this is called from filter_truncate() until we have filter_punch() */
2462 int filter_setattr(struct obd_export *exp, struct obd_info *oinfo,
2463 struct obd_trans_info *oti)
2465 struct ldlm_res_id res_id = { .name = { oinfo->oi_oa->o_id } };
2466 struct ldlm_valblock_ops *ns_lvbo;
2467 struct filter_mod_data *fmd;
2468 struct lvfs_run_ctxt saved;
2469 struct filter_obd *filter;
2470 struct ldlm_resource *res;
2471 struct dentry *dentry;
2475 dentry = __filter_oa2dentry(exp->exp_obd, oinfo->oi_oa,
2478 RETURN(PTR_ERR(dentry));
2480 filter = &exp->exp_obd->u.filter;
2481 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2484 if (oinfo->oi_oa->o_valid &
2485 (OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME)) {
2486 fmd = filter_fmd_get(exp,oinfo->oi_oa->o_id,oinfo->oi_oa->o_gr);
2487 if (fmd && fmd->fmd_mactime_xid < oti->oti_xid)
2488 fmd->fmd_mactime_xid = oti->oti_xid;
2489 filter_fmd_put(exp, fmd);
2492 /* setting objects attributes (including owner/group) */
2493 rc = filter_setattr_internal(exp, dentry, oinfo->oi_oa, oti);
2495 GOTO(out_unlock, rc);
2497 res = ldlm_resource_get(exp->exp_obd->obd_namespace, NULL,
2498 res_id, LDLM_EXTENT, 0);
2501 ns_lvbo = res->lr_namespace->ns_lvbo;
2502 if (ns_lvbo && ns_lvbo->lvbo_update)
2503 rc = ns_lvbo->lvbo_update(res, NULL, 0, 0);
2504 ldlm_resource_putref(res);
2507 oinfo->oi_oa->o_valid = OBD_MD_FLID;
2509 /* Quota release need uid/gid info */
2510 obdo_from_inode(oinfo->oi_oa, dentry->d_inode,
2511 FILTER_VALID_FLAGS | OBD_MD_FLUID | OBD_MD_FLGID);
2517 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
2521 /* XXX identical to osc_unpackmd */
2522 static int filter_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2523 struct lov_mds_md *lmm, int lmm_bytes)
2529 if (lmm_bytes < sizeof (*lmm)) {
2530 CERROR("lov_mds_md too small: %d, need %d\n",
2531 lmm_bytes, (int)sizeof(*lmm));
2534 /* XXX LOV_MAGIC etc check? */
2536 if (lmm->lmm_object_id == cpu_to_le64(0)) {
2537 CERROR("lov_mds_md: zero lmm_object_id\n");
2542 lsm_size = lov_stripe_md_size(1);
2546 if (*lsmp != NULL && lmm == NULL) {
2547 OBD_FREE(*lsmp, lsm_size);
2552 if (*lsmp == NULL) {
2553 OBD_ALLOC(*lsmp, lsm_size);
2557 loi_init((*lsmp)->lsm_oinfo);
2561 /* XXX zero *lsmp? */
2562 (*lsmp)->lsm_object_id = le64_to_cpu (lmm->lmm_object_id);
2563 LASSERT((*lsmp)->lsm_object_id);
2566 (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
2571 /* caller must hold fo_create_lock */
2572 static int filter_destroy_precreated(struct obd_export *exp, struct obdo *oa,
2573 struct filter_obd *filter)
2575 struct obdo doa; /* XXX obdo on stack */
2581 LASSERT(down_trylock(&filter->fo_create_lock) != 0);
2583 memset(&doa, 0, sizeof(doa));
2584 if (oa->o_valid & OBD_MD_FLGROUP) {
2585 doa.o_valid |= OBD_MD_FLGROUP;
2586 doa.o_gr = oa->o_gr;
2590 doa.o_mode = S_IFREG;
2592 if (!filter->fo_destroy_in_progress) {
2593 CERROR("%s: destroy_in_progress already cleared\n",
2594 exp->exp_obd->obd_name);
2598 last = filter_last_id(filter, doa.o_gr);
2599 CWARN("%s: deleting orphan objects from "LPU64" to "LPU64"\n",
2600 exp->exp_obd->obd_name, oa->o_id + 1, last);
2601 for (id = last; id > oa->o_id; id--) {
2603 rc = filter_destroy(exp, &doa, NULL, NULL, NULL);
2604 if (rc && rc != -ENOENT) /* this is pretty fatal... */
2605 CEMERG("error destroying precreate objid "LPU64": %d\n",
2607 filter_set_last_id(filter, id - 1, doa.o_gr);
2608 /* update last_id on disk periodically so that if we restart
2609 * we don't need to re-scan all of the just-deleted objects. */
2610 if ((id & 511) == 0)
2611 filter_update_last_objid(exp->exp_obd, doa.o_gr, 0);
2614 CDEBUG(D_HA, "%s: after destroy: set last_objids["LPU64"] = "LPU64"\n",
2615 exp->exp_obd->obd_name, doa.o_gr, oa->o_id);
2617 rc = filter_update_last_objid(exp->exp_obd, doa.o_gr, 1);
2618 filter->fo_destroy_in_progress = 0;
2623 static int filter_precreate(struct obd_device *obd, struct obdo *oa,
2624 obd_gr group, int *num);
2625 /* returns a negative error or a nonnegative number of files to create */
2626 static int filter_handle_precreate(struct obd_export *exp, struct obdo *oa,
2627 obd_gr group, struct obd_trans_info *oti)
2629 struct obd_device *obd = exp->exp_obd;
2630 struct filter_obd *filter = &obd->u.filter;
2634 /* delete orphans request */
2635 if ((oa->o_valid & OBD_MD_FLFLAGS) && (oa->o_flags & OBD_FL_DELORPHAN)){
2636 /* This causes inflight precreates to abort and drop lock */
2637 filter->fo_destroy_in_progress = 1;
2638 down(&filter->fo_create_lock);
2639 diff = oa->o_id - filter_last_id(filter, group);
2640 CDEBUG(D_HA, "filter_last_id() = "LPU64" -> diff = %d\n",
2641 filter_last_id(filter, group), diff);
2643 if (-diff > OST_MAX_PRECREATE) {
2644 CERROR("%s: ignoring bogus orphan destroy request: "
2645 "obdid "LPU64" last_id "LPU64"\n", obd->obd_name,
2646 oa->o_id, filter_last_id(filter, group));
2647 /* FIXME: should reset precreate_next_id on MDS */
2648 GOTO(out, rc = -EINVAL);
2651 rc = filter_destroy_precreated(exp, oa, filter);
2653 CERROR("%s: unable to write lastobjid, but "
2654 "orphans were deleted\n", obd->obd_name);
2657 /*XXX used by MDS for the first time! */
2658 filter->fo_destroy_in_progress = 0;
2661 down(&filter->fo_create_lock);
2662 if (oti->oti_conn_cnt < exp->exp_conn_cnt) {
2663 CERROR("%s: dropping old precreate request\n",
2667 /* only precreate if group == 0 and o_id is specfied */
2668 if (group != 0 || oa->o_id == 0)
2671 diff = oa->o_id - filter_last_id(filter, group);
2672 CDEBUG(D_HA, "filter_last_id() = "LPU64" -> diff = %d\n",
2673 filter_last_id(filter, group), diff);
2675 LASSERTF(diff >= 0,"%s: "LPU64" - "LPU64" = %d\n",obd->obd_name,
2676 oa->o_id, filter_last_id(filter, group), diff);
2680 oa->o_id = filter_last_id(&obd->u.filter, group);
2681 rc = filter_precreate(obd, oa, group, &diff);
2682 oa->o_id = filter_last_id(&obd->u.filter, group);
2683 oa->o_valid = OBD_MD_FLID;
2686 /* else diff == 0 */
2689 up(&filter->fo_create_lock);
2693 static int filter_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2696 struct filter_obd *filter = &obd->u.filter;
2697 int blockbits = obd->u.obt.obt_sb->s_blocksize_bits;
2701 /* at least try to account for cached pages. its still racey and
2702 * might be under-reporting if clients haven't announced their
2703 * caches with brw recently */
2704 spin_lock(&obd->obd_osfs_lock);
2705 rc = fsfilt_statfs(obd, obd->u.obt.obt_sb, max_age);
2706 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
2707 spin_unlock(&obd->obd_osfs_lock);
2709 CDEBUG(D_SUPER | D_CACHE, "blocks cached "LPU64" granted "LPU64
2710 " pending "LPU64" free "LPU64" avail "LPU64"\n",
2711 filter->fo_tot_dirty, filter->fo_tot_granted,
2712 filter->fo_tot_pending,
2713 osfs->os_bfree << blockbits, osfs->os_bavail << blockbits);
2715 filter_grant_sanity_check(obd, __FUNCTION__);
2717 osfs->os_bavail -= min(osfs->os_bavail, GRANT_FOR_LLOG(obd) +
2718 ((filter->fo_tot_dirty + filter->fo_tot_pending +
2719 osfs->os_bsize - 1) >> blockbits));
2721 /* set EROFS to state field if FS is mounted as RDONLY. The goal is to
2722 * stop creating files on MDS if OST is not good shape to create
2724 osfs->os_state = (filter->fo_obt.obt_sb->s_flags & MS_RDONLY) ?
2729 /* We rely on the fact that only one thread will be creating files in a given
2730 * group at a time, which is why we don't need an atomic filter_get_new_id.
2731 * Even if we had that atomic function, the following race would exist:
2733 * thread 1: gets id x from filter_next_id
2734 * thread 2: gets id (x + 1) from filter_next_id
2735 * thread 2: creates object (x + 1)
2736 * thread 1: tries to create object x, gets -ENOSPC
2738 * Caller must hold fo_create_lock
2740 static int filter_precreate(struct obd_device *obd, struct obdo *oa,
2741 obd_gr group, int *num)
2743 struct dentry *dchild = NULL, *dparent = NULL;
2744 struct filter_obd *filter;
2745 struct obd_statfs *osfs;
2746 int err = 0, rc = 0, recreate_obj = 0, i;
2747 unsigned long enough_time = jiffies + (obd_timeout * HZ) / 4;
2749 void *handle = NULL;
2752 filter = &obd->u.filter;
2754 LASSERT(down_trylock(&filter->fo_create_lock) != 0);
2756 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
2757 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
2760 OBD_ALLOC(osfs, sizeof(*osfs));
2763 rc = filter_statfs(obd, osfs, cfs_time_current_64() - HZ);
2764 if (rc == 0 && osfs->os_bavail < (osfs->os_blocks >> 10)) {
2765 CDEBUG(D_HA, "OST out of space! avail "LPU64"\n",
2767 filter->fo_obt.obt_sb->s_blocksize_bits);
2771 OBD_FREE(osfs, sizeof(*osfs));
2776 CDEBUG(D_HA, "%s: precreating %d objects in group "LPU64" at "LPU64"\n",
2777 obd->obd_name, *num, group, oa->o_id);
2779 for (i = 0; i < *num && err == 0; i++) {
2780 int cleanup_phase = 0;
2782 if (filter->fo_destroy_in_progress) {
2783 CWARN("%s: precreate aborted by destroy\n",
2792 last_id = filter_last_id(filter, group);
2793 if (next_id > last_id) {
2794 CERROR("Error: Trying to recreate obj greater"
2795 "than last id "LPD64" > "LPD64"\n",
2797 GOTO(cleanup, rc = -EINVAL);
2800 next_id = filter_last_id(filter, group) + 1;
2802 CDEBUG(D_INFO, "precreate objid "LPU64"\n", next_id);
2804 dparent = filter_parent_lock(obd, group, next_id);
2805 if (IS_ERR(dparent))
2806 GOTO(cleanup, rc = PTR_ERR(dparent));
2809 dchild = filter_fid2dentry(obd, dparent, group, next_id);
2811 GOTO(cleanup, rc = PTR_ERR(dchild));
2814 if (dchild->d_inode != NULL) {
2815 /* This would only happen if lastobjid was bad on disk*/
2816 /* Could also happen if recreating missing obj but
2820 CERROR("%s: recreating existing object %.*s?\n",
2821 obd->obd_name, dchild->d_name.len,
2822 dchild->d_name.name);
2824 CERROR("%s: Serious error: objid %.*s already "
2825 "exists; is this filesystem corrupt?\n",
2826 obd->obd_name, dchild->d_name.len,
2827 dchild->d_name.name);
2830 GOTO(cleanup, rc = -EEXIST);
2833 handle = fsfilt_start_log(obd, dparent->d_inode,
2834 FSFILT_OP_CREATE, NULL, 1);
2836 GOTO(cleanup, rc = PTR_ERR(handle));
2839 /* We mark object SUID+SGID to flag it for accepting UID+GID
2840 * from client on first write. Currently the permission bits
2841 * on the OST are never used, so this is OK. */
2842 rc = ll_vfs_create(dparent->d_inode, dchild,
2843 S_IFREG | S_ISUID | S_ISGID | 0666, NULL);
2845 CERROR("create failed rc = %d\n", rc);
2849 if (!recreate_obj) {
2850 filter_set_last_id(filter, next_id, group);
2851 err = filter_update_last_objid(obd, group, 0);
2853 CERROR("unable to write lastobjid "
2854 "but file created\n");
2858 switch(cleanup_phase) {
2860 err = fsfilt_commit(obd, dparent->d_inode, handle, 0);
2862 CERROR("error on commit, err = %d\n", err);
2869 filter_parent_unlock(dparent);
2876 if (time_after(jiffies, enough_time)) {
2877 CDEBUG(D_HA, "%s: precreate slow - want %d got %d \n",
2878 obd->obd_name, *num, i);
2884 CDEBUG(D_HA, "%s: created %d objects for group "LPU64": "LPU64"\n",
2885 obd->obd_name, i, group, filter->fo_last_objids[group]);
2887 CDEBUG(D_HA, "%s: filter_precreate() created %d objects: rc %d\n",
2888 obd->obd_name, i, 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));
3004 /* we're gonna truncate it first in order to avoid possible deadlock:
3006 * open trasaction open transaction
3007 * down(i_zombie) down(i_zombie)
3008 * restart transaction
3009 * (see BUG 4180) -bzzz
3011 LOCK_INODE_MUTEX(dchild->d_inode);
3012 handle = fsfilt_start_log(obd, dchild->d_inode, FSFILT_OP_SETATTR,
3014 if (IS_ERR(handle)) {
3015 UNLOCK_INODE_MUTEX(dchild->d_inode);
3016 GOTO(cleanup, rc = PTR_ERR(handle));
3019 iattr.ia_valid = ATTR_SIZE;
3021 rc = fsfilt_setattr(obd, dchild, handle, &iattr, 1);
3022 rc2 = fsfilt_commit(obd, dchild->d_inode, handle, 0);
3023 UNLOCK_INODE_MUTEX(dchild->d_inode);
3027 GOTO(cleanup, rc = rc2);
3029 /* We don't actually need to lock the parent until we are unlinking
3030 * here, and not while truncating above. That avoids holding the
3031 * parent lock for a long time during truncate, which can block other
3032 * threads from doing anything to objects in that directory. bug 7171 */
3033 dparent = filter_parent_lock(obd, oa->o_gr, oa->o_id);
3034 if (IS_ERR(dparent))
3035 GOTO(cleanup, rc = PTR_ERR(dparent));
3036 cleanup_phase = 3; /* filter_parent_unlock */
3038 LOCK_INODE_MUTEX(dchild->d_inode);
3039 handle = fsfilt_start_log(obd, dparent->d_inode,FSFILT_OP_UNLINK,oti,1);
3040 if (IS_ERR(handle)) {
3041 UNLOCK_INODE_MUTEX(dchild->d_inode);
3042 GOTO(cleanup, rc = PTR_ERR(handle));
3044 cleanup_phase = 4; /* fsfilt_commit */
3046 /* Quota release need uid/gid of inode */
3047 obdo_from_inode(oa, dchild->d_inode, OBD_MD_FLUID|OBD_MD_FLGID);
3049 filter_fmd_drop(exp, oa->o_id, oa->o_gr);
3051 /* this drops dchild->d_inode->i_mutex unconditionally */
3052 rc = filter_destroy_internal(obd, oa->o_id, oa->o_gr, dparent, dchild);
3056 switch(cleanup_phase) {
3059 fsfilt_add_journal_cb(obd, 0,
3060 oti ? oti->oti_handle : handle,
3061 filter_cancel_cookies_cb, fcc);
3064 rc = filter_finish_transno(exp, oti, rc);
3065 rc2 = fsfilt_commit(obd, dparent->d_inode, handle, 0);
3067 CERROR("error on commit, err = %d\n", rc2);
3072 filter_parent_unlock(dparent);
3076 OBD_FREE(fcc, sizeof(*fcc));
3078 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3081 CERROR("invalid cleanup_phase %d\n", cleanup_phase);
3085 /* trigger quota release */
3086 qcids[USRQUOTA] = oa->o_uid;
3087 qcids[GRPQUOTA] = oa->o_gid;
3088 rc2 = lquota_adjust(quota_interface, obd, qcids, NULL, rc,
3091 CDEBUG(rc ? D_ERROR : D_QUOTA,
3092 "filter adjust qunit! (rc:%d)\n", rc2);
3096 /* NB start and end are used for punch, but not truncate */
3097 static int filter_truncate(struct obd_export *exp, struct obd_info *oinfo,
3098 struct obd_trans_info *oti,
3099 struct ptlrpc_request_set *rqset)
3104 if (oinfo->oi_policy.l_extent.end != OBD_OBJECT_EOF) {
3105 CERROR("PUNCH not supported, only truncate: end = "LPX64"\n",
3106 oinfo->oi_policy.l_extent.end);
3110 CDEBUG(D_INODE, "calling truncate for object "LPU64", valid = "LPX64
3111 ", o_size = "LPD64"\n", oinfo->oi_oa->o_id,
3112 oinfo->oi_oa->o_valid, oinfo->oi_policy.l_extent.start);
3114 oinfo->oi_oa->o_size = oinfo->oi_policy.l_extent.start;
3115 rc = filter_setattr(exp, oinfo, oti);
3119 static int filter_sync(struct obd_export *exp, struct obdo *oa,
3120 struct lov_stripe_md *lsm, obd_off start, obd_off end)
3122 struct lvfs_run_ctxt saved;
3123 struct filter_obd *filter;
3124 struct dentry *dentry;
3125 struct llog_ctxt *ctxt;
3129 filter = &exp->exp_obd->u.filter;
3131 /* an objid of zero is taken to mean "sync whole filesystem" */
3132 if (!oa || !(oa->o_valid & OBD_MD_FLID)) {
3133 rc = fsfilt_sync(exp->exp_obd, filter->fo_obt.obt_sb);
3134 /* flush any remaining cancel messages out to the target */
3135 ctxt = llog_get_context(exp->exp_obd, LLOG_MDS_OST_REPL_CTXT);
3136 llog_sync(ctxt, exp);
3140 dentry = filter_oa2dentry(exp->exp_obd, oa);
3142 RETURN(PTR_ERR(dentry));
3144 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
3146 LOCK_INODE_MUTEX(dentry->d_inode);
3148 rc = filemap_fdatawrite(dentry->d_inode->i_mapping);
3150 /* just any file to grab fsync method - "file" arg unused */
3151 struct file *file = filter->fo_rcvd_filp;
3153 if (file->f_op && file->f_op->fsync)
3154 rc = file->f_op->fsync(NULL, dentry, 1);
3156 rc2 = filemap_fdatawait(dentry->d_inode->i_mapping);
3160 UNLOCK_INODE_MUTEX(dentry->d_inode);
3162 oa->o_valid = OBD_MD_FLID;
3163 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
3165 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, NULL);
3171 static int filter_get_info(struct obd_export *exp, __u32 keylen,
3172 void *key, __u32 *vallen, void *val)
3174 struct obd_device *obd;
3177 obd = class_exp2obd(exp);
3179 CDEBUG(D_IOCTL, "invalid client export %p\n", exp);
3183 if (keylen == strlen("blocksize") &&
3184 memcmp(key, "blocksize", keylen) == 0) {
3185 __u32 *blocksize = val;
3186 *vallen = sizeof(*blocksize);
3187 *blocksize = obd->u.obt.obt_sb->s_blocksize;
3191 if (keylen == strlen("blocksize_bits") &&
3192 memcmp(key, "blocksize_bits", keylen) == 0) {
3193 __u32 *blocksize_bits = val;
3194 *vallen = sizeof(*blocksize_bits);
3195 *blocksize_bits = obd->u.obt.obt_sb->s_blocksize_bits;
3199 if (keylen >= strlen("last_id") && memcmp(key, "last_id", 7) == 0) {
3200 obd_id *last_id = val;
3201 /* FIXME: object groups */
3202 *last_id = filter_last_id(&obd->u.filter, 0);
3205 CDEBUG(D_IOCTL, "invalid key\n");
3209 static int filter_set_info_async(struct obd_export *exp, __u32 keylen,
3210 void *key, __u32 vallen, void *val,
3211 struct ptlrpc_request_set *set)
3213 struct obd_device *obd;
3214 struct llog_ctxt *ctxt;
3220 CDEBUG(D_IOCTL, "invalid export %p\n", exp);
3224 if (keylen < strlen(KEY_MDS_CONN) ||
3225 memcmp(key, KEY_MDS_CONN, keylen) != 0)
3228 LCONSOLE_WARN("%s: received MDS connection from %s\n", obd->obd_name,
3229 obd_export_nid2str(exp));
3230 obd->u.filter.fo_mdc_conn.cookie = exp->exp_handle.h_cookie;
3232 /* setup llog imports */
3233 ctxt = llog_get_context(obd, LLOG_MDS_OST_REPL_CTXT);
3234 rc = llog_receptor_accept(ctxt, exp->exp_imp_reverse);
3236 lquota_setinfo(quota_interface, exp, obd);
3241 int filter_iocontrol(unsigned int cmd, struct obd_export *exp,
3242 int len, void *karg, void *uarg)
3244 struct obd_device *obd = exp->exp_obd;
3245 struct obd_ioctl_data *data = karg;
3249 case OBD_IOC_ABORT_RECOVERY: {
3250 CERROR("aborting recovery for device %s\n", obd->obd_name);
3251 target_abort_recovery(obd);
3255 case OBD_IOC_SYNC: {
3256 CDEBUG(D_HA, "syncing ost %s\n", obd->obd_name);
3257 rc = fsfilt_sync(obd, obd->u.obt.obt_sb);
3261 case OBD_IOC_SET_READONLY: {
3263 struct super_block *sb = obd->u.obt.obt_sb;
3264 struct inode *inode = sb->s_root->d_inode;
3265 BDEVNAME_DECLARE_STORAGE(tmp);
3266 CERROR("*** setting device %s read-only ***\n",
3267 ll_bdevname(sb, tmp));
3269 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
3270 if (!IS_ERR(handle))
3271 rc = fsfilt_commit(obd, inode, handle, 1);
3273 CDEBUG(D_HA, "syncing ost %s\n", obd->obd_name);
3274 rc = fsfilt_sync(obd, obd->u.obt.obt_sb);
3276 lvfs_set_rdonly(lvfs_sbdev(obd->u.obt.obt_sb));
3280 case OBD_IOC_CATLOGLIST: {
3281 rc = llog_catalog_list(obd, 1, data);
3285 case OBD_IOC_LLOG_CANCEL:
3286 case OBD_IOC_LLOG_REMOVE:
3287 case OBD_IOC_LLOG_INFO:
3288 case OBD_IOC_LLOG_PRINT: {
3289 /* FIXME to be finished */
3290 RETURN(-EOPNOTSUPP);
3292 struct llog_ctxt *ctxt = NULL;
3294 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
3295 rc = llog_ioctl(ctxt, cmd, data);
3296 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
3309 static int filter_health_check(struct obd_device *obd)
3311 struct filter_obd *filter = &obd->u.filter;
3315 * health_check to return 0 on healthy
3316 * and 1 on unhealthy.
3318 if (obd->u.obt.obt_sb->s_flags & MS_RDONLY)
3321 LASSERT(filter->fo_health_check_filp != NULL);
3322 rc |= !!lvfs_check_io_health(obd, filter->fo_health_check_filp);
3327 static struct dentry *filter_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
3330 return filter_fid2dentry(data, NULL, gr, id);
3333 static int filter_process_config(struct obd_device *obd, obd_count len, void *buf)
3335 struct lustre_cfg *lcfg = buf;
3336 struct lprocfs_static_vars lvars;
3339 lprocfs_init_vars(filter, &lvars);
3341 rc = class_process_proc_param(PARAM_OST, lvars.obd_vars, lcfg, obd);
3345 static struct lvfs_callback_ops filter_lvfs_ops = {
3346 l_fid2dentry: filter_lvfs_fid2dentry,
3349 static struct obd_ops filter_obd_ops = {
3350 .o_owner = THIS_MODULE,
3351 .o_get_info = filter_get_info,
3352 .o_set_info_async = filter_set_info_async,
3353 .o_setup = filter_setup,
3354 .o_precleanup = filter_precleanup,
3355 .o_cleanup = filter_cleanup,
3356 .o_connect = filter_connect,
3357 .o_reconnect = filter_reconnect,
3358 .o_disconnect = filter_disconnect,
3359 .o_ping = filter_ping,
3360 .o_init_export = filter_init_export,
3361 .o_destroy_export = filter_destroy_export,
3362 .o_statfs = filter_statfs,
3363 .o_getattr = filter_getattr,
3364 .o_unpackmd = filter_unpackmd,
3365 .o_create = filter_create,
3366 .o_setattr = filter_setattr,
3367 .o_destroy = filter_destroy,
3368 .o_brw = filter_brw,
3369 .o_punch = filter_truncate,
3370 .o_sync = filter_sync,
3371 .o_preprw = filter_preprw,
3372 .o_commitrw = filter_commitrw,
3373 .o_llog_init = filter_llog_init,
3374 .o_llog_finish = filter_llog_finish,
3375 .o_iocontrol = filter_iocontrol,
3376 .o_health_check = filter_health_check,
3377 .o_process_config = filter_process_config,
3380 static struct obd_ops filter_sanobd_ops = {
3381 .o_owner = THIS_MODULE,
3382 .o_get_info = filter_get_info,
3383 .o_set_info_async = filter_set_info_async,
3384 .o_setup = filter_san_setup,
3385 .o_precleanup = filter_precleanup,
3386 .o_cleanup = filter_cleanup,
3387 .o_connect = filter_connect,
3388 .o_reconnect = filter_reconnect,
3389 .o_disconnect = filter_disconnect,
3390 .o_ping = filter_ping,
3391 .o_init_export = filter_init_export,
3392 .o_destroy_export = filter_destroy_export,
3393 .o_statfs = filter_statfs,
3394 .o_getattr = filter_getattr,
3395 .o_unpackmd = filter_unpackmd,
3396 .o_create = filter_create,
3397 .o_setattr = filter_setattr,
3398 .o_destroy = filter_destroy,
3399 .o_brw = filter_brw,
3400 .o_punch = filter_truncate,
3401 .o_sync = filter_sync,
3402 .o_preprw = filter_preprw,
3403 .o_commitrw = filter_commitrw,
3404 .o_san_preprw = filter_san_preprw,
3405 .o_llog_init = filter_llog_init,
3406 .o_llog_finish = filter_llog_finish,
3407 .o_iocontrol = filter_iocontrol,
3410 quota_interface_t *quota_interface;
3411 extern quota_interface_t filter_quota_interface;
3413 static int __init obdfilter_init(void)
3415 struct lprocfs_static_vars lvars;
3418 printk(KERN_INFO "Lustre: Filtering OBD driver; info@clusterfs.com\n");
3420 lprocfs_init_vars(filter, &lvars);
3422 OBD_ALLOC(obdfilter_created_scratchpad,
3423 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
3424 sizeof(*obdfilter_created_scratchpad));
3425 if (obdfilter_created_scratchpad == NULL)
3428 ll_fmd_cachep = kmem_cache_create("ll_fmd_cache",
3429 sizeof(struct filter_mod_data),
3432 GOTO(out, rc = -ENOMEM);
3434 quota_interface = PORTAL_SYMBOL_GET(filter_quota_interface);
3435 init_obd_quota_ops(quota_interface, &filter_obd_ops);
3436 init_obd_quota_ops(quota_interface, &filter_sanobd_ops);
3438 rc = class_register_type(&filter_obd_ops, NULL, lvars.module_vars,
3439 LUSTRE_OST_NAME, NULL);
3443 rc = class_register_type(&filter_sanobd_ops, NULL, lvars.module_vars,
3444 LUSTRE_OSTSAN_NAME, NULL);
3448 class_unregister_type(LUSTRE_OST_NAME);
3450 err = kmem_cache_destroy(ll_fmd_cachep);
3451 LASSERTF(err == 0, "Cannot destroy ll_fmd_cachep: rc %d\n",err);
3452 ll_fmd_cachep = NULL;
3454 if (quota_interface)
3455 PORTAL_SYMBOL_PUT(filter_quota_interface);
3457 OBD_FREE(obdfilter_created_scratchpad,
3458 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
3459 sizeof(*obdfilter_created_scratchpad));
3465 static void __exit obdfilter_exit(void)
3467 if (quota_interface)
3468 PORTAL_SYMBOL_PUT(filter_quota_interface);
3470 if (ll_fmd_cachep) {
3471 int rc = kmem_cache_destroy(ll_fmd_cachep);
3472 LASSERTF(rc == 0, "Cannot destroy ll_fmd_cachep: rc %d\n", rc);
3473 ll_fmd_cachep = NULL;
3476 class_unregister_type(LUSTRE_OSTSAN_NAME);
3477 class_unregister_type(LUSTRE_OST_NAME);
3478 OBD_FREE(obdfilter_created_scratchpad,
3479 OBDFILTER_CREATED_SCRATCHPAD_ENTRIES *
3480 sizeof(*obdfilter_created_scratchpad));
3483 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
3484 MODULE_DESCRIPTION("Lustre Filtering OBD driver");
3485 MODULE_LICENSE("GPL");
3487 module_init(obdfilter_init);
3488 module_exit(obdfilter_exit);