4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
39 * Author: Mike Pershin <tappro@whamcloud.com>
40 * Author: Johann Lombardi <johann@whamcloud.com>
43 * The OBD Filter Device (OFD) module belongs to the Object Storage
44 * Server stack and connects the RPC oriented Unified Target (TGT)
45 * layer (see lustre/include/lu_target.h) to the storage oriented OSD
46 * layer (see lustre/doc/osd-api.txt).
54 * OFD implements the LU and OBD device APIs and is responsible for:
56 * - Handling client requests (create, destroy, bulk IO, setattr,
57 * get_info, set_info, statfs) for the objects belonging to the OST
58 * (together with TGT).
60 * - Providing grant space management which allows clients to reserve
61 * disk space for data writeback. OFD tracks grants on global and
64 * - Handling object precreation requests from MDTs.
66 * - Operating the LDLM service that allows clients to maintain object
67 * data cache coherence.
70 #define DEBUG_SUBSYSTEM S_FILTER
72 #include <obd_class.h>
73 #include <lustre_param.h>
74 #include <lustre_fid.h>
75 #include <lustre_lfsck.h>
76 #include <lustre/lustre_idl.h>
77 #include <lustre_dlm.h>
78 #include <lustre_quota.h>
80 #include "ofd_internal.h"
82 /* Slab for OFD object allocation */
83 static struct kmem_cache *ofd_object_kmem;
85 static struct lu_kmem_descr ofd_caches[] = {
87 .ckd_cache = &ofd_object_kmem,
88 .ckd_name = "ofd_obj",
89 .ckd_size = sizeof(struct ofd_object)
96 static int ofd_connect_to_next(const struct lu_env *env, struct ofd_device *m,
97 const char *next, struct obd_export **exp)
99 struct obd_connect_data *data = NULL;
100 struct obd_device *obd;
106 GOTO(out, rc = -ENOMEM);
108 obd = class_name2obd(next);
110 CERROR("%s: can't locate next device: %s\n",
112 GOTO(out, rc = -ENOTCONN);
115 data->ocd_connect_flags = OBD_CONNECT_VERSION;
116 data->ocd_version = LUSTRE_VERSION_CODE;
118 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
120 CERROR("%s: cannot connect to next dev %s: rc = %d\n",
121 ofd_name(m), next, rc);
125 m->ofd_dt_dev.dd_lu_dev.ld_site =
126 m->ofd_osd_exp->exp_obd->obd_lu_dev->ld_site;
127 LASSERT(m->ofd_dt_dev.dd_lu_dev.ld_site);
128 m->ofd_osd = lu2dt_dev(m->ofd_osd_exp->exp_obd->obd_lu_dev);
129 m->ofd_dt_dev.dd_lu_dev.ld_site->ls_top_dev = &m->ofd_dt_dev.dd_lu_dev;
137 static int ofd_stack_init(const struct lu_env *env,
138 struct ofd_device *m, struct lustre_cfg *cfg)
140 const char *dev = lustre_cfg_string(cfg, 0);
142 struct ofd_thread_info *info = ofd_info(env);
143 struct lustre_mount_info *lmi;
149 lmi = server_get_mount(dev);
151 CERROR("Cannot get mount info for %s!\n", dev);
155 /* find bottom osd */
156 OBD_ALLOC(osdname, MTI_NAME_MAXLEN);
160 snprintf(osdname, MTI_NAME_MAXLEN, "%s-osd", dev);
161 rc = ofd_connect_to_next(env, m, osdname, &m->ofd_osd_exp);
162 OBD_FREE(osdname, MTI_NAME_MAXLEN);
166 d = m->ofd_osd_exp->exp_obd->obd_lu_dev;
168 m->ofd_osd = lu2dt_dev(d);
170 snprintf(info->fti_u.name, sizeof(info->fti_u.name),
171 "%s-osd", lustre_cfg_string(cfg, 0));
176 static void ofd_stack_fini(const struct lu_env *env, struct ofd_device *m,
177 struct lu_device *top)
179 struct obd_device *obd = ofd_obd(m);
180 struct lustre_cfg_bufs bufs;
181 struct lustre_cfg *lcfg;
186 lu_site_purge(env, top->ld_site, ~0);
187 /* process cleanup, pass mdt obd name to get obd umount flags */
188 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
193 lustre_cfg_bufs_set_string(&bufs, 1, flags);
194 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
196 CERROR("Cannot alloc lcfg!\n");
201 top->ld_ops->ldo_process_config(env, top, lcfg);
202 lustre_cfg_free(lcfg);
204 lu_site_purge(env, top->ld_site, ~0);
205 if (!cfs_hash_is_empty(top->ld_site->ls_obj_hash)) {
206 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
207 lu_site_print(env, top->ld_site, &msgdata, lu_cdebug_printer);
210 LASSERT(m->ofd_osd_exp);
211 obd_disconnect(m->ofd_osd_exp);
216 /* For interoperability, see mdt_interop_param[]. */
217 static struct cfg_interop_param ofd_interop_param[] = {
218 { "ost.quota_type", NULL },
222 /* Some parameters were moved from ofd to osd and only their
223 * symlinks were kept in ofd by LU-3106. They are:
224 * -writehthrough_cache_enable
225 * -readcache_max_filese
228 * Since they are not included by the static lprocfs var list,
229 * a pre-check is added for them to avoid "unknown param" error
230 * message confuses the customer. If they are matched in this
231 * check, they will be passed to the osd directly.
233 static bool match_symlink_param(char *param)
238 if (class_match_param(param, PARAM_OST, ¶m) == 0) {
239 sval = strchr(param, '=');
241 paramlen = sval - param;
242 if (strncmp(param, "writethrough_cache_enable",
244 strncmp(param, "readcache_max_filesize",
246 strncmp(param, "read_cache_enable",
248 strncmp(param, "brw_stats", paramlen) == 0)
256 /* used by MGS to process specific configurations */
257 static int ofd_process_config(const struct lu_env *env, struct lu_device *d,
258 struct lustre_cfg *cfg)
260 struct ofd_device *m = ofd_dev(d);
261 struct dt_device *dt_next = m->ofd_osd;
262 struct lu_device *next = &dt_next->dd_lu_dev;
267 switch (cfg->lcfg_command) {
269 struct obd_device *obd = ofd_obd(m);
270 /* For interoperability */
271 struct cfg_interop_param *ptr = NULL;
272 struct lustre_cfg *old_cfg = NULL;
275 param = lustre_cfg_string(cfg, 1);
277 CERROR("param is empty\n");
282 ptr = class_find_old_param(param, ofd_interop_param);
284 if (ptr->new_param == NULL) {
286 CWARN("For interoperability, skip this %s."
287 " It is obsolete.\n", ptr->old_param);
291 CWARN("Found old param %s, changed it to %s.\n",
292 ptr->old_param, ptr->new_param);
295 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
302 if (match_symlink_param(param)) {
303 rc = next->ld_ops->ldo_process_config(env, next, cfg);
307 rc = class_process_proc_seq_param(PARAM_OST, obd->obd_vars, cfg,
309 if (rc > 0 || rc == -ENOSYS) {
310 CDEBUG(D_CONFIG, "pass param %s down the stack.\n",
312 /* we don't understand; pass it on */
313 rc = next->ld_ops->ldo_process_config(env, next, cfg);
317 case LCFG_SPTLRPC_CONF: {
322 /* others are passed further */
323 rc = next->ld_ops->ldo_process_config(env, next, cfg);
329 static int ofd_object_init(const struct lu_env *env, struct lu_object *o,
330 const struct lu_object_conf *conf)
332 struct ofd_device *d = ofd_dev(o->lo_dev);
333 struct lu_device *under;
334 struct lu_object *below;
339 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
340 PFID(lu_object_fid(o)));
342 under = &d->ofd_osd->dd_lu_dev;
343 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
345 lu_object_add(o, below);
352 static void ofd_object_free(const struct lu_env *env, struct lu_object *o)
354 struct ofd_object *of = ofd_obj(o);
355 struct lu_object_header *h;
360 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
361 PFID(lu_object_fid(o)));
364 lu_object_header_fini(h);
365 OBD_SLAB_FREE_PTR(of, ofd_object_kmem);
369 static int ofd_object_print(const struct lu_env *env, void *cookie,
370 lu_printer_t p, const struct lu_object *o)
372 return (*p)(env, cookie, LUSTRE_OST_NAME"-object@%p", o);
375 struct lu_object_operations ofd_obj_ops = {
376 .loo_object_init = ofd_object_init,
377 .loo_object_free = ofd_object_free,
378 .loo_object_print = ofd_object_print
381 static struct lu_object *ofd_object_alloc(const struct lu_env *env,
382 const struct lu_object_header *hdr,
385 struct ofd_object *of;
389 OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, GFP_NOFS);
392 struct lu_object_header *h;
394 o = &of->ofo_obj.do_lu;
396 lu_object_header_init(h);
397 lu_object_init(o, h, d);
398 lu_object_add_top(h, o);
399 o->lo_ops = &ofd_obj_ops;
406 extern int ost_handle(struct ptlrpc_request *req);
408 static int ofd_lfsck_out_notify(const struct lu_env *env, void *data,
409 enum lfsck_events event)
411 struct ofd_device *ofd = data;
412 struct obd_device *obd = ofd_obd(ofd);
415 case LE_LASTID_REBUILDING:
416 CWARN("%s: Found crashed LAST_ID, deny creating new OST-object "
417 "on the device until the LAST_ID rebuilt successfully.\n",
419 down_write(&ofd->ofd_lastid_rwsem);
420 ofd->ofd_lastid_rebuilding = 1;
421 up_write(&ofd->ofd_lastid_rwsem);
423 case LE_LASTID_REBUILT: {
424 down_write(&ofd->ofd_lastid_rwsem);
425 ofd_seqs_free(env, ofd);
426 ofd->ofd_lastid_rebuilding = 0;
427 ofd->ofd_lastid_gen++;
428 up_write(&ofd->ofd_lastid_rwsem);
432 CERROR("%s: unknown lfsck event: rc = %d\n",
433 ofd_name(ofd), event);
440 static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev,
441 struct lu_device *dev)
443 struct ofd_thread_info *info;
444 struct ofd_device *ofd = ofd_dev(dev);
445 struct obd_device *obd = ofd_obd(ofd);
446 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
451 info = ofd_info_init(env, NULL);
455 /* initialize lower device */
456 rc = next->ld_ops->ldo_prepare(env, dev, next);
460 rc = lfsck_register(env, ofd->ofd_osd, ofd->ofd_osd, obd,
461 ofd_lfsck_out_notify, ofd, false);
463 CERROR("%s: failed to initialize lfsck: rc = %d\n",
468 rc = lfsck_register_namespace(env, ofd->ofd_osd, ofd->ofd_namespace);
469 /* The LFSCK instance is registered just now, so it must be there when
470 * register the namespace to such instance. */
471 LASSERTF(rc == 0, "register namespace failed: rc = %d\n", rc);
473 target_recovery_init(&ofd->ofd_lut, tgt_request_handle);
474 LASSERT(obd->obd_no_conn);
475 spin_lock(&obd->obd_dev_lock);
476 obd->obd_no_conn = 0;
477 spin_unlock(&obd->obd_dev_lock);
479 if (obd->obd_recovering == 0)
480 ofd_postrecov(env, ofd);
485 static int ofd_recovery_complete(const struct lu_env *env,
486 struct lu_device *dev)
488 struct ofd_device *ofd = ofd_dev(dev);
489 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
490 int rc = 0, max_precreate;
494 /* Grant space for object precreation on the self export.
495 * This initial reserved space (i.e. 10MB for zfs and 280KB for ldiskfs)
496 * is enough to create 10k objects. More space is then acquired for
497 * precreation in ofd_grant_create().
499 max_precreate = OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace / 2;
500 ofd_grant_connect(env, dev->ld_obd->obd_self_export, max_precreate,
502 rc = next->ld_ops->ldo_recovery_complete(env, next);
506 static struct lu_device_operations ofd_lu_ops = {
507 .ldo_object_alloc = ofd_object_alloc,
508 .ldo_process_config = ofd_process_config,
509 .ldo_recovery_complete = ofd_recovery_complete,
510 .ldo_prepare = ofd_prepare,
513 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
515 static int ofd_procfs_init(struct ofd_device *ofd)
517 struct obd_device *obd = ofd_obd(ofd);
518 cfs_proc_dir_entry_t *entry;
523 /* lprocfs must be setup before the ofd so state can be safely added
524 * to /proc incrementally as the ofd is setup */
525 obd->obd_vars = lprocfs_ofd_obd_vars;
526 rc = lprocfs_seq_obd_setup(obd);
528 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
533 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
535 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
537 GOTO(obd_cleanup, rc);
540 obd->obd_uses_nid_stats = 1;
542 entry = lprocfs_seq_register("exports", obd->obd_proc_entry, NULL,
546 CERROR("%s: error %d setting up lprocfs for %s\n",
547 obd->obd_name, rc, "exports");
548 GOTO(obd_cleanup, rc);
550 obd->obd_proc_exports_entry = entry;
552 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
553 #ifndef HAVE_ONLY_PROCFS_SEQ
556 obd, &lprocfs_nid_stats_clear_fops);
559 CERROR("%s: add proc entry 'clear' failed: %d.\n",
561 GOTO(obd_cleanup, rc);
564 ofd_stats_counter_init(obd->obd_stats);
566 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
567 ofd_stats_counter_init);
569 GOTO(obd_cleanup, rc);
572 lprocfs_obd_cleanup(obd);
573 lprocfs_free_obd_stats(obd);
579 * ofd_procfs_add_brw_stats_symlink - expose osd stats to ofd layer
581 * The osd interfaces to the backend file system exposes useful data
582 * such as brw_stats and read or write cache states. This same data
583 * needs to be exposed into the obdfilter (ofd) layer to maintain
584 * backwards compatibility. This function creates the symlinks in the
585 * proc layer to enable this.
587 static void ofd_procfs_add_brw_stats_symlink(struct ofd_device *ofd)
589 struct obd_device *obd = ofd_obd(ofd);
590 struct obd_device *osd_obd = ofd->ofd_osd_exp->exp_obd;
592 if (obd->obd_proc_entry == NULL)
595 lprocfs_add_symlink("brw_stats", obd->obd_proc_entry,
596 "../../%s/%s/brw_stats",
597 osd_obd->obd_type->typ_name, obd->obd_name);
599 lprocfs_add_symlink("read_cache_enable", obd->obd_proc_entry,
600 "../../%s/%s/read_cache_enable",
601 osd_obd->obd_type->typ_name, obd->obd_name);
603 lprocfs_add_symlink("readcache_max_filesize",
605 "../../%s/%s/readcache_max_filesize",
606 osd_obd->obd_type->typ_name, obd->obd_name);
608 lprocfs_add_symlink("writethrough_cache_enable",
610 "../../%s/%s/writethrough_cache_enable",
611 osd_obd->obd_type->typ_name, obd->obd_name);
614 static void ofd_procfs_fini(struct ofd_device *ofd)
616 struct obd_device *obd = ofd_obd(ofd);
618 lprocfs_free_per_client_stats(obd);
619 lprocfs_obd_cleanup(obd);
620 lprocfs_free_obd_stats(obd);
621 lprocfs_job_stats_fini(obd);
624 extern int ost_handle(struct ptlrpc_request *req);
626 int ofd_fid_fini(const struct lu_env *env, struct ofd_device *ofd)
628 return seq_site_fini(env, &ofd->ofd_seq_site);
631 int ofd_fid_init(const struct lu_env *env, struct ofd_device *ofd)
633 struct seq_server_site *ss = &ofd->ofd_seq_site;
634 struct lu_device *lu = &ofd->ofd_dt_dev.dd_lu_dev;
635 char *obd_name = ofd_name(ofd);
639 ss = &ofd->ofd_seq_site;
640 lu->ld_site->ld_seq_site = ss;
641 ss->ss_lu = lu->ld_site;
642 ss->ss_node_id = ofd->ofd_lut.lut_lsd.lsd_osd_index;
644 OBD_ALLOC_PTR(ss->ss_server_seq);
645 if (ss->ss_server_seq == NULL)
646 GOTO(out_free, rc = -ENOMEM);
648 OBD_ALLOC(name, strlen(obd_name) + 10);
650 OBD_FREE_PTR(ss->ss_server_seq);
651 ss->ss_server_seq = NULL;
652 GOTO(out_free, rc = -ENOMEM);
655 rc = seq_server_init(env, ss->ss_server_seq, ofd->ofd_osd, obd_name,
656 LUSTRE_SEQ_SERVER, ss);
658 CERROR("%s : seq server init error %d\n", obd_name, rc);
661 ss->ss_server_seq->lss_space.lsr_index = ss->ss_node_id;
663 OBD_ALLOC_PTR(ss->ss_client_seq);
664 if (ss->ss_client_seq == NULL)
665 GOTO(out_free, rc = -ENOMEM);
667 snprintf(name, strlen(obd_name) + 6, "%p-super", obd_name);
668 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_DATA,
671 CERROR("%s : seq client init error %d\n", obd_name, rc);
674 OBD_FREE(name, strlen(obd_name) + 10);
677 rc = seq_server_set_cli(env, ss->ss_server_seq, ss->ss_client_seq);
681 if (ss->ss_server_seq) {
682 seq_server_fini(ss->ss_server_seq, env);
683 OBD_FREE_PTR(ss->ss_server_seq);
684 ss->ss_server_seq = NULL;
687 if (ss->ss_client_seq) {
688 seq_client_fini(ss->ss_client_seq);
689 OBD_FREE_PTR(ss->ss_client_seq);
690 ss->ss_client_seq = NULL;
694 OBD_FREE(name, strlen(obd_name) + 10);
702 int ofd_set_info_hdl(struct tgt_session_info *tsi)
704 struct ptlrpc_request *req = tgt_ses_req(tsi);
705 struct ost_body *body = NULL, *repbody;
706 void *key, *val = NULL;
707 int keylen, vallen, rc = 0;
708 bool is_grant_shrink;
709 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
713 key = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_KEY);
715 DEBUG_REQ(D_HA, req, "no set_info key");
716 RETURN(err_serious(-EFAULT));
718 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_KEY,
721 val = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_VAL);
723 DEBUG_REQ(D_HA, req, "no set_info val");
724 RETURN(err_serious(-EFAULT));
726 vallen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_VAL,
729 is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK);
731 /* In this case the value is actually an RMF_OST_BODY, so we
732 * transmutate the type of this PTLRPC */
733 req_capsule_extend(tsi->tsi_pill, &RQF_OST_SET_GRANT_INFO);
735 rc = req_capsule_server_pack(tsi->tsi_pill);
739 if (is_grant_shrink) {
740 body = req_capsule_client_get(tsi->tsi_pill, &RMF_OST_BODY);
742 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
745 /** handle grant shrink, similar to a read request */
746 ofd_grant_prepare_read(tsi->tsi_env, tsi->tsi_exp,
748 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
750 obd_export_evict_by_nid(tsi->tsi_exp->exp_obd, val);
752 } else if (KEY_IS(KEY_CAPA_KEY)) {
753 rc = ofd_update_capa_key(ofd, val);
754 } else if (KEY_IS(KEY_SPTLRPC_CONF)) {
755 rc = tgt_adapt_sptlrpc_conf(tsi->tsi_tgt, 0);
757 CERROR("%s: Unsupported key %s\n",
758 tgt_name(tsi->tsi_tgt), (char *)key);
761 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SET_INFO,
767 int ofd_fiemap_get(const struct lu_env *env, struct ofd_device *ofd,
768 struct lu_fid *fid, struct ll_user_fiemap *fiemap)
770 struct ofd_object *fo;
773 fo = ofd_object_find(env, ofd, fid);
775 CERROR("%s: error finding object "DFID"\n",
776 ofd_name(ofd), PFID(fid));
780 ofd_read_lock(env, fo);
781 if (ofd_object_exists(fo))
782 rc = dt_fiemap_get(env, ofd_object_child(fo), fiemap);
785 ofd_read_unlock(env, fo);
786 ofd_object_put(env, fo);
790 struct locked_region {
791 struct list_head list;
792 struct lustre_handle lh;
795 static int lock_region(struct ldlm_namespace *ns, struct ldlm_res_id *res_id,
796 unsigned long long begin, unsigned long long end,
797 struct list_head *locked)
799 struct locked_region *region = NULL;
803 LASSERT(begin <= end);
804 OBD_ALLOC_PTR(region);
808 rc = tgt_extent_lock(ns, res_id, begin, end, ®ion->lh,
813 CDEBUG(D_OTHER, "ost lock [%llu,%llu], lh=%p\n", begin, end,
815 list_add(®ion->list, locked);
820 static int lock_zero_regions(struct ldlm_namespace *ns,
821 struct ldlm_res_id *res_id,
822 struct ll_user_fiemap *fiemap,
823 struct list_head *locked)
825 __u64 begin = fiemap->fm_start;
828 struct ll_fiemap_extent *fiemap_start = fiemap->fm_extents;
832 CDEBUG(D_OTHER, "extents count %u\n", fiemap->fm_mapped_extents);
833 for (i = 0; i < fiemap->fm_mapped_extents; i++) {
834 if (fiemap_start[i].fe_logical > begin) {
835 CDEBUG(D_OTHER, "ost lock [%llu,%llu]\n",
836 begin, fiemap_start[i].fe_logical);
837 rc = lock_region(ns, res_id, begin,
838 fiemap_start[i].fe_logical, locked);
843 begin = fiemap_start[i].fe_logical + fiemap_start[i].fe_length;
846 if (begin < (fiemap->fm_start + fiemap->fm_length)) {
847 CDEBUG(D_OTHER, "ost lock [%llu,%llu]\n",
848 begin, fiemap->fm_start + fiemap->fm_length);
849 rc = lock_region(ns, res_id, begin,
850 fiemap->fm_start + fiemap->fm_length, locked);
857 unlock_zero_regions(struct ldlm_namespace *ns, struct list_head *locked)
859 struct locked_region *entry, *temp;
861 list_for_each_entry_safe(entry, temp, locked, list) {
862 CDEBUG(D_OTHER, "ost unlock lh=%p\n", &entry->lh);
863 tgt_extent_unlock(&entry->lh, LCK_PR);
864 list_del(&entry->list);
869 int ofd_get_info_hdl(struct tgt_session_info *tsi)
871 struct obd_export *exp = tsi->tsi_exp;
872 struct ofd_device *ofd = ofd_exp(exp);
873 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
876 int replylen, rc = 0;
880 /* this common part for get_info rpc */
881 key = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_KEY);
883 DEBUG_REQ(D_HA, tgt_ses_req(tsi), "no get_info key");
884 RETURN(err_serious(-EPROTO));
886 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_GETINFO_KEY,
889 if (KEY_IS(KEY_LAST_ID)) {
891 struct ofd_seq *oseq;
893 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_LAST_ID);
894 rc = req_capsule_server_pack(tsi->tsi_pill);
896 RETURN(err_serious(rc));
898 last_id = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_ID);
900 oseq = ofd_seq_load(tsi->tsi_env, ofd,
901 (obd_seq)exp->exp_filter_data.fed_group);
905 *last_id = ofd_seq_last_oid(oseq);
906 ofd_seq_put(tsi->tsi_env, oseq);
907 } else if (KEY_IS(KEY_FIEMAP)) {
908 struct ll_fiemap_info_key *fm_key;
909 struct ll_user_fiemap *fiemap;
912 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_FIEMAP);
914 fm_key = req_capsule_client_get(tsi->tsi_pill, &RMF_FIEMAP_KEY);
915 rc = tgt_validate_obdo(tsi, &fm_key->oa);
917 RETURN(err_serious(rc));
919 fid = &fm_key->oa.o_oi.oi_fid;
921 CDEBUG(D_INODE, "get FIEMAP of object "DFID"\n", PFID(fid));
923 replylen = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
924 req_capsule_set_size(tsi->tsi_pill, &RMF_FIEMAP_VAL,
925 RCL_SERVER, replylen);
927 rc = req_capsule_server_pack(tsi->tsi_pill);
929 RETURN(err_serious(rc));
931 fiemap = req_capsule_server_get(tsi->tsi_pill, &RMF_FIEMAP_VAL);
935 *fiemap = fm_key->fiemap;
936 rc = ofd_fiemap_get(tsi->tsi_env, ofd, fid, fiemap);
938 /* LU-3219: Lock the sparse areas to make sure dirty
939 * flushed back from client, then call fiemap again. */
940 if (fm_key->oa.o_valid & OBD_MD_FLFLAGS &&
941 fm_key->oa.o_flags & OBD_FL_SRVLOCK) {
942 struct list_head locked;
944 INIT_LIST_HEAD(&locked);
945 ost_fid_build_resid(fid, &fti->fti_resid);
946 rc = lock_zero_regions(ofd->ofd_namespace,
947 &fti->fti_resid, fiemap,
949 if (rc == 0 && !list_empty(&locked)) {
950 rc = ofd_fiemap_get(tsi->tsi_env, ofd, fid,
952 unlock_zero_regions(ofd->ofd_namespace,
956 } else if (KEY_IS(KEY_LAST_FID)) {
957 struct ofd_device *ofd = ofd_exp(exp);
958 struct ofd_seq *oseq;
962 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_LAST_FID);
963 rc = req_capsule_server_pack(tsi->tsi_pill);
965 RETURN(err_serious(rc));
967 fid = req_capsule_client_get(tsi->tsi_pill, &RMF_FID);
969 RETURN(err_serious(-EPROTO));
971 fid_le_to_cpu(&fti->fti_ostid.oi_fid, fid);
973 fid = req_capsule_server_get(tsi->tsi_pill, &RMF_FID);
977 oseq = ofd_seq_load(tsi->tsi_env, ofd,
978 ostid_seq(&fti->fti_ostid));
980 RETURN(PTR_ERR(oseq));
982 rc = ostid_to_fid(fid, &oseq->os_oi,
983 ofd->ofd_lut.lut_lsd.lsd_osd_index);
987 CDEBUG(D_HA, "%s: LAST FID is "DFID"\n", ofd_name(ofd),
990 ofd_seq_put(tsi->tsi_env, oseq);
992 CERROR("%s: not supported key %s\n", tgt_name(tsi->tsi_tgt),
996 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_GET_INFO,
1002 static int ofd_getattr_hdl(struct tgt_session_info *tsi)
1004 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1005 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1006 struct ost_body *repbody;
1007 struct lustre_handle lh = { 0 };
1008 struct ofd_object *fo;
1010 ldlm_mode_t lock_mode = LCK_PR;
1015 LASSERT(tsi->tsi_ost_body != NULL);
1017 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1018 if (repbody == NULL)
1021 repbody->oa.o_oi = tsi->tsi_ost_body->oa.o_oi;
1022 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1024 srvlock = tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLFLAGS &&
1025 tsi->tsi_ost_body->oa.o_flags & OBD_FL_SRVLOCK;
1028 if (unlikely(tsi->tsi_ost_body->oa.o_flags & OBD_FL_FLUSH))
1031 rc = tgt_extent_lock(tsi->tsi_tgt->lut_obd->obd_namespace,
1032 &tsi->tsi_resid, 0, OBD_OBJECT_EOF, &lh,
1038 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1040 GOTO(out, rc = PTR_ERR(fo));
1042 rc = ofd_attr_get(tsi->tsi_env, fo, &fti->fti_attr);
1046 obdo_from_la(&repbody->oa, &fti->fti_attr,
1047 OFD_VALID_FLAGS | LA_UID | LA_GID);
1048 tgt_drop_id(tsi->tsi_exp, &repbody->oa);
1050 /* Store object version in reply */
1051 curr_version = dt_version_get(tsi->tsi_env,
1052 ofd_object_child(fo));
1053 if ((__s64)curr_version != -EOPNOTSUPP) {
1054 repbody->oa.o_valid |= OBD_MD_FLDATAVERSION;
1055 repbody->oa.o_data_version = curr_version;
1059 ofd_object_put(tsi->tsi_env, fo);
1062 tgt_extent_unlock(&lh, lock_mode);
1064 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_GETATTR,
1067 repbody->oa.o_valid |= OBD_MD_FLFLAGS;
1068 repbody->oa.o_flags = OBD_FL_FLUSH;
1073 static int ofd_setattr_hdl(struct tgt_session_info *tsi)
1075 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1076 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1077 struct ost_body *body = tsi->tsi_ost_body;
1078 struct ost_body *repbody;
1079 struct ldlm_resource *res;
1080 struct ofd_object *fo;
1081 struct filter_fid *ff = NULL;
1086 LASSERT(body != NULL);
1088 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1089 if (repbody == NULL)
1092 repbody->oa.o_oi = body->oa.o_oi;
1093 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1095 /* This would be very bad - accidentally truncating a file when
1096 * changing the time or similar - bug 12203. */
1097 if (body->oa.o_valid & OBD_MD_FLSIZE &&
1098 body->oa.o_size != OBD_OBJECT_EOF) {
1099 static char mdsinum[48];
1101 if (body->oa.o_valid & OBD_MD_FLFID)
1102 snprintf(mdsinum, sizeof(mdsinum) - 1,
1103 "of parent "DFID, body->oa.o_parent_seq,
1104 body->oa.o_parent_oid, 0);
1108 CERROR("%s: setattr from %s is trying to truncate object "DFID
1109 " %s\n", ofd_name(ofd), obd_export_nid2str(tsi->tsi_exp),
1110 PFID(&tsi->tsi_fid), mdsinum);
1114 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1116 GOTO(out, rc = PTR_ERR(fo));
1118 la_from_obdo(&fti->fti_attr, &body->oa, body->oa.o_valid);
1119 fti->fti_attr.la_valid &= ~LA_TYPE;
1121 if (body->oa.o_valid & OBD_MD_FLFID) {
1122 ff = &fti->fti_mds_fid;
1123 ofd_prepare_fidea(ff, &body->oa);
1126 /* setting objects attributes (including owner/group) */
1127 rc = ofd_attr_set(tsi->tsi_env, fo, &fti->fti_attr, ff);
1131 obdo_from_la(&repbody->oa, &fti->fti_attr,
1132 OFD_VALID_FLAGS | LA_UID | LA_GID);
1133 tgt_drop_id(tsi->tsi_exp, &repbody->oa);
1135 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SETATTR,
1139 ofd_object_put(tsi->tsi_env, fo);
1142 /* we do not call this before to avoid lu_object_find() in
1143 * ->lvbo_update() holding another reference on the object.
1144 * otherwise concurrent destroy can make the object unavailable
1145 * for 2nd lu_object_find() waiting for the first reference
1146 * to go... deadlock! */
1147 res = ldlm_resource_get(ofd->ofd_namespace, NULL,
1148 &tsi->tsi_resid, LDLM_EXTENT, 0);
1150 ldlm_res_lvbo_update(res, NULL, 0);
1151 ldlm_resource_putref(res);
1157 static int ofd_orphans_destroy(const struct lu_env *env,
1158 struct obd_export *exp,
1159 struct ofd_device *ofd, struct obdo *oa)
1161 struct ofd_thread_info *info = ofd_info(env);
1162 struct lu_fid *fid = &info->fti_fid;
1163 struct ost_id *oi = &oa->o_oi;
1164 struct ofd_seq *oseq;
1165 obd_seq seq = ostid_seq(oi);
1166 obd_id end_id = ostid_id(oi);
1174 oseq = ofd_seq_get(ofd, seq);
1176 CERROR("%s: Can not find seq for "DOSTID"\n",
1177 ofd_name(ofd), POSTID(oi));
1182 last = ofd_seq_last_oid(oseq);
1185 LASSERT(exp != NULL);
1186 skip_orphan = !!(exp_connect_flags(exp) & OBD_CONNECT_SKIP_ORPHAN);
1188 if (OBD_FAIL_CHECK(OBD_FAIL_OST_NODESTROY))
1191 LCONSOLE(D_INFO, "%s: deleting orphan objects from "DOSTID
1192 " to "DOSTID"\n", ofd_name(ofd), seq, end_id + 1, seq, last);
1194 while (oid > end_id) {
1195 rc = fid_set_id(fid, oid);
1196 if (unlikely(rc != 0))
1199 rc = ofd_destroy_by_fid(env, ofd, fid, 1);
1200 if (rc != 0 && rc != -ENOENT && rc != -ESTALE &&
1201 likely(rc != -EREMCHG && rc != -EINPROGRESS))
1202 /* this is pretty fatal... */
1203 CEMERG("%s: error destroying precreated id "
1205 ofd_name(ofd), PFID(fid), rc);
1209 ofd_seq_last_oid_set(oseq, oid);
1210 /* update last_id on disk periodically so that if we
1211 * restart * we don't need to re-scan all of the just
1212 * deleted objects. */
1213 if ((oid & 511) == 0)
1214 ofd_seq_last_oid_write(env, ofd, oseq);
1218 CDEBUG(D_HA, "%s: after destroy: set last_id to "DOSTID"\n",
1219 ofd_name(ofd), seq, oid);
1223 ofd_seq_last_oid_set(oseq, oid);
1224 rc = ofd_seq_last_oid_write(env, ofd, oseq);
1226 /* don't reuse orphan object, return last used objid */
1227 ostid_set_id(oi, last);
1234 ofd_seq_put(env, oseq);
1238 static int ofd_create_hdl(struct tgt_session_info *tsi)
1240 struct ptlrpc_request *req = tgt_ses_req(tsi);
1241 struct ost_body *repbody;
1242 const struct obdo *oa = &tsi->tsi_ost_body->oa;
1243 struct obdo *rep_oa;
1244 struct obd_export *exp = tsi->tsi_exp;
1245 struct ofd_device *ofd = ofd_exp(exp);
1246 obd_seq seq = ostid_seq(&oa->o_oi);
1247 obd_id oid = ostid_id(&oa->o_oi);
1248 struct ofd_seq *oseq;
1254 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1257 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1258 if (repbody == NULL)
1261 down_read(&ofd->ofd_lastid_rwsem);
1262 /* Currently, for safe, we do not distinguish which LAST_ID is broken,
1263 * we may do that in the future.
1264 * Return -ENOSPC until the LAST_ID rebuilt. */
1265 if (unlikely(ofd->ofd_lastid_rebuilding))
1266 GOTO(out_sem, rc = -ENOSPC);
1268 rep_oa = &repbody->oa;
1269 rep_oa->o_oi = oa->o_oi;
1271 LASSERT(seq >= FID_SEQ_OST_MDT0);
1272 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
1274 CDEBUG(D_INFO, "ofd_create("DOSTID")\n", POSTID(&oa->o_oi));
1276 oseq = ofd_seq_load(tsi->tsi_env, ofd, seq);
1278 CERROR("%s: Can't find FID Sequence "LPX64": rc = %ld\n",
1279 ofd_name(ofd), seq, PTR_ERR(oseq));
1280 GOTO(out_sem, rc = -EINVAL);
1283 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1284 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1285 if (!ofd_obd(ofd)->obd_recovering ||
1286 oid > ofd_seq_last_oid(oseq)) {
1287 CERROR("%s: recreate objid "DOSTID" > last id "LPU64
1288 "\n", ofd_name(ofd), POSTID(&oa->o_oi),
1289 ofd_seq_last_oid(oseq));
1290 GOTO(out_nolock, rc = -EINVAL);
1292 /* Do nothing here, we re-create objects during recovery
1293 * upon write replay, see ofd_preprw_write() */
1294 GOTO(out_nolock, rc = 0);
1296 /* former ofd_handle_precreate */
1297 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1298 (oa->o_flags & OBD_FL_DELORPHAN)) {
1299 exp->exp_filter_data.fed_lastid_gen = ofd->ofd_lastid_gen;
1301 /* destroy orphans */
1302 if (lustre_msg_get_conn_cnt(tgt_ses_req(tsi)->rq_reqmsg) <
1303 exp->exp_conn_cnt) {
1304 CERROR("%s: dropping old orphan cleanup request\n",
1306 GOTO(out_nolock, rc = 0);
1308 /* This causes inflight precreates to abort and drop lock */
1309 oseq->os_destroys_in_progress = 1;
1310 mutex_lock(&oseq->os_create_lock);
1311 if (!oseq->os_destroys_in_progress) {
1312 CERROR("%s:["LPU64"] destroys_in_progress already"
1313 " cleared\n", ofd_name(ofd), seq);
1314 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
1317 diff = oid - ofd_seq_last_oid(oseq);
1318 CDEBUG(D_HA, "ofd_last_id() = "LPU64" -> diff = %d\n",
1319 ofd_seq_last_oid(oseq), diff);
1320 if (-diff > OST_MAX_PRECREATE) {
1321 /* FIXME: should reset precreate_next_id on MDS */
1323 } else if (diff < 0) {
1324 rc = ofd_orphans_destroy(tsi->tsi_env, exp,
1326 oseq->os_destroys_in_progress = 0;
1328 /* XXX: Used by MDS for the first time! */
1329 oseq->os_destroys_in_progress = 0;
1332 if (unlikely(exp->exp_filter_data.fed_lastid_gen !=
1333 ofd->ofd_lastid_gen)) {
1334 ofd_obd_disconnect(exp);
1335 GOTO(out_nolock, rc = -ENOTCONN);
1338 mutex_lock(&oseq->os_create_lock);
1339 if (lustre_msg_get_conn_cnt(tgt_ses_req(tsi)->rq_reqmsg) <
1340 exp->exp_conn_cnt) {
1341 CERROR("%s: dropping old precreate request\n",
1345 /* only precreate if seq is 0, IDIF or normal and also o_id
1346 * must be specfied */
1347 if ((!fid_seq_is_mdt(seq) && !fid_seq_is_norm(seq) &&
1348 !fid_seq_is_idif(seq)) || oid == 0) {
1349 diff = 1; /* shouldn't we create this right now? */
1351 diff = oid - ofd_seq_last_oid(oseq);
1352 /* Do sync create if the seq is about to used up */
1353 if (fid_seq_is_idif(seq) || fid_seq_is_mdt0(seq)) {
1354 if (unlikely(oid >= IDIF_MAX_OID - 1))
1356 } else if (fid_seq_is_norm(seq)) {
1358 LUSTRE_DATA_SEQ_MAX_WIDTH - 1))
1361 CERROR("%s : invalid o_seq "DOSTID"\n",
1362 ofd_name(ofd), POSTID(&oa->o_oi));
1363 GOTO(out, rc = -EINVAL);
1368 cfs_time_t enough_time = cfs_time_shift(DISK_TIMEOUT);
1373 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1374 !(oa->o_flags & OBD_FL_DELORPHAN)) {
1375 /* don't enforce grant during orphan recovery */
1376 rc = ofd_grant_create(tsi->tsi_env,
1377 ofd_obd(ofd)->obd_self_export,
1380 CDEBUG(D_HA, "%s: failed to acquire grant "
1381 "space for precreate (%d): rc = %d\n",
1382 ofd_name(ofd), diff, rc);
1387 /* This can happen if a new OST is formatted and installed
1388 * in place of an old one at the same index. Instead of
1389 * precreating potentially millions of deleted old objects
1390 * (possibly filling the OST), only precreate the last batch.
1391 * LFSCK will eventually clean up any orphans. LU-14 */
1392 if (diff > 5 * OST_MAX_PRECREATE) {
1393 diff = OST_MAX_PRECREATE / 2;
1394 LCONSOLE_WARN("%s: precreate FID "DOSTID" is over %u "
1395 "larger than the LAST_ID "DOSTID", only "
1396 "precreating the last %u objects.\n",
1397 ofd_name(ofd), POSTID(&oa->o_oi),
1398 5 * OST_MAX_PRECREATE,
1399 POSTID(&oseq->os_oi), diff);
1400 ofd_seq_last_oid_set(oseq, ostid_id(&oa->o_oi) - diff);
1404 next_id = ofd_seq_last_oid(oseq) + 1;
1405 count = ofd_precreate_batch(ofd, diff);
1407 CDEBUG(D_HA, "%s: reserve %d objects in group "LPX64
1408 " at "LPU64"\n", ofd_name(ofd),
1409 count, seq, next_id);
1411 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1412 && cfs_time_after(jiffies, enough_time)) {
1413 CDEBUG(D_HA, "%s: Slow creates, %d/%d objects"
1414 " created at a rate of %d/s\n",
1415 ofd_name(ofd), created, diff + created,
1416 created / DISK_TIMEOUT);
1420 rc = ofd_precreate_objects(tsi->tsi_env, ofd, next_id,
1421 oseq, count, sync_trans);
1425 } else if (rc < 0) {
1431 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1432 LCONSOLE_WARN("%s: can't create the same count of"
1433 " objects when replaying the request"
1434 " (diff is %d). see LU-4621\n",
1435 ofd_name(ofd), diff);
1438 /* some objects got created, we can return
1439 * them, even if last creation failed */
1442 CERROR("%s: unable to precreate: rc = %d\n",
1445 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1446 !(oa->o_flags & OBD_FL_DELORPHAN))
1447 ofd_grant_commit(tsi->tsi_env,
1448 ofd_obd(ofd)->obd_self_export, rc);
1450 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
1453 ofd_counter_incr(exp, LPROC_OFD_STATS_CREATE,
1456 mutex_unlock(&oseq->os_create_lock);
1459 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
1460 struct ofd_thread_info *info = ofd_info(tsi->tsi_env);
1461 struct lu_fid *fid = &info->fti_fid;
1463 /* For compatible purpose, it needs to convert back to
1464 * OST ID before put it on wire. */
1465 *fid = rep_oa->o_oi.oi_fid;
1466 fid_to_ostid(fid, &rep_oa->o_oi);
1468 rep_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
1470 ofd_seq_put(tsi->tsi_env, oseq);
1473 up_read(&ofd->ofd_lastid_rwsem);
1477 static int ofd_destroy_hdl(struct tgt_session_info *tsi)
1479 const struct ost_body *body = tsi->tsi_ost_body;
1480 struct ost_body *repbody;
1481 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1482 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1483 struct lu_fid *fid = &fti->fti_fid;
1490 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1493 /* This is old case for clients before Lustre 2.4 */
1494 /* If there's a DLM request, cancel the locks mentioned in it */
1495 if (req_capsule_field_present(tsi->tsi_pill, &RMF_DLM_REQ,
1497 struct ldlm_request *dlm;
1499 dlm = req_capsule_client_get(tsi->tsi_pill, &RMF_DLM_REQ);
1502 ldlm_request_cancel(tgt_ses_req(tsi), dlm, 0);
1505 *fid = body->oa.o_oi.oi_fid;
1506 oid = ostid_id(&body->oa.o_oi);
1509 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1511 /* check that o_misc makes sense */
1512 if (body->oa.o_valid & OBD_MD_FLOBJCOUNT)
1513 count = body->oa.o_misc;
1515 count = 1; /* default case - single destroy */
1517 CDEBUG(D_HA, "%s: Destroy object "DOSTID" count %d\n", ofd_name(ofd),
1518 POSTID(&body->oa.o_oi), count);
1523 lrc = ofd_destroy_by_fid(tsi->tsi_env, ofd, fid, 0);
1524 if (lrc == -ENOENT) {
1526 "%s: destroying non-existent object "DFID"\n",
1527 ofd_name(ofd), PFID(fid));
1528 /* rewrite rc with -ENOENT only if it is 0 */
1531 } else if (lrc != 0) {
1532 CERROR("%s: error destroying object "DFID": %d\n",
1533 ofd_name(ofd), PFID(fid), lrc);
1539 lrc = fid_set_id(fid, oid);
1540 if (unlikely(lrc != 0 && count > 0))
1541 GOTO(out, rc = lrc);
1544 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_DESTROY,
1550 fid_to_ostid(fid, &repbody->oa.o_oi);
1554 static int ofd_statfs_hdl(struct tgt_session_info *tsi)
1556 struct obd_statfs *osfs;
1561 osfs = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_STATFS);
1563 rc = ofd_statfs(tsi->tsi_env, tsi->tsi_exp, osfs,
1564 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), 0);
1566 CERROR("%s: statfs failed: rc = %d\n",
1567 tgt_name(tsi->tsi_tgt), rc);
1569 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_EINPROGRESS))
1572 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_STATFS,
1578 static int ofd_sync_hdl(struct tgt_session_info *tsi)
1580 struct ost_body *body = tsi->tsi_ost_body;
1581 struct ost_body *repbody;
1582 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1583 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1584 struct ofd_object *fo = NULL;
1589 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1591 /* if no objid is specified, it means "sync whole filesystem" */
1592 if (!fid_is_zero(&tsi->tsi_fid)) {
1593 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1595 RETURN(PTR_ERR(fo));
1598 rc = tgt_sync(tsi->tsi_env, tsi->tsi_tgt,
1599 fo != NULL ? ofd_object_child(fo) : NULL,
1600 repbody->oa.o_size, repbody->oa.o_blocks);
1604 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SYNC,
1609 repbody->oa.o_oi = body->oa.o_oi;
1610 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1612 rc = ofd_attr_get(tsi->tsi_env, fo, &fti->fti_attr);
1614 obdo_from_la(&repbody->oa, &fti->fti_attr,
1617 /* don't return rc from getattr */
1622 ofd_object_put(tsi->tsi_env, fo);
1626 static int ofd_punch_hdl(struct tgt_session_info *tsi)
1628 const struct obdo *oa = &tsi->tsi_ost_body->oa;
1629 struct ost_body *repbody;
1630 struct ofd_thread_info *info = tsi2ofd_info(tsi);
1631 struct ldlm_namespace *ns = tsi->tsi_tgt->lut_obd->obd_namespace;
1632 struct ldlm_resource *res;
1633 struct ofd_object *fo;
1634 struct filter_fid *ff = NULL;
1636 struct lustre_handle lh = { 0, };
1643 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
1644 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
1646 if ((oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
1647 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
1648 RETURN(err_serious(-EPROTO));
1650 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1651 if (repbody == NULL)
1652 RETURN(err_serious(-ENOMEM));
1654 /* punch start,end are passed in o_size,o_blocks throught wire */
1658 if (end != OBD_OBJECT_EOF) /* Only truncate is supported */
1661 /* standard truncate optimization: if file body is completely
1662 * destroyed, don't send data back to the server. */
1664 flags |= LDLM_FL_AST_DISCARD_DATA;
1666 repbody->oa.o_oi = oa->o_oi;
1667 repbody->oa.o_valid = OBD_MD_FLID;
1669 srvlock = oa->o_valid & OBD_MD_FLFLAGS &&
1670 oa->o_flags & OBD_FL_SRVLOCK;
1673 rc = tgt_extent_lock(ns, &tsi->tsi_resid, start, end, &lh,
1679 CDEBUG(D_INODE, "calling punch for object "DFID", valid = "LPX64
1680 ", start = "LPD64", end = "LPD64"\n", PFID(&tsi->tsi_fid),
1681 oa->o_valid, start, end);
1683 fo = ofd_object_find_exists(tsi->tsi_env, ofd_exp(tsi->tsi_exp),
1686 GOTO(out, rc = PTR_ERR(fo));
1688 la_from_obdo(&info->fti_attr, oa,
1689 OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME);
1690 info->fti_attr.la_size = start;
1691 info->fti_attr.la_valid |= LA_SIZE;
1693 if (oa->o_valid & OBD_MD_FLFID) {
1694 ff = &info->fti_mds_fid;
1695 ofd_prepare_fidea(ff, oa);
1698 rc = ofd_object_punch(tsi->tsi_env, fo, start, end, &info->fti_attr,
1699 ff, (struct obdo *)oa);
1703 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_PUNCH,
1707 ofd_object_put(tsi->tsi_env, fo);
1710 tgt_extent_unlock(&lh, LCK_PW);
1712 /* we do not call this before to avoid lu_object_find() in
1713 * ->lvbo_update() holding another reference on the object.
1714 * otherwise concurrent destroy can make the object unavailable
1715 * for 2nd lu_object_find() waiting for the first reference
1716 * to go... deadlock! */
1717 res = ldlm_resource_get(ns, NULL, &tsi->tsi_resid,
1720 ldlm_res_lvbo_update(res, NULL, 0);
1721 ldlm_resource_putref(res);
1727 static int ofd_quotactl(struct tgt_session_info *tsi)
1729 struct obd_quotactl *oqctl, *repoqc;
1734 oqctl = req_capsule_client_get(tsi->tsi_pill, &RMF_OBD_QUOTACTL);
1736 RETURN(err_serious(-EPROTO));
1738 repoqc = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_QUOTACTL);
1740 RETURN(err_serious(-ENOMEM));
1742 /* report success for quota on/off for interoperability with current MDT
1744 if (oqctl->qc_cmd == Q_QUOTAON || oqctl->qc_cmd == Q_QUOTAOFF)
1748 rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom, repoqc);
1750 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_QUOTACTL,
1756 /* High priority request handlers for OFD */
1758 /* prolong locks for the current service time of the corresponding
1759 * portal (= OST_IO_PORTAL)
1761 static inline int prolong_timeout(struct ptlrpc_request *req)
1763 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1766 return obd_timeout / 2;
1768 return max(at_est2timeout(at_get(&svcpt->scp_at_estimate)),
1772 static int ofd_prolong_one_lock(struct tgt_session_info *tsi,
1773 struct ldlm_lock *lock,
1774 struct ldlm_extent *extent, int timeout)
1777 if (lock->l_flags & LDLM_FL_DESTROYED) /* lock already cancelled */
1780 /* XXX: never try to grab resource lock here because we're inside
1781 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1782 * res lock and then exp_bl_list_lock. */
1784 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1785 /* ignore locks not being cancelled */
1788 LDLM_DEBUG(lock, "refreshed for req x"LPU64" ext("LPU64"->"LPU64") "
1789 "to %ds.\n", tgt_ses_req(tsi)->rq_xid, extent->start,
1790 extent->end, timeout);
1792 /* OK. this is a possible lock the user holds doing I/O
1793 * let's refresh eviction timer for it */
1794 ldlm_refresh_waiting_lock(lock, timeout);
1798 static int ofd_prolong_extent_locks(struct tgt_session_info *tsi,
1799 __u64 start, __u64 end)
1801 struct obd_export *exp = tsi->tsi_exp;
1802 struct obdo *oa = &tsi->tsi_ost_body->oa;
1803 struct ldlm_extent extent = {
1807 struct ldlm_lock *lock;
1808 int timeout = prolong_timeout(tgt_ses_req(tsi));
1813 if (oa->o_valid & OBD_MD_FLHANDLE) {
1814 /* mostly a request should be covered by only one lock, try
1816 lock = ldlm_handle2lock(&oa->o_handle);
1818 /* Fast path to check if the lock covers the whole IO
1819 * region exclusively. */
1820 if (lock->l_granted_mode == LCK_PW &&
1821 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1824 LASSERT(lock->l_export == exp);
1825 lock_count = ofd_prolong_one_lock(tsi, lock,
1827 LDLM_LOCK_PUT(lock);
1830 LDLM_LOCK_PUT(lock);
1834 spin_lock_bh(&exp->exp_bl_list_lock);
1835 list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1836 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1837 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1839 if (!ldlm_res_eq(&tsi->tsi_resid, &lock->l_resource->lr_name))
1842 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1846 lock_count += ofd_prolong_one_lock(tsi, lock, &extent, timeout);
1848 spin_unlock_bh(&exp->exp_bl_list_lock);
1854 * Returns 1 if the given PTLRPC matches the given LDLM lock, or 0 if it does
1857 static int ofd_rw_hpreq_lock_match(struct ptlrpc_request *req,
1858 struct ldlm_lock *lock)
1860 struct niobuf_remote *rnb;
1861 struct obd_ioobj *ioo;
1863 struct ldlm_extent ext;
1864 __u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
1868 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1869 LASSERT(ioo != NULL);
1871 rnb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1872 LASSERT(rnb != NULL);
1874 ext.start = rnb->rnb_offset;
1875 rnb += ioo->ioo_bufcnt - 1;
1876 ext.end = rnb->rnb_offset + rnb->rnb_len - 1;
1878 LASSERT(lock->l_resource != NULL);
1879 if (!ostid_res_name_eq(&ioo->ioo_oid, &lock->l_resource->lr_name))
1883 if (opc == OST_READ)
1886 if (!(lock->l_granted_mode & mode))
1889 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1893 * High-priority queue request check for whether the given PTLRPC request
1894 * (\a req) is blocking an LDLM lock cancel.
1896 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1897 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1899 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1900 * function looks only at OST_READs and OST_WRITEs.
1902 static int ofd_rw_hpreq_check(struct ptlrpc_request *req)
1904 struct tgt_session_info *tsi;
1905 struct obd_ioobj *ioo;
1906 struct niobuf_remote *rnb;
1912 /* Don't use tgt_ses_info() to get session info, because lock_match()
1913 * can be called while request has no processing thread yet. */
1914 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
1915 LASSERT(tsi != NULL);
1918 * Use LASSERT below because malformed RPCs should have
1919 * been filtered out in tgt_hpreq_handler().
1921 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1922 LASSERT(ioo != NULL);
1924 rnb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1925 LASSERT(rnb != NULL);
1926 LASSERT(!(rnb->rnb_flags & OBD_BRW_SRVLOCK));
1928 start = rnb->rnb_offset;
1929 rnb += ioo->ioo_bufcnt - 1;
1930 end = rnb->rnb_offset + rnb->rnb_len - 1;
1932 DEBUG_REQ(D_RPCTRACE, req, "%s %s: refresh rw locks: "DFID
1933 " ("LPU64"->"LPU64")\n",
1934 tgt_name(tsi->tsi_tgt), current->comm,
1935 PFID(&tsi->tsi_fid), start, end);
1937 lock_count = ofd_prolong_extent_locks(tsi, start, end);
1939 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1940 tgt_name(tsi->tsi_tgt), lock_count, req);
1942 RETURN(lock_count > 0);
1945 static void ofd_rw_hpreq_fini(struct ptlrpc_request *req)
1947 ofd_rw_hpreq_check(req);
1951 * Like tgt_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1953 static int ofd_punch_hpreq_lock_match(struct ptlrpc_request *req,
1954 struct ldlm_lock *lock)
1956 struct tgt_session_info *tsi;
1958 /* Don't use tgt_ses_info() to get session info, because lock_match()
1959 * can be called while request has no processing thread yet. */
1960 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
1961 LASSERT(tsi != NULL);
1963 LASSERT(tsi->tsi_ost_body != NULL);
1964 if (tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLHANDLE &&
1965 tsi->tsi_ost_body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1972 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1974 static int ofd_punch_hpreq_check(struct ptlrpc_request *req)
1976 struct tgt_session_info *tsi;
1982 /* Don't use tgt_ses_info() to get session info, because lock_match()
1983 * can be called while request has no processing thread yet. */
1984 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
1985 LASSERT(tsi != NULL);
1986 oa = &tsi->tsi_ost_body->oa;
1988 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS &&
1989 oa->o_flags & OBD_FL_SRVLOCK));
1992 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1993 tgt_name(tsi->tsi_tgt), tsi->tsi_resid.name[0],
1994 tsi->tsi_resid.name[1], oa->o_size, oa->o_blocks);
1996 lock_count = ofd_prolong_extent_locks(tsi, oa->o_size, oa->o_blocks);
1998 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1999 tgt_name(tsi->tsi_tgt), lock_count, req);
2001 RETURN(lock_count > 0);
2004 static void ofd_punch_hpreq_fini(struct ptlrpc_request *req)
2006 ofd_punch_hpreq_check(req);
2009 struct ptlrpc_hpreq_ops ofd_hpreq_rw = {
2010 .hpreq_lock_match = ofd_rw_hpreq_lock_match,
2011 .hpreq_check = ofd_rw_hpreq_check,
2012 .hpreq_fini = ofd_rw_hpreq_fini
2015 struct ptlrpc_hpreq_ops ofd_hpreq_punch = {
2016 .hpreq_lock_match = ofd_punch_hpreq_lock_match,
2017 .hpreq_check = ofd_punch_hpreq_check,
2018 .hpreq_fini = ofd_punch_hpreq_fini
2021 /** Assign high priority operations to the IO requests */
2022 static void ofd_hp_brw(struct tgt_session_info *tsi)
2024 struct niobuf_remote *rnb;
2025 struct obd_ioobj *ioo;
2029 ioo = req_capsule_client_get(tsi->tsi_pill, &RMF_OBD_IOOBJ);
2030 LASSERT(ioo != NULL); /* must exist after request preprocessing */
2031 if (ioo->ioo_bufcnt > 0) {
2032 rnb = req_capsule_client_get(tsi->tsi_pill, &RMF_NIOBUF_REMOTE);
2033 LASSERT(rnb != NULL); /* must exist after request preprocessing */
2035 /* no high priority if server lock is needed */
2036 if (rnb->rnb_flags & OBD_BRW_SRVLOCK)
2039 tgt_ses_req(tsi)->rq_ops = &ofd_hpreq_rw;
2042 static void ofd_hp_punch(struct tgt_session_info *tsi)
2044 LASSERT(tsi->tsi_ost_body != NULL); /* must exists if we are here */
2045 /* no high-priority if server lock is needed */
2046 if (tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLFLAGS &&
2047 tsi->tsi_ost_body->oa.o_flags & OBD_FL_SRVLOCK)
2049 tgt_ses_req(tsi)->rq_ops = &ofd_hpreq_punch;
2052 #define OBD_FAIL_OST_READ_NET OBD_FAIL_OST_BRW_NET
2053 #define OBD_FAIL_OST_WRITE_NET OBD_FAIL_OST_BRW_NET
2054 #define OST_BRW_READ OST_READ
2055 #define OST_BRW_WRITE OST_WRITE
2057 static struct tgt_handler ofd_tgt_handlers[] = {
2058 TGT_RPC_HANDLER(OST_FIRST_OPC,
2059 0, OST_CONNECT, tgt_connect,
2060 &RQF_CONNECT, LUSTRE_OBD_VERSION),
2061 TGT_RPC_HANDLER(OST_FIRST_OPC,
2062 0, OST_DISCONNECT, tgt_disconnect,
2063 &RQF_OST_DISCONNECT, LUSTRE_OBD_VERSION),
2064 TGT_RPC_HANDLER(OST_FIRST_OPC,
2065 0, OST_SET_INFO, ofd_set_info_hdl,
2066 &RQF_OBD_SET_INFO, LUSTRE_OST_VERSION),
2067 TGT_OST_HDL(0, OST_GET_INFO, ofd_get_info_hdl),
2068 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO, OST_GETATTR, ofd_getattr_hdl),
2069 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR,
2070 OST_SETATTR, ofd_setattr_hdl),
2071 TGT_OST_HDL(0 | HABEO_REFERO | MUTABOR,
2072 OST_CREATE, ofd_create_hdl),
2073 TGT_OST_HDL(0 | HABEO_REFERO | MUTABOR,
2074 OST_DESTROY, ofd_destroy_hdl),
2075 TGT_OST_HDL(0 | HABEO_REFERO, OST_STATFS, ofd_statfs_hdl),
2076 TGT_OST_HDL_HP(HABEO_CORPUS| HABEO_REFERO,
2077 OST_BRW_READ, tgt_brw_read,
2079 /* don't set CORPUS flag for brw_write because -ENOENT may be valid case */
2080 TGT_OST_HDL_HP(HABEO_CORPUS| MUTABOR, OST_BRW_WRITE, tgt_brw_write,
2082 TGT_OST_HDL_HP(HABEO_CORPUS| HABEO_REFERO | MUTABOR,
2083 OST_PUNCH, ofd_punch_hdl,
2085 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO, OST_SYNC, ofd_sync_hdl),
2086 TGT_OST_HDL(0 | HABEO_REFERO, OST_QUOTACTL, ofd_quotactl),
2089 static struct tgt_opc_slice ofd_common_slice[] = {
2091 .tos_opc_start = OST_FIRST_OPC,
2092 .tos_opc_end = OST_LAST_OPC,
2093 .tos_hs = ofd_tgt_handlers
2096 .tos_opc_start = OBD_FIRST_OPC,
2097 .tos_opc_end = OBD_LAST_OPC,
2098 .tos_hs = tgt_obd_handlers
2101 .tos_opc_start = LDLM_FIRST_OPC,
2102 .tos_opc_end = LDLM_LAST_OPC,
2103 .tos_hs = tgt_dlm_handlers
2106 .tos_opc_start = OUT_UPDATE_FIRST_OPC,
2107 .tos_opc_end = OUT_UPDATE_LAST_OPC,
2108 .tos_hs = tgt_out_handlers
2111 .tos_opc_start = SEQ_FIRST_OPC,
2112 .tos_opc_end = SEQ_LAST_OPC,
2113 .tos_hs = seq_handlers
2116 .tos_opc_start = LFSCK_FIRST_OPC,
2117 .tos_opc_end = LFSCK_LAST_OPC,
2118 .tos_hs = tgt_lfsck_handlers
2125 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
2126 struct lu_device_type *ldt, struct lustre_cfg *cfg)
2128 const char *dev = lustre_cfg_string(cfg, 0);
2129 struct ofd_thread_info *info = NULL;
2130 struct obd_device *obd;
2131 struct obd_statfs *osfs;
2136 obd = class_name2obd(dev);
2138 CERROR("Cannot find obd with name %s\n", dev);
2142 rc = lu_env_refill((struct lu_env *)env);
2146 obd->u.obt.obt_magic = OBT_MAGIC;
2148 m->ofd_fmd_max_num = OFD_FMD_MAX_NUM_DEFAULT;
2149 m->ofd_fmd_max_age = OFD_FMD_MAX_AGE_DEFAULT;
2151 spin_lock_init(&m->ofd_flags_lock);
2152 m->ofd_raid_degraded = 0;
2153 m->ofd_syncjournal = 0;
2155 m->ofd_grant_compat_disable = 0;
2156 m->ofd_soft_sync_limit = OFD_SOFT_SYNC_LIMIT_DEFAULT;
2159 spin_lock_init(&m->ofd_osfs_lock);
2160 m->ofd_osfs_age = cfs_time_shift_64(-1000);
2161 m->ofd_osfs_unstable = 0;
2162 m->ofd_statfs_inflight = 0;
2163 m->ofd_osfs_inflight = 0;
2166 spin_lock_init(&m->ofd_grant_lock);
2167 m->ofd_tot_dirty = 0;
2168 m->ofd_tot_granted = 0;
2169 m->ofd_tot_pending = 0;
2170 m->ofd_seq_count = 0;
2171 init_waitqueue_head(&m->ofd_inconsistency_thread.t_ctl_waitq);
2172 INIT_LIST_HEAD(&m->ofd_inconsistency_list);
2173 spin_lock_init(&m->ofd_inconsistency_lock);
2175 spin_lock_init(&m->ofd_batch_lock);
2176 init_rwsem(&m->ofd_lastid_rwsem);
2178 obd->u.filter.fo_fl_oss_capa = 0;
2179 INIT_LIST_HEAD(&obd->u.filter.fo_capa_keys);
2180 obd->u.filter.fo_capa_hash = init_capa_hash();
2181 if (obd->u.filter.fo_capa_hash == NULL)
2184 m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops;
2185 m->ofd_dt_dev.dd_lu_dev.ld_obd = obd;
2186 /* set this lu_device to obd, because error handling need it */
2187 obd->obd_lu_dev = &m->ofd_dt_dev.dd_lu_dev;
2189 rc = ofd_procfs_init(m);
2191 CERROR("Can't init ofd lprocfs, rc %d\n", rc);
2195 /* No connection accepted until configurations will finish */
2196 spin_lock(&obd->obd_dev_lock);
2197 obd->obd_no_conn = 1;
2198 spin_unlock(&obd->obd_dev_lock);
2199 obd->obd_replayable = 1;
2200 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
2201 char *str = lustre_cfg_string(cfg, 4);
2203 if (strchr(str, 'n')) {
2204 CWARN("%s: recovery disabled\n", obd->obd_name);
2205 obd->obd_replayable = 0;
2209 info = ofd_info_init(env, NULL);
2213 rc = ofd_stack_init(env, m, cfg);
2215 CERROR("Can't init device stack, rc %d\n", rc);
2216 GOTO(err_fini_proc, rc);
2219 ofd_procfs_add_brw_stats_symlink(m);
2221 /* populate cached statfs data */
2222 osfs = &ofd_info(env)->fti_u.osfs;
2223 rc = ofd_statfs_internal(env, m, osfs, 0, NULL);
2225 CERROR("%s: can't get statfs data, rc %d\n", obd->obd_name, rc);
2226 GOTO(err_fini_stack, rc);
2228 if (!IS_PO2(osfs->os_bsize)) {
2229 CERROR("%s: blocksize (%d) is not a power of 2\n",
2230 obd->obd_name, osfs->os_bsize);
2231 GOTO(err_fini_stack, rc = -EPROTO);
2233 m->ofd_blockbits = fls(osfs->os_bsize) - 1;
2235 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_DEFAULT;
2236 if (osfs->os_bsize * osfs->os_blocks < OFD_PRECREATE_SMALL_FS)
2237 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_SMALL;
2239 snprintf(info->fti_u.name, sizeof(info->fti_u.name), "%s-%s",
2240 "filter"/*LUSTRE_OST_NAME*/, obd->obd_uuid.uuid);
2241 m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name,
2242 LDLM_NAMESPACE_SERVER,
2243 LDLM_NAMESPACE_GREEDY,
2245 if (m->ofd_namespace == NULL)
2246 GOTO(err_fini_stack, rc = -ENOMEM);
2247 /* set obd_namespace for compatibility with old code */
2248 obd->obd_namespace = m->ofd_namespace;
2249 ldlm_register_intent(m->ofd_namespace, ofd_intent_policy);
2250 m->ofd_namespace->ns_lvbo = &ofd_lvbo;
2251 m->ofd_namespace->ns_lvbp = m;
2253 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
2254 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
2256 dt_conf_get(env, m->ofd_osd, &m->ofd_dt_conf);
2258 /* Allow at most ddp_grant_reserved% of the available filesystem space
2259 * to be granted to clients, so that any errors in the grant overhead
2260 * calculations do not allow granting more space to clients than can be
2261 * written. Assumes that in aggregate the grant overhead calculations do
2262 * not have more than ddp_grant_reserved% estimation error in them. */
2263 m->ofd_grant_ratio =
2264 ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved);
2266 rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd, ofd_common_slice,
2267 OBD_FAIL_OST_ALL_REQUEST_NET,
2268 OBD_FAIL_OST_ALL_REPLY_NET);
2270 GOTO(err_free_ns, rc);
2272 rc = ofd_fs_setup(env, m, obd);
2274 GOTO(err_fini_lut, rc);
2276 rc = ofd_start_inconsistency_verification_thread(m);
2278 GOTO(err_fini_fs, rc);
2283 ofd_fs_cleanup(env, m);
2285 tgt_fini(env, &m->ofd_lut);
2287 ldlm_namespace_free(m->ofd_namespace, 0, obd->obd_force);
2288 obd->obd_namespace = m->ofd_namespace = NULL;
2290 ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev);
2296 static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
2298 struct obd_device *obd = ofd_obd(m);
2299 struct lu_device *d = &m->ofd_dt_dev.dd_lu_dev;
2300 struct lfsck_stop stop;
2302 stop.ls_status = LS_PAUSED;
2304 lfsck_stop(env, m->ofd_osd, &stop);
2305 target_recovery_fini(obd);
2306 obd_exports_barrier(obd);
2307 obd_zombie_barrier();
2309 tgt_fini(env, &m->ofd_lut);
2310 ofd_stop_inconsistency_verification_thread(m);
2311 lfsck_degister(env, m->ofd_osd);
2312 ofd_fs_cleanup(env, m);
2314 ofd_free_capa_keys(m);
2315 cleanup_capa_hash(obd->u.filter.fo_capa_hash);
2317 if (m->ofd_namespace != NULL) {
2318 ldlm_namespace_free(m->ofd_namespace, NULL,
2319 d->ld_obd->obd_force);
2320 d->ld_obd->obd_namespace = m->ofd_namespace = NULL;
2323 ofd_stack_fini(env, m, &m->ofd_dt_dev.dd_lu_dev);
2325 LASSERT(atomic_read(&d->ld_ref) == 0);
2326 server_put_mount(obd->obd_name, true);
2330 static struct lu_device *ofd_device_fini(const struct lu_env *env,
2331 struct lu_device *d)
2334 ofd_fini(env, ofd_dev(d));
2338 static struct lu_device *ofd_device_free(const struct lu_env *env,
2339 struct lu_device *d)
2341 struct ofd_device *m = ofd_dev(d);
2343 dt_device_fini(&m->ofd_dt_dev);
2348 static struct lu_device *ofd_device_alloc(const struct lu_env *env,
2349 struct lu_device_type *t,
2350 struct lustre_cfg *cfg)
2352 struct ofd_device *m;
2353 struct lu_device *l;
2358 return ERR_PTR(-ENOMEM);
2360 l = &m->ofd_dt_dev.dd_lu_dev;
2361 dt_device_init(&m->ofd_dt_dev, t);
2362 rc = ofd_init0(env, m, t, cfg);
2364 ofd_device_free(env, l);
2371 /* thread context key constructor/destructor */
2372 LU_KEY_INIT_FINI(ofd, struct ofd_thread_info);
2374 static void ofd_key_exit(const struct lu_context *ctx,
2375 struct lu_context_key *key, void *data)
2377 struct ofd_thread_info *info = data;
2379 info->fti_env = NULL;
2380 info->fti_exp = NULL;
2383 info->fti_pre_version = 0;
2386 memset(&info->fti_attr, 0, sizeof info->fti_attr);
2389 struct lu_context_key ofd_thread_key = {
2390 .lct_tags = LCT_DT_THREAD,
2391 .lct_init = ofd_key_init,
2392 .lct_fini = ofd_key_fini,
2393 .lct_exit = ofd_key_exit
2396 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
2397 LU_TYPE_INIT_FINI(ofd, &ofd_thread_key);
2399 static struct lu_device_type_operations ofd_device_type_ops = {
2400 .ldto_init = ofd_type_init,
2401 .ldto_fini = ofd_type_fini,
2403 .ldto_start = ofd_type_start,
2404 .ldto_stop = ofd_type_stop,
2406 .ldto_device_alloc = ofd_device_alloc,
2407 .ldto_device_free = ofd_device_free,
2408 .ldto_device_fini = ofd_device_fini
2411 static struct lu_device_type ofd_device_type = {
2412 .ldt_tags = LU_DEVICE_DT,
2413 .ldt_name = LUSTRE_OST_NAME,
2414 .ldt_ops = &ofd_device_type_ops,
2415 .ldt_ctx_tags = LCT_DT_THREAD
2418 int __init ofd_init(void)
2422 rc = lu_kmem_init(ofd_caches);
2426 rc = ofd_fmd_init();
2428 lu_kmem_fini(ofd_caches);
2432 rc = class_register_type(&ofd_obd_ops, NULL, true, NULL,
2433 #ifndef HAVE_ONLY_PROCFS_SEQ
2436 LUSTRE_OST_NAME, &ofd_device_type);
2440 void __exit ofd_exit(void)
2443 lu_kmem_fini(ofd_caches);
2444 class_unregister_type(LUSTRE_OST_NAME);
2447 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
2448 MODULE_DESCRIPTION("Lustre Object Filtering Device");
2449 MODULE_LICENSE("GPL");
2451 module_init(ofd_init);
2452 module_exit(ofd_exit);