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_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);
429 CWARN("%s: Rebuilt crashed LAST_ID files successfully.\n",
434 CERROR("%s: unknown lfsck event: rc = %d\n",
435 ofd_name(ofd), event);
442 static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev,
443 struct lu_device *dev)
445 struct ofd_thread_info *info;
446 struct ofd_device *ofd = ofd_dev(dev);
447 struct obd_device *obd = ofd_obd(ofd);
448 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
453 info = ofd_info_init(env, NULL);
457 /* initialize lower device */
458 rc = next->ld_ops->ldo_prepare(env, dev, next);
462 rc = lfsck_register(env, ofd->ofd_osd, ofd->ofd_osd, obd,
463 ofd_lfsck_out_notify, ofd, false);
465 CERROR("%s: failed to initialize lfsck: rc = %d\n",
470 rc = lfsck_register_namespace(env, ofd->ofd_osd, ofd->ofd_namespace);
471 /* The LFSCK instance is registered just now, so it must be there when
472 * register the namespace to such instance. */
473 LASSERTF(rc == 0, "register namespace failed: rc = %d\n", rc);
475 target_recovery_init(&ofd->ofd_lut, tgt_request_handle);
476 LASSERT(obd->obd_no_conn);
477 spin_lock(&obd->obd_dev_lock);
478 obd->obd_no_conn = 0;
479 spin_unlock(&obd->obd_dev_lock);
481 if (obd->obd_recovering == 0)
482 ofd_postrecov(env, ofd);
487 static int ofd_recovery_complete(const struct lu_env *env,
488 struct lu_device *dev)
490 struct ofd_device *ofd = ofd_dev(dev);
491 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
492 int rc = 0, max_precreate;
496 /* Grant space for object precreation on the self export.
497 * This initial reserved space (i.e. 10MB for zfs and 280KB for ldiskfs)
498 * is enough to create 10k objects. More space is then acquired for
499 * precreation in ofd_grant_create().
501 max_precreate = OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace / 2;
502 ofd_grant_connect(env, dev->ld_obd->obd_self_export, max_precreate,
504 rc = next->ld_ops->ldo_recovery_complete(env, next);
508 static struct lu_device_operations ofd_lu_ops = {
509 .ldo_object_alloc = ofd_object_alloc,
510 .ldo_process_config = ofd_process_config,
511 .ldo_recovery_complete = ofd_recovery_complete,
512 .ldo_prepare = ofd_prepare,
515 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
517 static int ofd_procfs_init(struct ofd_device *ofd)
519 struct obd_device *obd = ofd_obd(ofd);
520 cfs_proc_dir_entry_t *entry;
525 /* lprocfs must be setup before the ofd so state can be safely added
526 * to /proc incrementally as the ofd is setup */
527 obd->obd_vars = lprocfs_ofd_obd_vars;
528 rc = lprocfs_obd_setup(obd);
530 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
535 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
537 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
539 GOTO(obd_cleanup, rc);
542 obd->obd_uses_nid_stats = 1;
544 entry = lprocfs_seq_register("exports", obd->obd_proc_entry, NULL,
548 CERROR("%s: error %d setting up lprocfs for %s\n",
549 obd->obd_name, rc, "exports");
550 GOTO(obd_cleanup, rc);
552 obd->obd_proc_exports_entry = entry;
554 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
555 #ifndef HAVE_ONLY_PROCFS_SEQ
558 obd, &lprocfs_nid_stats_clear_fops);
561 CERROR("%s: add proc entry 'clear' failed: %d.\n",
563 GOTO(obd_cleanup, rc);
566 ofd_stats_counter_init(obd->obd_stats);
568 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
569 ofd_stats_counter_init);
571 GOTO(obd_cleanup, rc);
574 lprocfs_obd_cleanup(obd);
575 lprocfs_free_obd_stats(obd);
581 * ofd_procfs_add_brw_stats_symlink - expose osd stats to ofd layer
583 * The osd interfaces to the backend file system exposes useful data
584 * such as brw_stats and read or write cache states. This same data
585 * needs to be exposed into the obdfilter (ofd) layer to maintain
586 * backwards compatibility. This function creates the symlinks in the
587 * proc layer to enable this.
589 static void ofd_procfs_add_brw_stats_symlink(struct ofd_device *ofd)
591 struct obd_device *obd = ofd_obd(ofd);
592 struct obd_device *osd_obd = ofd->ofd_osd_exp->exp_obd;
594 if (obd->obd_proc_entry == NULL)
597 lprocfs_add_symlink("brw_stats", obd->obd_proc_entry,
598 "../../%s/%s/brw_stats",
599 osd_obd->obd_type->typ_name, obd->obd_name);
601 lprocfs_add_symlink("read_cache_enable", obd->obd_proc_entry,
602 "../../%s/%s/read_cache_enable",
603 osd_obd->obd_type->typ_name, obd->obd_name);
605 lprocfs_add_symlink("readcache_max_filesize",
607 "../../%s/%s/readcache_max_filesize",
608 osd_obd->obd_type->typ_name, obd->obd_name);
610 lprocfs_add_symlink("writethrough_cache_enable",
612 "../../%s/%s/writethrough_cache_enable",
613 osd_obd->obd_type->typ_name, obd->obd_name);
616 static void ofd_procfs_fini(struct ofd_device *ofd)
618 struct obd_device *obd = ofd_obd(ofd);
620 lprocfs_free_per_client_stats(obd);
621 lprocfs_obd_cleanup(obd);
622 lprocfs_free_obd_stats(obd);
623 lprocfs_job_stats_fini(obd);
626 extern int ost_handle(struct ptlrpc_request *req);
628 int ofd_fid_fini(const struct lu_env *env, struct ofd_device *ofd)
630 return seq_site_fini(env, &ofd->ofd_seq_site);
633 int ofd_fid_init(const struct lu_env *env, struct ofd_device *ofd)
635 struct seq_server_site *ss = &ofd->ofd_seq_site;
636 struct lu_device *lu = &ofd->ofd_dt_dev.dd_lu_dev;
637 char *obd_name = ofd_name(ofd);
641 ss = &ofd->ofd_seq_site;
642 lu->ld_site->ld_seq_site = ss;
643 ss->ss_lu = lu->ld_site;
644 ss->ss_node_id = ofd->ofd_lut.lut_lsd.lsd_osd_index;
646 OBD_ALLOC_PTR(ss->ss_server_seq);
647 if (ss->ss_server_seq == NULL)
648 GOTO(out_free, rc = -ENOMEM);
650 OBD_ALLOC(name, strlen(obd_name) + 10);
652 OBD_FREE_PTR(ss->ss_server_seq);
653 ss->ss_server_seq = NULL;
654 GOTO(out_free, rc = -ENOMEM);
657 rc = seq_server_init(env, ss->ss_server_seq, ofd->ofd_osd, obd_name,
658 LUSTRE_SEQ_SERVER, ss);
660 CERROR("%s : seq server init error %d\n", obd_name, rc);
663 ss->ss_server_seq->lss_space.lsr_index = ss->ss_node_id;
665 OBD_ALLOC_PTR(ss->ss_client_seq);
666 if (ss->ss_client_seq == NULL)
667 GOTO(out_free, rc = -ENOMEM);
669 snprintf(name, strlen(obd_name) + 6, "%p-super", obd_name);
670 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_DATA,
673 CERROR("%s : seq client init error %d\n", obd_name, rc);
676 OBD_FREE(name, strlen(obd_name) + 10);
679 rc = seq_server_set_cli(env, ss->ss_server_seq, ss->ss_client_seq);
683 if (ss->ss_server_seq) {
684 seq_server_fini(ss->ss_server_seq, env);
685 OBD_FREE_PTR(ss->ss_server_seq);
686 ss->ss_server_seq = NULL;
689 if (ss->ss_client_seq) {
690 seq_client_fini(ss->ss_client_seq);
691 OBD_FREE_PTR(ss->ss_client_seq);
692 ss->ss_client_seq = NULL;
696 OBD_FREE(name, strlen(obd_name) + 10);
704 int ofd_set_info_hdl(struct tgt_session_info *tsi)
706 struct ptlrpc_request *req = tgt_ses_req(tsi);
707 struct ost_body *body = NULL, *repbody;
708 void *key, *val = NULL;
709 int keylen, vallen, rc = 0;
710 bool is_grant_shrink;
711 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
715 key = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_KEY);
717 DEBUG_REQ(D_HA, req, "no set_info key");
718 RETURN(err_serious(-EFAULT));
720 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_KEY,
723 val = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_VAL);
725 DEBUG_REQ(D_HA, req, "no set_info val");
726 RETURN(err_serious(-EFAULT));
728 vallen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_VAL,
731 is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK);
733 /* In this case the value is actually an RMF_OST_BODY, so we
734 * transmutate the type of this PTLRPC */
735 req_capsule_extend(tsi->tsi_pill, &RQF_OST_SET_GRANT_INFO);
737 rc = req_capsule_server_pack(tsi->tsi_pill);
741 if (is_grant_shrink) {
742 body = req_capsule_client_get(tsi->tsi_pill, &RMF_OST_BODY);
744 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
747 /** handle grant shrink, similar to a read request */
748 ofd_grant_prepare_read(tsi->tsi_env, tsi->tsi_exp,
750 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
752 obd_export_evict_by_nid(tsi->tsi_exp->exp_obd, val);
754 } else if (KEY_IS(KEY_CAPA_KEY)) {
755 rc = ofd_update_capa_key(ofd, val);
756 } else if (KEY_IS(KEY_SPTLRPC_CONF)) {
757 rc = tgt_adapt_sptlrpc_conf(tsi->tsi_tgt, 0);
759 CERROR("%s: Unsupported key %s\n",
760 tgt_name(tsi->tsi_tgt), (char *)key);
763 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SET_INFO,
769 int ofd_fiemap_get(const struct lu_env *env, struct ofd_device *ofd,
770 struct lu_fid *fid, struct ll_user_fiemap *fiemap)
772 struct ofd_object *fo;
775 fo = ofd_object_find(env, ofd, fid);
777 CERROR("%s: error finding object "DFID"\n",
778 ofd_name(ofd), PFID(fid));
782 ofd_read_lock(env, fo);
783 if (ofd_object_exists(fo))
784 rc = dt_fiemap_get(env, ofd_object_child(fo), fiemap);
787 ofd_read_unlock(env, fo);
788 ofd_object_put(env, fo);
792 struct locked_region {
793 struct list_head list;
794 struct lustre_handle lh;
797 static int lock_region(struct ldlm_namespace *ns, struct ldlm_res_id *res_id,
798 unsigned long long begin, unsigned long long end,
799 struct list_head *locked)
801 struct locked_region *region = NULL;
805 LASSERT(begin <= end);
806 OBD_ALLOC_PTR(region);
810 rc = tgt_extent_lock(ns, res_id, begin, end, ®ion->lh,
815 CDEBUG(D_OTHER, "ost lock [%llu,%llu], lh=%p\n", begin, end,
817 list_add(®ion->list, locked);
822 static int lock_zero_regions(struct ldlm_namespace *ns,
823 struct ldlm_res_id *res_id,
824 struct ll_user_fiemap *fiemap,
825 struct list_head *locked)
827 __u64 begin = fiemap->fm_start;
830 struct ll_fiemap_extent *fiemap_start = fiemap->fm_extents;
834 CDEBUG(D_OTHER, "extents count %u\n", fiemap->fm_mapped_extents);
835 for (i = 0; i < fiemap->fm_mapped_extents; i++) {
836 if (fiemap_start[i].fe_logical > begin) {
837 CDEBUG(D_OTHER, "ost lock [%llu,%llu]\n",
838 begin, fiemap_start[i].fe_logical);
839 rc = lock_region(ns, res_id, begin,
840 fiemap_start[i].fe_logical, locked);
845 begin = fiemap_start[i].fe_logical + fiemap_start[i].fe_length;
848 if (begin < (fiemap->fm_start + fiemap->fm_length)) {
849 CDEBUG(D_OTHER, "ost lock [%llu,%llu]\n",
850 begin, fiemap->fm_start + fiemap->fm_length);
851 rc = lock_region(ns, res_id, begin,
852 fiemap->fm_start + fiemap->fm_length, locked);
859 unlock_zero_regions(struct ldlm_namespace *ns, struct list_head *locked)
861 struct locked_region *entry, *temp;
863 list_for_each_entry_safe(entry, temp, locked, list) {
864 CDEBUG(D_OTHER, "ost unlock lh=%p\n", &entry->lh);
865 tgt_extent_unlock(&entry->lh, LCK_PR);
866 list_del(&entry->list);
871 int ofd_get_info_hdl(struct tgt_session_info *tsi)
873 struct obd_export *exp = tsi->tsi_exp;
874 struct ofd_device *ofd = ofd_exp(exp);
875 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
878 int replylen, rc = 0;
882 /* this common part for get_info rpc */
883 key = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_KEY);
885 DEBUG_REQ(D_HA, tgt_ses_req(tsi), "no get_info key");
886 RETURN(err_serious(-EPROTO));
888 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_GETINFO_KEY,
891 if (KEY_IS(KEY_LAST_ID)) {
893 struct ofd_seq *oseq;
895 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_LAST_ID);
896 rc = req_capsule_server_pack(tsi->tsi_pill);
898 RETURN(err_serious(rc));
900 last_id = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_ID);
902 oseq = ofd_seq_load(tsi->tsi_env, ofd,
903 (obd_seq)exp->exp_filter_data.fed_group);
907 *last_id = ofd_seq_last_oid(oseq);
908 ofd_seq_put(tsi->tsi_env, oseq);
909 } else if (KEY_IS(KEY_FIEMAP)) {
910 struct ll_fiemap_info_key *fm_key;
911 struct ll_user_fiemap *fiemap;
914 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_FIEMAP);
916 fm_key = req_capsule_client_get(tsi->tsi_pill, &RMF_FIEMAP_KEY);
917 rc = tgt_validate_obdo(tsi, &fm_key->oa);
919 RETURN(err_serious(rc));
921 fid = &fm_key->oa.o_oi.oi_fid;
923 CDEBUG(D_INODE, "get FIEMAP of object "DFID"\n", PFID(fid));
925 replylen = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
926 req_capsule_set_size(tsi->tsi_pill, &RMF_FIEMAP_VAL,
927 RCL_SERVER, replylen);
929 rc = req_capsule_server_pack(tsi->tsi_pill);
931 RETURN(err_serious(rc));
933 fiemap = req_capsule_server_get(tsi->tsi_pill, &RMF_FIEMAP_VAL);
937 *fiemap = fm_key->fiemap;
938 rc = ofd_fiemap_get(tsi->tsi_env, ofd, fid, fiemap);
940 /* LU-3219: Lock the sparse areas to make sure dirty
941 * flushed back from client, then call fiemap again. */
942 if (fm_key->oa.o_valid & OBD_MD_FLFLAGS &&
943 fm_key->oa.o_flags & OBD_FL_SRVLOCK) {
944 struct list_head locked;
946 INIT_LIST_HEAD(&locked);
947 ost_fid_build_resid(fid, &fti->fti_resid);
948 rc = lock_zero_regions(ofd->ofd_namespace,
949 &fti->fti_resid, fiemap,
951 if (rc == 0 && !list_empty(&locked)) {
952 rc = ofd_fiemap_get(tsi->tsi_env, ofd, fid,
954 unlock_zero_regions(ofd->ofd_namespace,
958 } else if (KEY_IS(KEY_LAST_FID)) {
959 struct ofd_device *ofd = ofd_exp(exp);
960 struct ofd_seq *oseq;
964 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_LAST_FID);
965 rc = req_capsule_server_pack(tsi->tsi_pill);
967 RETURN(err_serious(rc));
969 fid = req_capsule_client_get(tsi->tsi_pill, &RMF_FID);
971 RETURN(err_serious(-EPROTO));
973 fid_le_to_cpu(&fti->fti_ostid.oi_fid, fid);
975 fid = req_capsule_server_get(tsi->tsi_pill, &RMF_FID);
979 oseq = ofd_seq_load(tsi->tsi_env, ofd,
980 ostid_seq(&fti->fti_ostid));
982 RETURN(PTR_ERR(oseq));
984 rc = ostid_to_fid(fid, &oseq->os_oi,
985 ofd->ofd_lut.lut_lsd.lsd_osd_index);
989 CDEBUG(D_HA, "%s: LAST FID is "DFID"\n", ofd_name(ofd),
992 ofd_seq_put(tsi->tsi_env, oseq);
994 CERROR("%s: not supported key %s\n", tgt_name(tsi->tsi_tgt),
998 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_GET_INFO,
1004 static int ofd_getattr_hdl(struct tgt_session_info *tsi)
1006 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1007 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1008 struct ost_body *repbody;
1009 struct lustre_handle lh = { 0 };
1010 struct ofd_object *fo;
1012 ldlm_mode_t lock_mode = LCK_PR;
1017 LASSERT(tsi->tsi_ost_body != NULL);
1019 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1020 if (repbody == NULL)
1023 repbody->oa.o_oi = tsi->tsi_ost_body->oa.o_oi;
1024 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1026 srvlock = tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLFLAGS &&
1027 tsi->tsi_ost_body->oa.o_flags & OBD_FL_SRVLOCK;
1030 if (unlikely(tsi->tsi_ost_body->oa.o_flags & OBD_FL_FLUSH))
1033 rc = tgt_extent_lock(tsi->tsi_tgt->lut_obd->obd_namespace,
1034 &tsi->tsi_resid, 0, OBD_OBJECT_EOF, &lh,
1040 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1042 GOTO(out, rc = PTR_ERR(fo));
1044 rc = ofd_attr_get(tsi->tsi_env, fo, &fti->fti_attr);
1048 obdo_from_la(&repbody->oa, &fti->fti_attr,
1049 OFD_VALID_FLAGS | LA_UID | LA_GID);
1050 tgt_drop_id(tsi->tsi_exp, &repbody->oa);
1052 /* Store object version in reply */
1053 curr_version = dt_version_get(tsi->tsi_env,
1054 ofd_object_child(fo));
1055 if ((__s64)curr_version != -EOPNOTSUPP) {
1056 repbody->oa.o_valid |= OBD_MD_FLDATAVERSION;
1057 repbody->oa.o_data_version = curr_version;
1061 ofd_object_put(tsi->tsi_env, fo);
1064 tgt_extent_unlock(&lh, lock_mode);
1066 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_GETATTR,
1069 repbody->oa.o_valid |= OBD_MD_FLFLAGS;
1070 repbody->oa.o_flags = OBD_FL_FLUSH;
1075 static int ofd_setattr_hdl(struct tgt_session_info *tsi)
1077 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1078 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1079 struct ost_body *body = tsi->tsi_ost_body;
1080 struct ost_body *repbody;
1081 struct ldlm_resource *res;
1082 struct ofd_object *fo;
1083 struct filter_fid *ff = NULL;
1088 LASSERT(body != NULL);
1090 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1091 if (repbody == NULL)
1094 repbody->oa.o_oi = body->oa.o_oi;
1095 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1097 /* This would be very bad - accidentally truncating a file when
1098 * changing the time or similar - bug 12203. */
1099 if (body->oa.o_valid & OBD_MD_FLSIZE &&
1100 body->oa.o_size != OBD_OBJECT_EOF) {
1101 static char mdsinum[48];
1103 if (body->oa.o_valid & OBD_MD_FLFID)
1104 snprintf(mdsinum, sizeof(mdsinum) - 1,
1105 "of parent "DFID, body->oa.o_parent_seq,
1106 body->oa.o_parent_oid, 0);
1110 CERROR("%s: setattr from %s is trying to truncate object "DFID
1111 " %s\n", ofd_name(ofd), obd_export_nid2str(tsi->tsi_exp),
1112 PFID(&tsi->tsi_fid), mdsinum);
1116 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1118 GOTO(out, rc = PTR_ERR(fo));
1120 la_from_obdo(&fti->fti_attr, &body->oa, body->oa.o_valid);
1121 fti->fti_attr.la_valid &= ~LA_TYPE;
1123 if (body->oa.o_valid & OBD_MD_FLFID) {
1124 ff = &fti->fti_mds_fid;
1125 ofd_prepare_fidea(ff, &body->oa);
1128 /* setting objects attributes (including owner/group) */
1129 rc = ofd_attr_set(tsi->tsi_env, fo, &fti->fti_attr, ff);
1133 obdo_from_la(&repbody->oa, &fti->fti_attr,
1134 OFD_VALID_FLAGS | LA_UID | LA_GID);
1135 tgt_drop_id(tsi->tsi_exp, &repbody->oa);
1137 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SETATTR,
1141 ofd_object_put(tsi->tsi_env, fo);
1144 /* we do not call this before to avoid lu_object_find() in
1145 * ->lvbo_update() holding another reference on the object.
1146 * otherwise concurrent destroy can make the object unavailable
1147 * for 2nd lu_object_find() waiting for the first reference
1148 * to go... deadlock! */
1149 res = ldlm_resource_get(ofd->ofd_namespace, NULL,
1150 &tsi->tsi_resid, LDLM_EXTENT, 0);
1152 ldlm_res_lvbo_update(res, NULL, 0);
1153 ldlm_resource_putref(res);
1159 static int ofd_orphans_destroy(const struct lu_env *env,
1160 struct obd_export *exp,
1161 struct ofd_device *ofd, struct obdo *oa)
1163 struct ofd_thread_info *info = ofd_info(env);
1164 struct lu_fid *fid = &info->fti_fid;
1165 struct ost_id *oi = &oa->o_oi;
1166 struct ofd_seq *oseq;
1167 obd_seq seq = ostid_seq(oi);
1168 obd_id end_id = ostid_id(oi);
1176 oseq = ofd_seq_get(ofd, seq);
1178 CERROR("%s: Can not find seq for "DOSTID"\n",
1179 ofd_name(ofd), POSTID(oi));
1184 last = ofd_seq_last_oid(oseq);
1187 LASSERT(exp != NULL);
1188 skip_orphan = !!(exp_connect_flags(exp) & OBD_CONNECT_SKIP_ORPHAN);
1190 if (OBD_FAIL_CHECK(OBD_FAIL_OST_NODESTROY))
1193 LCONSOLE(D_INFO, "%s: deleting orphan objects from "DOSTID
1194 " to "DOSTID"\n", ofd_name(ofd), seq, end_id + 1, seq, last);
1196 while (oid > end_id) {
1197 rc = fid_set_id(fid, oid);
1198 if (unlikely(rc != 0))
1201 rc = ofd_destroy_by_fid(env, ofd, fid, 1);
1202 if (rc != 0 && rc != -ENOENT && rc != -ESTALE &&
1203 likely(rc != -EREMCHG && rc != -EINPROGRESS))
1204 /* this is pretty fatal... */
1205 CEMERG("%s: error destroying precreated id "
1207 ofd_name(ofd), PFID(fid), rc);
1211 ofd_seq_last_oid_set(oseq, oid);
1212 /* update last_id on disk periodically so that if we
1213 * restart * we don't need to re-scan all of the just
1214 * deleted objects. */
1215 if ((oid & 511) == 0)
1216 ofd_seq_last_oid_write(env, ofd, oseq);
1220 CDEBUG(D_HA, "%s: after destroy: set last_id to "DOSTID"\n",
1221 ofd_name(ofd), seq, oid);
1225 ofd_seq_last_oid_set(oseq, oid);
1226 rc = ofd_seq_last_oid_write(env, ofd, oseq);
1228 /* don't reuse orphan object, return last used objid */
1229 ostid_set_id(oi, last);
1236 ofd_seq_put(env, oseq);
1240 static int ofd_create_hdl(struct tgt_session_info *tsi)
1242 struct ptlrpc_request *req = tgt_ses_req(tsi);
1243 struct ost_body *repbody;
1244 const struct obdo *oa = &tsi->tsi_ost_body->oa;
1245 struct obdo *rep_oa;
1246 struct obd_export *exp = tsi->tsi_exp;
1247 struct ofd_device *ofd = ofd_exp(exp);
1248 obd_seq seq = ostid_seq(&oa->o_oi);
1249 obd_id oid = ostid_id(&oa->o_oi);
1250 struct ofd_seq *oseq;
1256 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1259 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1260 if (repbody == NULL)
1263 down_read(&ofd->ofd_lastid_rwsem);
1264 /* Currently, for safe, we do not distinguish which LAST_ID is broken,
1265 * we may do that in the future.
1266 * Return -ENOSPC until the LAST_ID rebuilt. */
1267 if (unlikely(ofd->ofd_lastid_rebuilding))
1268 GOTO(out_sem, rc = -ENOSPC);
1270 rep_oa = &repbody->oa;
1271 rep_oa->o_oi = oa->o_oi;
1273 LASSERT(seq >= FID_SEQ_OST_MDT0);
1274 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
1276 CDEBUG(D_INFO, "ofd_create("DOSTID")\n", POSTID(&oa->o_oi));
1278 oseq = ofd_seq_load(tsi->tsi_env, ofd, seq);
1280 CERROR("%s: Can't find FID Sequence "LPX64": rc = %ld\n",
1281 ofd_name(ofd), seq, PTR_ERR(oseq));
1282 GOTO(out_sem, rc = -EINVAL);
1285 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1286 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1287 if (!ofd_obd(ofd)->obd_recovering ||
1288 oid > ofd_seq_last_oid(oseq)) {
1289 CERROR("%s: recreate objid "DOSTID" > last id "LPU64
1290 "\n", ofd_name(ofd), POSTID(&oa->o_oi),
1291 ofd_seq_last_oid(oseq));
1292 GOTO(out_nolock, rc = -EINVAL);
1294 /* Do nothing here, we re-create objects during recovery
1295 * upon write replay, see ofd_preprw_write() */
1296 GOTO(out_nolock, rc = 0);
1298 /* former ofd_handle_precreate */
1299 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1300 (oa->o_flags & OBD_FL_DELORPHAN)) {
1301 exp->exp_filter_data.fed_lastid_gen = ofd->ofd_lastid_gen;
1303 /* destroy orphans */
1304 if (lustre_msg_get_conn_cnt(tgt_ses_req(tsi)->rq_reqmsg) <
1305 exp->exp_conn_cnt) {
1306 CERROR("%s: dropping old orphan cleanup request\n",
1308 GOTO(out_nolock, rc = 0);
1310 /* This causes inflight precreates to abort and drop lock */
1311 oseq->os_destroys_in_progress = 1;
1312 mutex_lock(&oseq->os_create_lock);
1313 if (!oseq->os_destroys_in_progress) {
1314 CERROR("%s:["LPU64"] destroys_in_progress already"
1315 " cleared\n", ofd_name(ofd), seq);
1316 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
1319 diff = oid - ofd_seq_last_oid(oseq);
1320 CDEBUG(D_HA, "ofd_last_id() = "LPU64" -> diff = %d\n",
1321 ofd_seq_last_oid(oseq), diff);
1322 if (-diff > OST_MAX_PRECREATE) {
1323 /* FIXME: should reset precreate_next_id on MDS */
1325 } else if (diff < 0) {
1326 rc = ofd_orphans_destroy(tsi->tsi_env, exp,
1328 oseq->os_destroys_in_progress = 0;
1330 /* XXX: Used by MDS for the first time! */
1331 oseq->os_destroys_in_progress = 0;
1334 if (unlikely(exp->exp_filter_data.fed_lastid_gen !=
1335 ofd->ofd_lastid_gen)) {
1336 /* Keep the export ref so we can send the reply. */
1337 ofd_obd_disconnect(class_export_get(exp));
1338 GOTO(out_nolock, rc = -ENOTCONN);
1341 mutex_lock(&oseq->os_create_lock);
1342 if (lustre_msg_get_conn_cnt(tgt_ses_req(tsi)->rq_reqmsg) <
1343 exp->exp_conn_cnt) {
1344 CERROR("%s: dropping old precreate request\n",
1348 /* only precreate if seq is 0, IDIF or normal and also o_id
1349 * must be specfied */
1350 if ((!fid_seq_is_mdt(seq) && !fid_seq_is_norm(seq) &&
1351 !fid_seq_is_idif(seq)) || oid == 0) {
1352 diff = 1; /* shouldn't we create this right now? */
1354 diff = oid - ofd_seq_last_oid(oseq);
1355 /* Do sync create if the seq is about to used up */
1356 if (fid_seq_is_idif(seq) || fid_seq_is_mdt0(seq)) {
1357 if (unlikely(oid >= IDIF_MAX_OID - 1))
1359 } else if (fid_seq_is_norm(seq)) {
1361 LUSTRE_DATA_SEQ_MAX_WIDTH - 1))
1364 CERROR("%s : invalid o_seq "DOSTID"\n",
1365 ofd_name(ofd), POSTID(&oa->o_oi));
1366 GOTO(out, rc = -EINVAL);
1371 cfs_time_t enough_time = cfs_time_shift(DISK_TIMEOUT);
1376 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1377 !(oa->o_flags & OBD_FL_DELORPHAN)) {
1378 /* don't enforce grant during orphan recovery */
1379 rc = ofd_grant_create(tsi->tsi_env,
1380 ofd_obd(ofd)->obd_self_export,
1383 CDEBUG(D_HA, "%s: failed to acquire grant "
1384 "space for precreate (%d): rc = %d\n",
1385 ofd_name(ofd), diff, rc);
1390 /* This can happen if a new OST is formatted and installed
1391 * in place of an old one at the same index. Instead of
1392 * precreating potentially millions of deleted old objects
1393 * (possibly filling the OST), only precreate the last batch.
1394 * LFSCK will eventually clean up any orphans. LU-14 */
1395 if (diff > 5 * OST_MAX_PRECREATE) {
1396 diff = OST_MAX_PRECREATE / 2;
1397 LCONSOLE_WARN("%s: precreate FID "DOSTID" is over %u "
1398 "larger than the LAST_ID "DOSTID", only "
1399 "precreating the last %u objects.\n",
1400 ofd_name(ofd), POSTID(&oa->o_oi),
1401 5 * OST_MAX_PRECREATE,
1402 POSTID(&oseq->os_oi), diff);
1403 ofd_seq_last_oid_set(oseq, ostid_id(&oa->o_oi) - diff);
1407 next_id = ofd_seq_last_oid(oseq) + 1;
1408 count = ofd_precreate_batch(ofd, diff);
1410 CDEBUG(D_HA, "%s: reserve %d objects in group "LPX64
1411 " at "LPU64"\n", ofd_name(ofd),
1412 count, seq, next_id);
1414 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1415 && cfs_time_after(jiffies, enough_time)) {
1416 CDEBUG(D_HA, "%s: Slow creates, %d/%d objects"
1417 " created at a rate of %d/s\n",
1418 ofd_name(ofd), created, diff + created,
1419 created / DISK_TIMEOUT);
1423 rc = ofd_precreate_objects(tsi->tsi_env, ofd, next_id,
1424 oseq, count, sync_trans);
1428 } else if (rc < 0) {
1434 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1435 LCONSOLE_WARN("%s: can't create the same count of"
1436 " objects when replaying the request"
1437 " (diff is %d). see LU-4621\n",
1438 ofd_name(ofd), diff);
1441 /* some objects got created, we can return
1442 * them, even if last creation failed */
1445 CERROR("%s: unable to precreate: rc = %d\n",
1448 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1449 !(oa->o_flags & OBD_FL_DELORPHAN))
1450 ofd_grant_commit(tsi->tsi_env,
1451 ofd_obd(ofd)->obd_self_export, rc);
1453 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
1456 ofd_counter_incr(exp, LPROC_OFD_STATS_CREATE,
1459 mutex_unlock(&oseq->os_create_lock);
1462 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
1463 struct ofd_thread_info *info = ofd_info(tsi->tsi_env);
1464 struct lu_fid *fid = &info->fti_fid;
1466 /* For compatible purpose, it needs to convert back to
1467 * OST ID before put it on wire. */
1468 *fid = rep_oa->o_oi.oi_fid;
1469 fid_to_ostid(fid, &rep_oa->o_oi);
1471 rep_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
1473 ofd_seq_put(tsi->tsi_env, oseq);
1476 up_read(&ofd->ofd_lastid_rwsem);
1480 static int ofd_destroy_hdl(struct tgt_session_info *tsi)
1482 const struct ost_body *body = tsi->tsi_ost_body;
1483 struct ost_body *repbody;
1484 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1485 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1486 struct lu_fid *fid = &fti->fti_fid;
1493 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1496 /* This is old case for clients before Lustre 2.4 */
1497 /* If there's a DLM request, cancel the locks mentioned in it */
1498 if (req_capsule_field_present(tsi->tsi_pill, &RMF_DLM_REQ,
1500 struct ldlm_request *dlm;
1502 dlm = req_capsule_client_get(tsi->tsi_pill, &RMF_DLM_REQ);
1505 ldlm_request_cancel(tgt_ses_req(tsi), dlm, 0);
1508 *fid = body->oa.o_oi.oi_fid;
1509 oid = ostid_id(&body->oa.o_oi);
1512 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1514 /* check that o_misc makes sense */
1515 if (body->oa.o_valid & OBD_MD_FLOBJCOUNT)
1516 count = body->oa.o_misc;
1518 count = 1; /* default case - single destroy */
1520 CDEBUG(D_HA, "%s: Destroy object "DOSTID" count %d\n", ofd_name(ofd),
1521 POSTID(&body->oa.o_oi), count);
1526 lrc = ofd_destroy_by_fid(tsi->tsi_env, ofd, fid, 0);
1527 if (lrc == -ENOENT) {
1529 "%s: destroying non-existent object "DFID"\n",
1530 ofd_name(ofd), PFID(fid));
1531 /* rewrite rc with -ENOENT only if it is 0 */
1534 } else if (lrc != 0) {
1535 CERROR("%s: error destroying object "DFID": %d\n",
1536 ofd_name(ofd), PFID(fid), lrc);
1542 lrc = fid_set_id(fid, oid);
1543 if (unlikely(lrc != 0 && count > 0))
1544 GOTO(out, rc = lrc);
1547 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_DESTROY,
1553 fid_to_ostid(fid, &repbody->oa.o_oi);
1557 static int ofd_statfs_hdl(struct tgt_session_info *tsi)
1559 struct obd_statfs *osfs;
1564 osfs = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_STATFS);
1566 rc = ofd_statfs(tsi->tsi_env, tsi->tsi_exp, osfs,
1567 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), 0);
1569 CERROR("%s: statfs failed: rc = %d\n",
1570 tgt_name(tsi->tsi_tgt), rc);
1572 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_EINPROGRESS))
1575 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_STATFS,
1581 static int ofd_sync_hdl(struct tgt_session_info *tsi)
1583 struct ost_body *body = tsi->tsi_ost_body;
1584 struct ost_body *repbody;
1585 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1586 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1587 struct ofd_object *fo = NULL;
1592 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1594 /* if no objid is specified, it means "sync whole filesystem" */
1595 if (!fid_is_zero(&tsi->tsi_fid)) {
1596 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1598 RETURN(PTR_ERR(fo));
1601 rc = tgt_sync(tsi->tsi_env, tsi->tsi_tgt,
1602 fo != NULL ? ofd_object_child(fo) : NULL,
1603 repbody->oa.o_size, repbody->oa.o_blocks);
1607 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SYNC,
1612 repbody->oa.o_oi = body->oa.o_oi;
1613 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1615 rc = ofd_attr_get(tsi->tsi_env, fo, &fti->fti_attr);
1617 obdo_from_la(&repbody->oa, &fti->fti_attr,
1620 /* don't return rc from getattr */
1625 ofd_object_put(tsi->tsi_env, fo);
1629 static int ofd_punch_hdl(struct tgt_session_info *tsi)
1631 const struct obdo *oa = &tsi->tsi_ost_body->oa;
1632 struct ost_body *repbody;
1633 struct ofd_thread_info *info = tsi2ofd_info(tsi);
1634 struct ldlm_namespace *ns = tsi->tsi_tgt->lut_obd->obd_namespace;
1635 struct ldlm_resource *res;
1636 struct ofd_object *fo;
1637 struct filter_fid *ff = NULL;
1639 struct lustre_handle lh = { 0, };
1646 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
1647 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
1649 if ((oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
1650 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
1651 RETURN(err_serious(-EPROTO));
1653 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1654 if (repbody == NULL)
1655 RETURN(err_serious(-ENOMEM));
1657 /* punch start,end are passed in o_size,o_blocks throught wire */
1661 if (end != OBD_OBJECT_EOF) /* Only truncate is supported */
1664 /* standard truncate optimization: if file body is completely
1665 * destroyed, don't send data back to the server. */
1667 flags |= LDLM_FL_AST_DISCARD_DATA;
1669 repbody->oa.o_oi = oa->o_oi;
1670 repbody->oa.o_valid = OBD_MD_FLID;
1672 srvlock = oa->o_valid & OBD_MD_FLFLAGS &&
1673 oa->o_flags & OBD_FL_SRVLOCK;
1676 rc = tgt_extent_lock(ns, &tsi->tsi_resid, start, end, &lh,
1682 CDEBUG(D_INODE, "calling punch for object "DFID", valid = "LPX64
1683 ", start = "LPD64", end = "LPD64"\n", PFID(&tsi->tsi_fid),
1684 oa->o_valid, start, end);
1686 fo = ofd_object_find_exists(tsi->tsi_env, ofd_exp(tsi->tsi_exp),
1689 GOTO(out, rc = PTR_ERR(fo));
1691 la_from_obdo(&info->fti_attr, oa,
1692 OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME);
1693 info->fti_attr.la_size = start;
1694 info->fti_attr.la_valid |= LA_SIZE;
1696 if (oa->o_valid & OBD_MD_FLFID) {
1697 ff = &info->fti_mds_fid;
1698 ofd_prepare_fidea(ff, oa);
1701 rc = ofd_object_punch(tsi->tsi_env, fo, start, end, &info->fti_attr,
1702 ff, (struct obdo *)oa);
1706 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_PUNCH,
1710 ofd_object_put(tsi->tsi_env, fo);
1713 tgt_extent_unlock(&lh, LCK_PW);
1715 /* we do not call this before to avoid lu_object_find() in
1716 * ->lvbo_update() holding another reference on the object.
1717 * otherwise concurrent destroy can make the object unavailable
1718 * for 2nd lu_object_find() waiting for the first reference
1719 * to go... deadlock! */
1720 res = ldlm_resource_get(ns, NULL, &tsi->tsi_resid,
1723 ldlm_res_lvbo_update(res, NULL, 0);
1724 ldlm_resource_putref(res);
1730 static int ofd_quotactl(struct tgt_session_info *tsi)
1732 struct obd_quotactl *oqctl, *repoqc;
1737 oqctl = req_capsule_client_get(tsi->tsi_pill, &RMF_OBD_QUOTACTL);
1739 RETURN(err_serious(-EPROTO));
1741 repoqc = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_QUOTACTL);
1743 RETURN(err_serious(-ENOMEM));
1745 /* report success for quota on/off for interoperability with current MDT
1747 if (oqctl->qc_cmd == Q_QUOTAON || oqctl->qc_cmd == Q_QUOTAOFF)
1751 rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom, repoqc);
1753 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_QUOTACTL,
1759 /* High priority request handlers for OFD */
1761 /* prolong locks for the current service time of the corresponding
1762 * portal (= OST_IO_PORTAL)
1764 static inline int prolong_timeout(struct ptlrpc_request *req)
1766 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1769 return obd_timeout / 2;
1771 return max(at_est2timeout(at_get(&svcpt->scp_at_estimate)),
1775 static int ofd_prolong_one_lock(struct tgt_session_info *tsi,
1776 struct ldlm_lock *lock,
1777 struct ldlm_extent *extent, int timeout)
1780 if (lock->l_flags & LDLM_FL_DESTROYED) /* lock already cancelled */
1783 /* XXX: never try to grab resource lock here because we're inside
1784 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1785 * res lock and then exp_bl_list_lock. */
1787 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1788 /* ignore locks not being cancelled */
1791 LDLM_DEBUG(lock, "refreshed for req x"LPU64" ext("LPU64"->"LPU64") "
1792 "to %ds.\n", tgt_ses_req(tsi)->rq_xid, extent->start,
1793 extent->end, timeout);
1795 /* OK. this is a possible lock the user holds doing I/O
1796 * let's refresh eviction timer for it */
1797 ldlm_refresh_waiting_lock(lock, timeout);
1801 static int ofd_prolong_extent_locks(struct tgt_session_info *tsi,
1802 __u64 start, __u64 end)
1804 struct obd_export *exp = tsi->tsi_exp;
1805 struct obdo *oa = &tsi->tsi_ost_body->oa;
1806 struct ldlm_extent extent = {
1810 struct ldlm_lock *lock;
1811 int timeout = prolong_timeout(tgt_ses_req(tsi));
1816 if (oa->o_valid & OBD_MD_FLHANDLE) {
1817 /* mostly a request should be covered by only one lock, try
1819 lock = ldlm_handle2lock(&oa->o_handle);
1821 /* Fast path to check if the lock covers the whole IO
1822 * region exclusively. */
1823 if (lock->l_granted_mode == LCK_PW &&
1824 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1827 LASSERT(lock->l_export == exp);
1828 lock_count = ofd_prolong_one_lock(tsi, lock,
1830 LDLM_LOCK_PUT(lock);
1833 LDLM_LOCK_PUT(lock);
1837 spin_lock_bh(&exp->exp_bl_list_lock);
1838 list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1839 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1840 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1842 if (!ldlm_res_eq(&tsi->tsi_resid, &lock->l_resource->lr_name))
1845 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1849 lock_count += ofd_prolong_one_lock(tsi, lock, &extent, timeout);
1851 spin_unlock_bh(&exp->exp_bl_list_lock);
1857 * Returns 1 if the given PTLRPC matches the given LDLM lock, or 0 if it does
1860 static int ofd_rw_hpreq_lock_match(struct ptlrpc_request *req,
1861 struct ldlm_lock *lock)
1863 struct niobuf_remote *rnb;
1864 struct obd_ioobj *ioo;
1866 struct ldlm_extent ext;
1867 __u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
1871 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1872 LASSERT(ioo != NULL);
1874 rnb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1875 LASSERT(rnb != NULL);
1877 ext.start = rnb->rnb_offset;
1878 rnb += ioo->ioo_bufcnt - 1;
1879 ext.end = rnb->rnb_offset + rnb->rnb_len - 1;
1881 LASSERT(lock->l_resource != NULL);
1882 if (!ostid_res_name_eq(&ioo->ioo_oid, &lock->l_resource->lr_name))
1886 if (opc == OST_READ)
1889 if (!(lock->l_granted_mode & mode))
1892 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1896 * High-priority queue request check for whether the given PTLRPC request
1897 * (\a req) is blocking an LDLM lock cancel.
1899 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1900 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1902 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1903 * function looks only at OST_READs and OST_WRITEs.
1905 static int ofd_rw_hpreq_check(struct ptlrpc_request *req)
1907 struct tgt_session_info *tsi;
1908 struct obd_ioobj *ioo;
1909 struct niobuf_remote *rnb;
1915 /* Don't use tgt_ses_info() to get session info, because lock_match()
1916 * can be called while request has no processing thread yet. */
1917 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
1918 LASSERT(tsi != NULL);
1921 * Use LASSERT below because malformed RPCs should have
1922 * been filtered out in tgt_hpreq_handler().
1924 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1925 LASSERT(ioo != NULL);
1927 rnb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1928 LASSERT(rnb != NULL);
1929 LASSERT(!(rnb->rnb_flags & OBD_BRW_SRVLOCK));
1931 start = rnb->rnb_offset;
1932 rnb += ioo->ioo_bufcnt - 1;
1933 end = rnb->rnb_offset + rnb->rnb_len - 1;
1935 DEBUG_REQ(D_RPCTRACE, req, "%s %s: refresh rw locks: "DFID
1936 " ("LPU64"->"LPU64")\n",
1937 tgt_name(tsi->tsi_tgt), current->comm,
1938 PFID(&tsi->tsi_fid), start, end);
1940 lock_count = ofd_prolong_extent_locks(tsi, start, end);
1942 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1943 tgt_name(tsi->tsi_tgt), lock_count, req);
1945 RETURN(lock_count > 0);
1948 static void ofd_rw_hpreq_fini(struct ptlrpc_request *req)
1950 ofd_rw_hpreq_check(req);
1954 * Like tgt_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1956 static int ofd_punch_hpreq_lock_match(struct ptlrpc_request *req,
1957 struct ldlm_lock *lock)
1959 struct tgt_session_info *tsi;
1961 /* Don't use tgt_ses_info() to get session info, because lock_match()
1962 * can be called while request has no processing thread yet. */
1963 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
1964 LASSERT(tsi != NULL);
1966 LASSERT(tsi->tsi_ost_body != NULL);
1967 if (tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLHANDLE &&
1968 tsi->tsi_ost_body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1975 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1977 static int ofd_punch_hpreq_check(struct ptlrpc_request *req)
1979 struct tgt_session_info *tsi;
1985 /* Don't use tgt_ses_info() to get session info, because lock_match()
1986 * can be called while request has no processing thread yet. */
1987 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
1988 LASSERT(tsi != NULL);
1989 oa = &tsi->tsi_ost_body->oa;
1991 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS &&
1992 oa->o_flags & OBD_FL_SRVLOCK));
1995 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1996 tgt_name(tsi->tsi_tgt), tsi->tsi_resid.name[0],
1997 tsi->tsi_resid.name[1], oa->o_size, oa->o_blocks);
1999 lock_count = ofd_prolong_extent_locks(tsi, oa->o_size, oa->o_blocks);
2001 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
2002 tgt_name(tsi->tsi_tgt), lock_count, req);
2004 RETURN(lock_count > 0);
2007 static void ofd_punch_hpreq_fini(struct ptlrpc_request *req)
2009 ofd_punch_hpreq_check(req);
2012 struct ptlrpc_hpreq_ops ofd_hpreq_rw = {
2013 .hpreq_lock_match = ofd_rw_hpreq_lock_match,
2014 .hpreq_check = ofd_rw_hpreq_check,
2015 .hpreq_fini = ofd_rw_hpreq_fini
2018 struct ptlrpc_hpreq_ops ofd_hpreq_punch = {
2019 .hpreq_lock_match = ofd_punch_hpreq_lock_match,
2020 .hpreq_check = ofd_punch_hpreq_check,
2021 .hpreq_fini = ofd_punch_hpreq_fini
2024 /** Assign high priority operations to the IO requests */
2025 static void ofd_hp_brw(struct tgt_session_info *tsi)
2027 struct niobuf_remote *rnb;
2028 struct obd_ioobj *ioo;
2032 ioo = req_capsule_client_get(tsi->tsi_pill, &RMF_OBD_IOOBJ);
2033 LASSERT(ioo != NULL); /* must exist after request preprocessing */
2034 if (ioo->ioo_bufcnt > 0) {
2035 rnb = req_capsule_client_get(tsi->tsi_pill, &RMF_NIOBUF_REMOTE);
2036 LASSERT(rnb != NULL); /* must exist after request preprocessing */
2038 /* no high priority if server lock is needed */
2039 if (rnb->rnb_flags & OBD_BRW_SRVLOCK)
2042 tgt_ses_req(tsi)->rq_ops = &ofd_hpreq_rw;
2045 static void ofd_hp_punch(struct tgt_session_info *tsi)
2047 LASSERT(tsi->tsi_ost_body != NULL); /* must exists if we are here */
2048 /* no high-priority if server lock is needed */
2049 if (tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLFLAGS &&
2050 tsi->tsi_ost_body->oa.o_flags & OBD_FL_SRVLOCK)
2052 tgt_ses_req(tsi)->rq_ops = &ofd_hpreq_punch;
2055 #define OBD_FAIL_OST_READ_NET OBD_FAIL_OST_BRW_NET
2056 #define OBD_FAIL_OST_WRITE_NET OBD_FAIL_OST_BRW_NET
2057 #define OST_BRW_READ OST_READ
2058 #define OST_BRW_WRITE OST_WRITE
2060 static struct tgt_handler ofd_tgt_handlers[] = {
2061 TGT_RPC_HANDLER(OST_FIRST_OPC,
2062 0, OST_CONNECT, tgt_connect,
2063 &RQF_CONNECT, LUSTRE_OBD_VERSION),
2064 TGT_RPC_HANDLER(OST_FIRST_OPC,
2065 0, OST_DISCONNECT, tgt_disconnect,
2066 &RQF_OST_DISCONNECT, LUSTRE_OBD_VERSION),
2067 TGT_RPC_HANDLER(OST_FIRST_OPC,
2068 0, OST_SET_INFO, ofd_set_info_hdl,
2069 &RQF_OBD_SET_INFO, LUSTRE_OST_VERSION),
2070 TGT_OST_HDL(0, OST_GET_INFO, ofd_get_info_hdl),
2071 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO, OST_GETATTR, ofd_getattr_hdl),
2072 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR,
2073 OST_SETATTR, ofd_setattr_hdl),
2074 TGT_OST_HDL(0 | HABEO_REFERO | MUTABOR,
2075 OST_CREATE, ofd_create_hdl),
2076 TGT_OST_HDL(0 | HABEO_REFERO | MUTABOR,
2077 OST_DESTROY, ofd_destroy_hdl),
2078 TGT_OST_HDL(0 | HABEO_REFERO, OST_STATFS, ofd_statfs_hdl),
2079 TGT_OST_HDL_HP(HABEO_CORPUS| HABEO_REFERO,
2080 OST_BRW_READ, tgt_brw_read,
2082 /* don't set CORPUS flag for brw_write because -ENOENT may be valid case */
2083 TGT_OST_HDL_HP(HABEO_CORPUS| MUTABOR, OST_BRW_WRITE, tgt_brw_write,
2085 TGT_OST_HDL_HP(HABEO_CORPUS| HABEO_REFERO | MUTABOR,
2086 OST_PUNCH, ofd_punch_hdl,
2088 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO, OST_SYNC, ofd_sync_hdl),
2089 TGT_OST_HDL(0 | HABEO_REFERO, OST_QUOTACTL, ofd_quotactl),
2092 static struct tgt_opc_slice ofd_common_slice[] = {
2094 .tos_opc_start = OST_FIRST_OPC,
2095 .tos_opc_end = OST_LAST_OPC,
2096 .tos_hs = ofd_tgt_handlers
2099 .tos_opc_start = OBD_FIRST_OPC,
2100 .tos_opc_end = OBD_LAST_OPC,
2101 .tos_hs = tgt_obd_handlers
2104 .tos_opc_start = LDLM_FIRST_OPC,
2105 .tos_opc_end = LDLM_LAST_OPC,
2106 .tos_hs = tgt_dlm_handlers
2109 .tos_opc_start = OUT_UPDATE_FIRST_OPC,
2110 .tos_opc_end = OUT_UPDATE_LAST_OPC,
2111 .tos_hs = tgt_out_handlers
2114 .tos_opc_start = SEQ_FIRST_OPC,
2115 .tos_opc_end = SEQ_LAST_OPC,
2116 .tos_hs = seq_handlers
2119 .tos_opc_start = LFSCK_FIRST_OPC,
2120 .tos_opc_end = LFSCK_LAST_OPC,
2121 .tos_hs = tgt_lfsck_handlers
2128 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
2129 struct lu_device_type *ldt, struct lustre_cfg *cfg)
2131 const char *dev = lustre_cfg_string(cfg, 0);
2132 struct ofd_thread_info *info = NULL;
2133 struct obd_device *obd;
2134 struct obd_statfs *osfs;
2139 obd = class_name2obd(dev);
2141 CERROR("Cannot find obd with name %s\n", dev);
2145 rc = lu_env_refill((struct lu_env *)env);
2149 obd->u.obt.obt_magic = OBT_MAGIC;
2151 m->ofd_fmd_max_num = OFD_FMD_MAX_NUM_DEFAULT;
2152 m->ofd_fmd_max_age = OFD_FMD_MAX_AGE_DEFAULT;
2154 spin_lock_init(&m->ofd_flags_lock);
2155 m->ofd_raid_degraded = 0;
2156 m->ofd_syncjournal = 0;
2158 m->ofd_grant_compat_disable = 0;
2159 m->ofd_soft_sync_limit = OFD_SOFT_SYNC_LIMIT_DEFAULT;
2162 spin_lock_init(&m->ofd_osfs_lock);
2163 m->ofd_osfs_age = cfs_time_shift_64(-1000);
2164 m->ofd_osfs_unstable = 0;
2165 m->ofd_statfs_inflight = 0;
2166 m->ofd_osfs_inflight = 0;
2169 spin_lock_init(&m->ofd_grant_lock);
2170 m->ofd_tot_dirty = 0;
2171 m->ofd_tot_granted = 0;
2172 m->ofd_tot_pending = 0;
2173 m->ofd_seq_count = 0;
2174 init_waitqueue_head(&m->ofd_inconsistency_thread.t_ctl_waitq);
2175 INIT_LIST_HEAD(&m->ofd_inconsistency_list);
2176 spin_lock_init(&m->ofd_inconsistency_lock);
2178 spin_lock_init(&m->ofd_batch_lock);
2179 init_rwsem(&m->ofd_lastid_rwsem);
2181 obd->u.filter.fo_fl_oss_capa = 0;
2182 INIT_LIST_HEAD(&obd->u.filter.fo_capa_keys);
2183 obd->u.filter.fo_capa_hash = init_capa_hash();
2184 if (obd->u.filter.fo_capa_hash == NULL)
2187 m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops;
2188 m->ofd_dt_dev.dd_lu_dev.ld_obd = obd;
2189 /* set this lu_device to obd, because error handling need it */
2190 obd->obd_lu_dev = &m->ofd_dt_dev.dd_lu_dev;
2192 rc = ofd_procfs_init(m);
2194 CERROR("Can't init ofd lprocfs, rc %d\n", rc);
2198 /* No connection accepted until configurations will finish */
2199 spin_lock(&obd->obd_dev_lock);
2200 obd->obd_no_conn = 1;
2201 spin_unlock(&obd->obd_dev_lock);
2202 obd->obd_replayable = 1;
2203 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
2204 char *str = lustre_cfg_string(cfg, 4);
2206 if (strchr(str, 'n')) {
2207 CWARN("%s: recovery disabled\n", obd->obd_name);
2208 obd->obd_replayable = 0;
2212 info = ofd_info_init(env, NULL);
2216 rc = ofd_stack_init(env, m, cfg);
2218 CERROR("Can't init device stack, rc %d\n", rc);
2219 GOTO(err_fini_proc, rc);
2222 ofd_procfs_add_brw_stats_symlink(m);
2224 /* populate cached statfs data */
2225 osfs = &ofd_info(env)->fti_u.osfs;
2226 rc = ofd_statfs_internal(env, m, osfs, 0, NULL);
2228 CERROR("%s: can't get statfs data, rc %d\n", obd->obd_name, rc);
2229 GOTO(err_fini_stack, rc);
2231 if (!IS_PO2(osfs->os_bsize)) {
2232 CERROR("%s: blocksize (%d) is not a power of 2\n",
2233 obd->obd_name, osfs->os_bsize);
2234 GOTO(err_fini_stack, rc = -EPROTO);
2236 m->ofd_blockbits = fls(osfs->os_bsize) - 1;
2238 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_DEFAULT;
2239 if (osfs->os_bsize * osfs->os_blocks < OFD_PRECREATE_SMALL_FS)
2240 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_SMALL;
2242 snprintf(info->fti_u.name, sizeof(info->fti_u.name), "%s-%s",
2243 "filter"/*LUSTRE_OST_NAME*/, obd->obd_uuid.uuid);
2244 m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name,
2245 LDLM_NAMESPACE_SERVER,
2246 LDLM_NAMESPACE_GREEDY,
2248 if (m->ofd_namespace == NULL)
2249 GOTO(err_fini_stack, rc = -ENOMEM);
2250 /* set obd_namespace for compatibility with old code */
2251 obd->obd_namespace = m->ofd_namespace;
2252 ldlm_register_intent(m->ofd_namespace, ofd_intent_policy);
2253 m->ofd_namespace->ns_lvbo = &ofd_lvbo;
2254 m->ofd_namespace->ns_lvbp = m;
2256 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
2257 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
2259 dt_conf_get(env, m->ofd_osd, &m->ofd_dt_conf);
2261 /* Allow at most ddp_grant_reserved% of the available filesystem space
2262 * to be granted to clients, so that any errors in the grant overhead
2263 * calculations do not allow granting more space to clients than can be
2264 * written. Assumes that in aggregate the grant overhead calculations do
2265 * not have more than ddp_grant_reserved% estimation error in them. */
2266 m->ofd_grant_ratio =
2267 ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved);
2269 rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd, ofd_common_slice,
2270 OBD_FAIL_OST_ALL_REQUEST_NET,
2271 OBD_FAIL_OST_ALL_REPLY_NET);
2273 GOTO(err_free_ns, rc);
2275 rc = ofd_fs_setup(env, m, obd);
2277 GOTO(err_fini_lut, rc);
2279 rc = ofd_start_inconsistency_verification_thread(m);
2281 GOTO(err_fini_fs, rc);
2286 ofd_fs_cleanup(env, m);
2288 tgt_fini(env, &m->ofd_lut);
2290 ldlm_namespace_free(m->ofd_namespace, 0, obd->obd_force);
2291 obd->obd_namespace = m->ofd_namespace = NULL;
2293 ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev);
2299 static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
2301 struct obd_device *obd = ofd_obd(m);
2302 struct lu_device *d = &m->ofd_dt_dev.dd_lu_dev;
2303 struct lfsck_stop stop;
2305 stop.ls_status = LS_PAUSED;
2307 lfsck_stop(env, m->ofd_osd, &stop);
2308 target_recovery_fini(obd);
2309 obd_exports_barrier(obd);
2310 obd_zombie_barrier();
2312 tgt_fini(env, &m->ofd_lut);
2313 ofd_stop_inconsistency_verification_thread(m);
2314 lfsck_degister(env, m->ofd_osd);
2315 ofd_fs_cleanup(env, m);
2317 ofd_free_capa_keys(m);
2318 cleanup_capa_hash(obd->u.filter.fo_capa_hash);
2320 if (m->ofd_namespace != NULL) {
2321 ldlm_namespace_free(m->ofd_namespace, NULL,
2322 d->ld_obd->obd_force);
2323 d->ld_obd->obd_namespace = m->ofd_namespace = NULL;
2326 ofd_stack_fini(env, m, &m->ofd_dt_dev.dd_lu_dev);
2328 LASSERT(atomic_read(&d->ld_ref) == 0);
2329 server_put_mount(obd->obd_name, true);
2333 static struct lu_device *ofd_device_fini(const struct lu_env *env,
2334 struct lu_device *d)
2337 ofd_fini(env, ofd_dev(d));
2341 static struct lu_device *ofd_device_free(const struct lu_env *env,
2342 struct lu_device *d)
2344 struct ofd_device *m = ofd_dev(d);
2346 dt_device_fini(&m->ofd_dt_dev);
2351 static struct lu_device *ofd_device_alloc(const struct lu_env *env,
2352 struct lu_device_type *t,
2353 struct lustre_cfg *cfg)
2355 struct ofd_device *m;
2356 struct lu_device *l;
2361 return ERR_PTR(-ENOMEM);
2363 l = &m->ofd_dt_dev.dd_lu_dev;
2364 dt_device_init(&m->ofd_dt_dev, t);
2365 rc = ofd_init0(env, m, t, cfg);
2367 ofd_device_free(env, l);
2374 /* thread context key constructor/destructor */
2375 LU_KEY_INIT_FINI(ofd, struct ofd_thread_info);
2377 static void ofd_key_exit(const struct lu_context *ctx,
2378 struct lu_context_key *key, void *data)
2380 struct ofd_thread_info *info = data;
2382 info->fti_env = NULL;
2383 info->fti_exp = NULL;
2386 info->fti_pre_version = 0;
2389 memset(&info->fti_attr, 0, sizeof info->fti_attr);
2392 struct lu_context_key ofd_thread_key = {
2393 .lct_tags = LCT_DT_THREAD,
2394 .lct_init = ofd_key_init,
2395 .lct_fini = ofd_key_fini,
2396 .lct_exit = ofd_key_exit
2399 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
2400 LU_TYPE_INIT_FINI(ofd, &ofd_thread_key);
2402 static struct lu_device_type_operations ofd_device_type_ops = {
2403 .ldto_init = ofd_type_init,
2404 .ldto_fini = ofd_type_fini,
2406 .ldto_start = ofd_type_start,
2407 .ldto_stop = ofd_type_stop,
2409 .ldto_device_alloc = ofd_device_alloc,
2410 .ldto_device_free = ofd_device_free,
2411 .ldto_device_fini = ofd_device_fini
2414 static struct lu_device_type ofd_device_type = {
2415 .ldt_tags = LU_DEVICE_DT,
2416 .ldt_name = LUSTRE_OST_NAME,
2417 .ldt_ops = &ofd_device_type_ops,
2418 .ldt_ctx_tags = LCT_DT_THREAD
2421 int __init ofd_init(void)
2425 rc = lu_kmem_init(ofd_caches);
2429 rc = ofd_fmd_init();
2431 lu_kmem_fini(ofd_caches);
2435 rc = class_register_type(&ofd_obd_ops, NULL, true, NULL,
2436 #ifndef HAVE_ONLY_PROCFS_SEQ
2439 LUSTRE_OST_NAME, &ofd_device_type);
2443 void __exit ofd_exit(void)
2446 lu_kmem_fini(ofd_caches);
2447 class_unregister_type(LUSTRE_OST_NAME);
2450 MODULE_AUTHOR("Whamcloud, Inc. <http://www.whamcloud.com/>");
2451 MODULE_DESCRIPTION("Lustre Object Filtering Device");
2452 MODULE_LICENSE("GPL");
2454 module_init(ofd_init);
2455 module_exit(ofd_exit);