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.
36 * lustre/ofd/ofd_obd.c
38 * Author: Andreas Dilger <adilger@whamcloud.com>
39 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
40 * Author: Mike Pershin <tappro@whamcloud.com>
43 #define DEBUG_SUBSYSTEM S_FILTER
45 #include <lustre/lustre_idl.h>
46 #include "ofd_internal.h"
47 #include <obd_cksum.h>
48 #include <lustre_quota.h>
49 #include <lustre_lfsck.h>
51 static int ofd_export_stats_init(struct ofd_device *ofd,
52 struct obd_export *exp, void *client_nid)
54 struct obd_device *obd = ofd_obd(ofd);
55 struct nid_stat *stats;
61 LASSERT(obd->obd_uses_nid_stats);
63 if (obd_uuid_equals(&exp->exp_client_uuid, &obd->obd_uuid))
64 /* Self-export gets no proc entry */
67 rc = lprocfs_exp_setup(exp, client_nid, &newnid);
69 /* Mask error for already created
79 stats = exp->exp_nid_stats;
80 LASSERT(stats != NULL);
82 num_stats = NUM_OBD_STATS + LPROC_OFD_STATS_LAST;
84 stats->nid_stats = lprocfs_alloc_stats(num_stats,
85 LPROCFS_STATS_FLAG_NOPERCPU);
86 if (stats->nid_stats == NULL)
89 lprocfs_init_ops_stats(LPROC_OFD_STATS_LAST, stats->nid_stats);
90 ofd_stats_counter_init(stats->nid_stats);
91 rc = lprocfs_register_stats(stats->nid_proc, "stats",
96 rc = lprocfs_nid_ldlm_stats_init(stats);
98 lprocfs_free_stats(&stats->nid_stats);
107 static int ofd_parse_connect_data(const struct lu_env *env,
108 struct obd_export *exp,
109 struct obd_connect_data *data,
112 struct ofd_device *ofd = ofd_exp(exp);
113 struct filter_export_data *fed = &exp->exp_filter_data;
118 CDEBUG(D_RPCTRACE, "%s: cli %s/%p ocd_connect_flags: "LPX64
119 " ocd_version: %x ocd_grant: %d ocd_index: %u"
121 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
122 data->ocd_connect_flags, data->ocd_version,
123 data->ocd_grant, data->ocd_index, data->ocd_group);
125 if (fed->fed_group != 0 && fed->fed_group != data->ocd_group) {
126 CWARN("!!! This export (nid %s) used object group %d "
127 "earlier; now it's trying to use group %d! This could "
128 "be a bug in the MDS. Please report to "
129 "http://bugs.whamcloud.com/\n",
130 obd_export_nid2str(exp), fed->fed_group,
134 fed->fed_group = data->ocd_group;
136 data->ocd_connect_flags &= OST_CONNECT_SUPPORTED;
137 data->ocd_version = LUSTRE_VERSION_CODE;
139 /* Kindly make sure the SKIP_ORPHAN flag is from MDS. */
140 if (data->ocd_connect_flags & OBD_CONNECT_MDS)
141 CDEBUG(D_HA, "%s: Received MDS connection for group %u\n",
142 exp->exp_obd->obd_name, data->ocd_group);
143 else if (data->ocd_connect_flags & OBD_CONNECT_SKIP_ORPHAN)
146 if (ofd_grant_param_supp(exp)) {
147 exp->exp_filter_data.fed_pagesize = data->ocd_blocksize;
148 /* ocd_{blocksize,inodespace} are log2 values */
149 data->ocd_blocksize = ofd->ofd_blockbits;
150 data->ocd_inodespace = ofd->ofd_dt_conf.ddp_inodespace;
151 /* ocd_grant_extent is in 1K blocks */
152 data->ocd_grant_extent = ofd->ofd_dt_conf.ddp_grant_frag >> 10;
155 if (data->ocd_connect_flags & OBD_CONNECT_GRANT)
156 data->ocd_grant = ofd_grant_connect(env, exp, data->ocd_grant,
159 if (data->ocd_connect_flags & OBD_CONNECT_INDEX) {
160 struct lr_server_data *lsd = &ofd->ofd_lut.lut_lsd;
161 int index = lsd->lsd_osd_index;
163 if (index != data->ocd_index) {
164 LCONSOLE_ERROR_MSG(0x136, "Connection from %s to index"
165 " %u doesn't match actual OST index"
166 " %u in last_rcvd file, bad "
168 obd_export_nid2str(exp), index,
172 if (!(lsd->lsd_feature_compat & OBD_COMPAT_OST)) {
173 /* this will only happen on the first connect */
174 lsd->lsd_feature_compat |= OBD_COMPAT_OST;
175 /* sync is not needed here as lut_client_add will
176 * set exp_need_sync flag */
177 tgt_server_data_update(env, &ofd->ofd_lut, 0);
180 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_SIZE)) {
181 data->ocd_brw_size = 65536;
182 } else if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
183 data->ocd_brw_size = min(data->ocd_brw_size,
184 (__u32)DT_MAX_BRW_SIZE);
185 if (data->ocd_brw_size == 0) {
186 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
187 " ocd_version: %x ocd_grant: %d ocd_index: %u "
188 "ocd_brw_size is unexpectedly zero, "
189 "network data corruption?"
190 "Refusing connection of this client\n",
191 exp->exp_obd->obd_name,
192 exp->exp_client_uuid.uuid,
193 exp, data->ocd_connect_flags, data->ocd_version,
194 data->ocd_grant, data->ocd_index);
199 if (data->ocd_connect_flags & OBD_CONNECT_CKSUM) {
200 __u32 cksum_types = data->ocd_cksum_types;
202 /* The client set in ocd_cksum_types the checksum types it
203 * supports. We have to mask off the algorithms that we don't
205 data->ocd_cksum_types &= cksum_types_supported_server();
207 if (unlikely(data->ocd_cksum_types == 0)) {
208 CERROR("%s: Connect with checksum support but no "
209 "ocd_cksum_types is set\n",
210 exp->exp_obd->obd_name);
214 CDEBUG(D_RPCTRACE, "%s: cli %s supports cksum type %x, return "
215 "%x\n", exp->exp_obd->obd_name, obd_export_nid2str(exp),
216 cksum_types, data->ocd_cksum_types);
218 /* This client does not support OBD_CONNECT_CKSUM
219 * fall back to CRC32 */
220 CDEBUG(D_RPCTRACE, "%s: cli %s does not support "
221 "OBD_CONNECT_CKSUM, CRC32 will be used\n",
222 exp->exp_obd->obd_name, obd_export_nid2str(exp));
225 if (data->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
226 data->ocd_maxbytes = ofd->ofd_dt_conf.ddp_maxbytes;
228 if (OCD_HAS_FLAG(data, PINGLESS)) {
229 if (ptlrpc_pinger_suppress_pings()) {
230 spin_lock(&exp->exp_obd->obd_dev_lock);
231 list_del_init(&exp->exp_obd_chain_timed);
232 spin_unlock(&exp->exp_obd->obd_dev_lock);
234 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
241 static int ofd_obd_reconnect(const struct lu_env *env, struct obd_export *exp,
242 struct obd_device *obd, struct obd_uuid *cluuid,
243 struct obd_connect_data *data, void *localdata)
245 struct ofd_device *ofd;
250 if (exp == NULL || obd == NULL || cluuid == NULL)
253 ofd = ofd_dev(obd->obd_lu_dev);
255 rc = ofd_parse_connect_data(env, exp, data, false);
257 ofd_export_stats_init(ofd, exp, localdata);
262 static int ofd_obd_connect(const struct lu_env *env, struct obd_export **_exp,
263 struct obd_device *obd, struct obd_uuid *cluuid,
264 struct obd_connect_data *data, void *localdata)
266 struct obd_export *exp;
267 struct ofd_device *ofd;
268 struct lustre_handle conn = { 0 };
272 if (_exp == NULL || obd == NULL || cluuid == NULL)
275 ofd = ofd_dev(obd->obd_lu_dev);
277 rc = class_connect(&conn, obd, cluuid);
281 exp = class_conn2export(&conn);
282 LASSERT(exp != NULL);
284 rc = ofd_parse_connect_data(env, exp, data, true);
288 if (obd->obd_replayable) {
289 struct tg_export_data *ted = &exp->exp_target_data;
291 memcpy(ted->ted_lcd->lcd_uuid, cluuid,
292 sizeof(ted->ted_lcd->lcd_uuid));
293 rc = tgt_client_new(env, exp);
296 ofd_export_stats_init(ofd, exp, localdata);
299 CDEBUG(D_HA, "%s: get connection from MDS %d\n", obd->obd_name,
300 data ? data->ocd_group : -1);
304 class_disconnect(exp);
312 static int ofd_obd_disconnect(struct obd_export *exp)
314 struct ofd_device *ofd = ofd_dev(exp->exp_obd->obd_lu_dev);
321 class_export_get(exp);
323 if (!(exp->exp_flags & OBD_OPT_FORCE))
324 ofd_grant_sanity_check(ofd_obd(ofd), __FUNCTION__);
326 rc = server_disconnect_export(exp);
328 ofd_grant_discard(exp);
330 /* Do not erase record for recoverable client. */
331 if (exp->exp_obd->obd_replayable &&
332 (!exp->exp_obd->obd_fail || exp->exp_failed)) {
333 rc = lu_env_init(&env, LCT_DT_THREAD);
337 tgt_client_del(&env, exp);
341 class_export_put(exp);
345 static int ofd_init_export(struct obd_export *exp)
349 spin_lock_init(&exp->exp_filter_data.fed_lock);
350 CFS_INIT_LIST_HEAD(&exp->exp_filter_data.fed_mod_list);
351 atomic_set(&exp->exp_filter_data.fed_soft_sync_count, 0);
352 spin_lock(&exp->exp_lock);
353 exp->exp_connecting = 1;
354 spin_unlock(&exp->exp_lock);
356 /* self-export doesn't need client data and ldlm initialization */
357 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
358 &exp->exp_client_uuid)))
361 rc = tgt_client_alloc(exp);
363 ldlm_init_export(exp);
365 CERROR("%s: Can't initialize export: rc %d\n",
366 exp->exp_obd->obd_name, rc);
370 static int ofd_destroy_export(struct obd_export *exp)
372 struct ofd_device *ofd = ofd_dev(exp->exp_obd->obd_lu_dev);
374 if (exp->exp_filter_data.fed_pending)
375 CERROR("%s: cli %s/%p has %lu pending on destroyed export"
376 "\n", exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
377 exp, exp->exp_filter_data.fed_pending);
379 target_destroy_export(exp);
381 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
382 &exp->exp_client_uuid)))
385 ldlm_destroy_export(exp);
386 tgt_client_free(exp);
388 ofd_fmd_cleanup(exp);
391 * discard grants once we're sure no more
392 * interaction with the client is possible
394 ofd_grant_discard(exp);
395 ofd_fmd_cleanup(exp);
397 if (exp_connect_flags(exp) & OBD_CONNECT_GRANT_SHRINK) {
398 if (ofd->ofd_tot_granted_clients > 0)
399 ofd->ofd_tot_granted_clients --;
402 if (!(exp->exp_flags & OBD_OPT_FORCE))
403 ofd_grant_sanity_check(exp->exp_obd, __FUNCTION__);
405 LASSERT(cfs_list_empty(&exp->exp_filter_data.fed_mod_list));
409 int ofd_postrecov(const struct lu_env *env, struct ofd_device *ofd)
411 struct lu_device *ldev = &ofd->ofd_dt_dev.dd_lu_dev;
413 CDEBUG(D_HA, "%s: recovery is over\n", ofd_obd(ofd)->obd_name);
414 return ldev->ld_ops->ldo_recovery_complete(env, ldev);
417 int ofd_obd_postrecov(struct obd_device *obd)
420 struct lu_device *ldev = obd->obd_lu_dev;
425 rc = lu_env_init(&env, LCT_DT_THREAD);
428 ofd_info_init(&env, obd->obd_self_export);
430 rc = ofd_postrecov(&env, ofd_dev(ldev));
436 static int ofd_adapt_sptlrpc_conf(const struct lu_env *env,
437 struct obd_device *obd, int initial)
439 struct filter_obd *fo = &obd->u.filter;
440 struct sptlrpc_rule_set tmp_rset;
443 sptlrpc_rule_set_init(&tmp_rset);
444 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
446 CERROR("%s: failed get sptlrpc rules: rc = %d\n",
451 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
453 write_lock(&fo->fo_sptlrpc_lock);
454 sptlrpc_rule_set_free(&fo->fo_sptlrpc_rset);
455 fo->fo_sptlrpc_rset = tmp_rset;
456 write_unlock(&fo->fo_sptlrpc_lock);
461 static int ofd_set_mds_conn(struct obd_export *exp, void *val)
467 LCONSOLE_WARN("%s: received MDS connection from %s\n",
468 exp->exp_obd->obd_name, obd_export_nid2str(exp));
472 static int ofd_set_info_async(const struct lu_env *env, struct obd_export *exp,
473 __u32 keylen, void *key, __u32 vallen, void *val,
474 struct ptlrpc_request_set *set)
476 struct ofd_device *ofd;
481 if (exp->exp_obd == NULL) {
482 CDEBUG(D_IOCTL, "invalid export %p\n", exp);
488 if (KEY_IS(KEY_CAPA_KEY)) {
489 rc = ofd_update_capa_key(ofd, val);
491 CERROR("%s: update capability key failed: rc = %d\n",
492 exp->exp_obd->obd_name, rc);
493 } else if (KEY_IS(KEY_SPTLRPC_CONF)) {
494 ofd_adapt_sptlrpc_conf(env, exp->exp_obd, 0);
495 } else if (KEY_IS(KEY_MDS_CONN)) {
496 rc = ofd_set_mds_conn(exp, val);
497 } else if (KEY_IS(KEY_GRANT_SHRINK)) {
498 struct ost_body *body = val;
500 ofd_info_init(env, exp);
501 /** handle grant shrink, similar to a read request */
502 ofd_grant_prepare_read(env, exp, &body->oa);
504 CERROR("%s: Unsupported key %s\n",
505 exp->exp_obd->obd_name, (char*)key);
512 static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
513 __u32 keylen, void *key, __u32 *vallen, void *val,
514 struct lov_stripe_md *lsm)
516 struct ofd_device *ofd;
521 if (exp->exp_obd == NULL) {
522 CDEBUG(D_IOCTL, "invalid client export %p\n", exp);
526 /* Because ofd_get_info might be called from
527 * handle_request_in as well(see LU-3239), where env might
528 * not be initilaized correctly, and le_ses might be in
529 * an un-initialized state, so only refill le_ctx here */
530 rc = lu_env_refill((struct lu_env *)env);
536 if (KEY_IS(KEY_BLOCKSIZE)) {
537 __u32 *blocksize = val;
539 if (*vallen < sizeof(*blocksize))
540 GOTO(out, rc = -EOVERFLOW);
541 *blocksize = 1 << ofd->ofd_dt_conf.ddp_block_shift;
543 *vallen = sizeof(*blocksize);
544 } else if (KEY_IS(KEY_BLOCKSIZE_BITS)) {
545 __u32 *blocksize_bits = val;
546 if (blocksize_bits) {
547 if (*vallen < sizeof(*blocksize_bits))
548 GOTO(out, rc = -EOVERFLOW);
549 *blocksize_bits = ofd->ofd_dt_conf.ddp_block_shift;
551 *vallen = sizeof(*blocksize_bits);
552 } else if (KEY_IS(KEY_LAST_ID)) {
553 obd_id *last_id = val;
554 struct ofd_seq *oseq;
557 *vallen = sizeof(obd_id);
560 ofd_info_init(env, exp);
561 oseq = ofd_seq_load(env, ofd,
562 (obd_seq)exp->exp_filter_data.fed_group);
563 LASSERT(!IS_ERR(oseq));
565 if (*vallen < sizeof(*last_id)) {
566 ofd_seq_put(env, oseq);
567 GOTO(out, rc = -EOVERFLOW);
569 *last_id = ofd_seq_last_oid(oseq);
571 ofd_seq_put(env, oseq);
572 *vallen = sizeof(*last_id);
573 } else if (KEY_IS(KEY_FIEMAP)) {
574 struct ofd_device *ofd = ofd_exp(exp);
575 struct ofd_object *fo;
576 struct ll_fiemap_info_key *fm_key = key;
580 *vallen = fiemap_count_to_size(
581 fm_key->fiemap.fm_extent_count);
585 rc = ostid_to_fid(&fid, &fm_key->oa.o_oi,
586 ofd->ofd_lut.lut_lsd.lsd_osd_index);
589 CDEBUG(D_INODE, "get FIEMAP of object "DFID"\n",
592 fo = ofd_object_find(env, ofd, &fid);
594 CERROR("%s: error finding object "DFID"\n",
595 exp->exp_obd->obd_name, PFID(&fid));
598 struct ll_user_fiemap *fiemap = val;
600 ofd_read_lock(env, fo);
601 if (ofd_object_exists(fo)) {
602 *fiemap = fm_key->fiemap;
603 rc = dt_fiemap_get(env,
604 ofd_object_child(fo),
609 ofd_read_unlock(env, fo);
610 ofd_object_put(env, fo);
612 } else if (KEY_IS(KEY_LAST_FID)) {
613 struct ofd_device *ofd = ofd_exp(exp);
614 struct ofd_seq *oseq;
615 struct lu_fid *fid = val;
619 *vallen = sizeof(struct lu_fid);
623 if (*vallen < sizeof(*fid))
624 GOTO(out, rc = -EOVERFLOW);
626 ofd_info_init(env, exp);
628 fid_le_to_cpu(fid, fid);
630 oseq = ofd_seq_load(env, ofd,
631 ostid_seq((struct ost_id *)fid));
633 GOTO(out, rc = PTR_ERR(oseq));
635 rc = ostid_to_fid(fid, &oseq->os_oi,
636 ofd->ofd_lut.lut_lsd.lsd_osd_index);
640 CDEBUG(D_HA, "%s: LAST FID is "DFID"\n", ofd_name(ofd),
642 *vallen = sizeof(*fid);
644 ofd_seq_put(env, oseq);
646 CERROR("Not supported key %s\n", (char*)key);
653 /** helper function for statfs, also used by grant code */
654 int ofd_statfs_internal(const struct lu_env *env, struct ofd_device *ofd,
655 struct obd_statfs *osfs, __u64 max_age, int *from_cache)
659 spin_lock(&ofd->ofd_osfs_lock);
660 if (cfs_time_before_64(ofd->ofd_osfs_age, max_age) || max_age == 0) {
663 /* statfs data are too old, get up-to-date one.
664 * we must be cautious here since multiple threads might be
665 * willing to update statfs data concurrently and we must
666 * grant that cached statfs data are always consistent */
668 if (ofd->ofd_statfs_inflight == 0)
669 /* clear inflight counter if no users, although it would
670 * take a while to overflow this 64-bit counter ... */
671 ofd->ofd_osfs_inflight = 0;
672 /* notify ofd_grant_commit() that we want to track writes
673 * completed as of now */
674 ofd->ofd_statfs_inflight++;
675 /* record value of inflight counter before running statfs to
676 * compute the diff once statfs is completed */
677 unstable = ofd->ofd_osfs_inflight;
678 spin_unlock(&ofd->ofd_osfs_lock);
680 /* statfs can sleep ... hopefully not for too long since we can
681 * call it fairly often as space fills up */
682 rc = dt_statfs(env, ofd->ofd_osd, osfs);
686 spin_lock(&ofd->ofd_grant_lock);
687 spin_lock(&ofd->ofd_osfs_lock);
688 /* calculate how much space was written while we released the
690 unstable = ofd->ofd_osfs_inflight - unstable;
691 ofd->ofd_osfs_unstable = 0;
693 /* some writes completed while we were running statfs
694 * w/o the ofd_osfs_lock. Those ones got added to
695 * the cached statfs data that we are about to crunch.
696 * Take them into account in the new statfs data */
697 osfs->os_bavail -= min_t(obd_size, osfs->os_bavail,
698 unstable >> ofd->ofd_blockbits);
699 /* However, we don't really know if those writes got
700 * accounted in the statfs call, so tell
701 * ofd_grant_space_left() there is some uncertainty
702 * on the accounting of those writes.
703 * The purpose is to prevent spurious error messages in
704 * ofd_grant_space_left() since those writes might be
705 * accounted twice. */
706 ofd->ofd_osfs_unstable += unstable;
708 /* similarly, there is some uncertainty on write requests
709 * between prepare & commit */
710 ofd->ofd_osfs_unstable += ofd->ofd_tot_pending;
711 spin_unlock(&ofd->ofd_grant_lock);
713 /* finally udpate cached statfs data */
714 ofd->ofd_osfs = *osfs;
715 ofd->ofd_osfs_age = cfs_time_current_64();
717 ofd->ofd_statfs_inflight--; /* stop tracking */
718 if (ofd->ofd_statfs_inflight == 0)
719 ofd->ofd_osfs_inflight = 0;
720 spin_unlock(&ofd->ofd_osfs_lock);
725 /* use cached statfs data */
726 *osfs = ofd->ofd_osfs;
727 spin_unlock(&ofd->ofd_osfs_lock);
734 int ofd_statfs(const struct lu_env *env, struct obd_export *exp,
735 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
737 struct obd_device *obd = class_exp2obd(exp);
738 struct ofd_device *ofd = ofd_dev(exp->exp_obd->obd_lu_dev);
743 rc = ofd_statfs_internal(env, ofd, osfs, max_age, NULL);
747 /* at least try to account for cached pages. its still racy and
748 * might be under-reporting if clients haven't announced their
749 * caches with brw recently */
751 CDEBUG(D_SUPER | D_CACHE, "blocks cached "LPU64" granted "LPU64
752 " pending "LPU64" free "LPU64" avail "LPU64"\n",
753 ofd->ofd_tot_dirty, ofd->ofd_tot_granted, ofd->ofd_tot_pending,
754 osfs->os_bfree << ofd->ofd_blockbits,
755 osfs->os_bavail << ofd->ofd_blockbits);
757 osfs->os_bavail -= min_t(obd_size, osfs->os_bavail,
758 ((ofd->ofd_tot_dirty + ofd->ofd_tot_pending +
759 osfs->os_bsize - 1) >> ofd->ofd_blockbits));
761 /* The QoS code on the MDS does not care about space reserved for
762 * precreate, so take it out. */
763 if (exp_connect_flags(exp) & OBD_CONNECT_MDS) {
764 struct filter_export_data *fed;
766 fed = &obd->obd_self_export->exp_filter_data;
767 osfs->os_bavail -= min_t(obd_size, osfs->os_bavail,
768 fed->fed_grant >> ofd->ofd_blockbits);
771 ofd_grant_sanity_check(obd, __FUNCTION__);
772 CDEBUG(D_CACHE, LPU64" blocks: "LPU64" free, "LPU64" avail; "
773 LPU64" objects: "LPU64" free; state %x\n",
774 osfs->os_blocks, osfs->os_bfree, osfs->os_bavail,
775 osfs->os_files, osfs->os_ffree, osfs->os_state);
777 if (OBD_FAIL_CHECK_VALUE(OBD_FAIL_OST_ENOINO,
778 ofd->ofd_lut.lut_lsd.lsd_osd_index))
781 /* OS_STATE_READONLY can be set by OSD already */
782 if (ofd->ofd_raid_degraded)
783 osfs->os_state |= OS_STATE_DEGRADED;
785 if (obd->obd_self_export != exp && ofd_grant_compat(exp, ofd)) {
786 /* clients which don't support OBD_CONNECT_GRANT_PARAM
787 * should not see a block size > page size, otherwise
788 * cl_lost_grant goes mad. Therefore, we emulate a 4KB (=2^12)
789 * block size which is the biggest block size known to work
790 * with all client's page size. */
791 osfs->os_blocks <<= ofd->ofd_blockbits - COMPAT_BSIZE_SHIFT;
792 osfs->os_bfree <<= ofd->ofd_blockbits - COMPAT_BSIZE_SHIFT;
793 osfs->os_bavail <<= ofd->ofd_blockbits - COMPAT_BSIZE_SHIFT;
794 osfs->os_bsize = 1 << COMPAT_BSIZE_SHIFT;
797 if (OBD_FAIL_CHECK_VALUE(OBD_FAIL_OST_ENOSPC,
798 ofd->ofd_lut.lut_lsd.lsd_osd_index))
799 osfs->os_bfree = osfs->os_bavail = 2;
806 int ofd_setattr(const struct lu_env *env, struct obd_export *exp,
807 struct obd_info *oinfo, struct obd_trans_info *oti)
809 struct ofd_thread_info *info;
810 struct ofd_device *ofd = ofd_exp(exp);
811 struct ldlm_namespace *ns = ofd->ofd_namespace;
812 struct ldlm_resource *res;
813 struct ofd_object *fo;
814 struct obdo *oa = oinfo->oi_oa;
815 struct filter_fid *ff = NULL;
820 info = ofd_info_init(env, exp);
821 ofd_oti2info(info, oti);
823 info->fti_fid = oinfo->oi_oa->o_oi.oi_fid;
824 ost_fid_build_resid(&info->fti_fid, &info->fti_resid);
825 rc = ofd_auth_capa(exp, &info->fti_fid, ostid_seq(&oa->o_oi),
826 oinfo_capa(oinfo), CAPA_OPC_META_WRITE);
830 /* This would be very bad - accidentally truncating a file when
831 * changing the time or similar - bug 12203. */
832 if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE &&
833 oinfo->oi_policy.l_extent.end != OBD_OBJECT_EOF) {
834 static char mdsinum[48];
836 if (oinfo->oi_oa->o_valid & OBD_MD_FLFID)
837 snprintf(mdsinum, sizeof(mdsinum) - 1,
838 "of parent "DFID, oinfo->oi_oa->o_parent_seq,
839 oinfo->oi_oa->o_parent_oid, 0);
843 CERROR("%s: setattr from %s trying to truncate object "DFID
844 " %s\n", exp->exp_obd->obd_name,
845 obd_export_nid2str(exp), PFID(&info->fti_fid), mdsinum);
846 GOTO(out, rc = -EPERM);
849 fo = ofd_object_find(env, ofd, &info->fti_fid);
851 CERROR("%s: can't find object "DFID"\n",
852 exp->exp_obd->obd_name, PFID(&info->fti_fid));
853 GOTO(out, rc = PTR_ERR(fo));
856 la_from_obdo(&info->fti_attr, oinfo->oi_oa, oinfo->oi_oa->o_valid);
857 info->fti_attr.la_valid &= ~LA_TYPE;
859 if (oa->o_valid & OBD_MD_FLFID) {
860 ff = &info->fti_mds_fid;
861 ofd_prepare_fidea(ff, oa);
864 /* setting objects attributes (including owner/group) */
865 rc = ofd_attr_set(env, fo, &info->fti_attr, ff);
867 GOTO(out_unlock, rc);
869 ofd_info2oti(info, oti);
871 ofd_counter_incr(exp, LPROC_OFD_STATS_SETATTR, oti->oti_jobid, 1);
874 ofd_object_put(env, fo);
877 /* we do not call this before to avoid lu_object_find() in
878 * ->lvbo_update() holding another reference on the object.
879 * otherwise concurrent destroy can make the object unavailable
880 * for 2nd lu_object_find() waiting for the first reference
881 * to go... deadlock! */
882 res = ldlm_resource_get(ns, NULL, &info->fti_resid, LDLM_EXTENT, 0);
884 ldlm_res_lvbo_update(res, NULL, 0);
885 ldlm_resource_putref(res);
892 static int ofd_punch(const struct lu_env *env, struct obd_export *exp,
893 struct obd_info *oinfo, struct obd_trans_info *oti,
894 struct ptlrpc_request_set *rqset)
896 struct ofd_thread_info *info;
897 struct ofd_device *ofd = ofd_exp(exp);
898 struct ldlm_namespace *ns = ofd->ofd_namespace;
899 struct ldlm_resource *res;
900 struct ofd_object *fo;
901 struct filter_fid *ff = NULL;
906 info = ofd_info_init(env, exp);
907 ofd_oti2info(info, oti);
909 info->fti_fid = oinfo->oi_oa->o_oi.oi_fid;
910 ost_fid_build_resid(&info->fti_fid, &info->fti_resid);
912 CDEBUG(D_INODE, "calling punch for object "DFID", valid = "LPX64
913 ", start = "LPD64", end = "LPD64"\n", PFID(&info->fti_fid),
914 oinfo->oi_oa->o_valid, oinfo->oi_policy.l_extent.start,
915 oinfo->oi_policy.l_extent.end);
917 rc = ofd_auth_capa(exp, &info->fti_fid, ostid_seq(&oinfo->oi_oa->o_oi),
918 oinfo_capa(oinfo), CAPA_OPC_OSS_TRUNC);
922 fo = ofd_object_find(env, ofd, &info->fti_fid);
924 CERROR("%s: error finding object "DFID": rc = %ld\n",
925 exp->exp_obd->obd_name, PFID(&info->fti_fid),
927 GOTO(out_env, rc = PTR_ERR(fo));
930 LASSERT(oinfo->oi_policy.l_extent.end == OBD_OBJECT_EOF);
931 if (oinfo->oi_policy.l_extent.end == OBD_OBJECT_EOF) {
933 oinfo->oi_oa->o_size = oinfo->oi_policy.l_extent.start;
934 } else if (oinfo->oi_policy.l_extent.end >= oinfo->oi_oa->o_size) {
935 oinfo->oi_oa->o_size = oinfo->oi_policy.l_extent.end;
938 la_from_obdo(&info->fti_attr, oinfo->oi_oa,
939 OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME);
940 info->fti_attr.la_valid &= ~LA_TYPE;
941 info->fti_attr.la_size = oinfo->oi_policy.l_extent.start;
942 info->fti_attr.la_valid |= LA_SIZE;
944 if (oinfo->oi_oa->o_valid & OBD_MD_FLFID) {
945 ff = &info->fti_mds_fid;
946 ofd_prepare_fidea(ff, oinfo->oi_oa);
949 rc = ofd_object_punch(env, fo, oinfo->oi_policy.l_extent.start,
950 oinfo->oi_policy.l_extent.end, &info->fti_attr,
955 res = ldlm_resource_get(ns, NULL, &info->fti_resid, LDLM_EXTENT, 0);
957 ldlm_res_lvbo_update(res, NULL, 0);
958 ldlm_resource_putref(res);
961 oinfo->oi_oa->o_valid = OBD_MD_FLID;
962 /* Quota release needs uid/gid info */
963 rc = ofd_attr_get(env, fo, &info->fti_attr);
964 obdo_from_la(oinfo->oi_oa, &info->fti_attr,
965 OFD_VALID_FLAGS | LA_UID | LA_GID);
966 ofd_info2oti(info, oti);
968 ofd_counter_incr(exp, LPROC_OFD_STATS_PUNCH, oti->oti_jobid, 1);
971 ofd_object_put(env, fo);
976 int ofd_destroy_by_fid(const struct lu_env *env, struct ofd_device *ofd,
977 const struct lu_fid *fid, int orphan)
979 struct ofd_thread_info *info = ofd_info(env);
980 struct lustre_handle lockh;
981 __u64 flags = LDLM_FL_AST_DISCARD_DATA;
983 ldlm_policy_data_t policy = {
984 .l_extent = { 0, OBD_OBJECT_EOF }
986 struct ofd_object *fo;
990 fo = ofd_object_find(env, ofd, fid);
993 if (!ofd_object_exists(fo))
994 GOTO(out, rc = -ENOENT);
996 /* Tell the clients that the object is gone now and that they should
997 * throw away any cached pages. */
998 ost_fid_build_resid(fid, &info->fti_resid);
999 rc = ldlm_cli_enqueue_local(ofd->ofd_namespace, &info->fti_resid,
1000 LDLM_EXTENT, &policy, LCK_PW, &flags,
1001 ldlm_blocking_ast, ldlm_completion_ast,
1002 NULL, NULL, 0, LVB_T_NONE, NULL, &lockh);
1004 /* We only care about the side-effects, just drop the lock. */
1006 ldlm_lock_decref(&lockh, LCK_PW);
1008 LASSERT(fo != NULL);
1010 rc = ofd_object_destroy(env, fo, orphan);
1013 ofd_object_put(env, fo);
1017 int ofd_destroy(const struct lu_env *env, struct obd_export *exp,
1018 struct obdo *oa, struct lov_stripe_md *md,
1019 struct obd_trans_info *oti, struct obd_export *md_exp,
1022 struct ofd_device *ofd = ofd_exp(exp);
1023 struct ofd_thread_info *info;
1031 info = ofd_info_init(env, exp);
1032 ofd_oti2info(info, oti);
1033 fid = &info->fti_fid;
1035 if (!(oa->o_valid & OBD_MD_FLGROUP))
1036 ostid_set_seq_mdt0(&oa->o_oi);
1038 *fid = oa->o_oi.oi_fid;
1039 oid = ostid_id(&oa->o_oi);
1042 /* check that o_misc makes sense */
1043 if (oa->o_valid & OBD_MD_FLOBJCOUNT)
1046 count = 1; /* default case - single destroy */
1048 CDEBUG(D_INODE, "%s: Destroy object "DOSTID" count %d\n", ofd_name(ofd),
1049 POSTID(&oa->o_oi), count);
1054 lrc = ofd_destroy_by_fid(env, ofd, fid, 0);
1055 if (lrc == -ENOENT) {
1057 "%s: destroying non-existent object "DFID"\n",
1058 ofd_obd(ofd)->obd_name, PFID(fid));
1059 /* rewrite rc with -ENOENT only if it is 0 */
1062 } else if (lrc != 0) {
1063 CERROR("%s: error destroying object "DFID": %d\n",
1064 ofd_obd(ofd)->obd_name, PFID(fid),
1071 lrc = fid_set_id(fid, oid);
1072 if (unlikely(lrc != 0 && count > 0))
1073 GOTO(out, rc = lrc);
1079 ofd_info2oti(info, oti);
1080 fid_to_ostid(fid, &oa->o_oi);
1084 int ofd_orphans_destroy(const struct lu_env *env, struct obd_export *exp,
1085 struct ofd_device *ofd, struct obdo *oa)
1087 struct ofd_thread_info *info = ofd_info(env);
1088 struct lu_fid *fid = &info->fti_fid;
1089 struct ost_id *oi = &oa->o_oi;
1090 struct ofd_seq *oseq;
1091 obd_seq seq = ostid_seq(oi);
1092 obd_id end_id = ostid_id(oi);
1099 oseq = ofd_seq_get(ofd, seq);
1101 CERROR("%s: Can not find seq for "DOSTID"\n",
1102 ofd_name(ofd), POSTID(oi));
1107 last = ofd_seq_last_oid(oseq);
1110 LASSERT(exp != NULL);
1111 skip_orphan = !!(exp_connect_flags(exp) & OBD_CONNECT_SKIP_ORPHAN);
1113 LCONSOLE(D_INFO, "%s: deleting orphan objects from "DOSTID
1114 " to "DOSTID"\n", ofd_name(ofd), seq, end_id + 1, seq, last);
1116 while (oid > end_id) {
1117 rc = fid_set_id(fid, oid);
1118 if (unlikely(rc != 0))
1121 rc = ofd_destroy_by_fid(env, ofd, fid, 1);
1122 if (rc != 0 && rc != -ENOENT) /* this is pretty fatal... */
1123 CEMERG("%s: error destroying precreated id "DFID
1124 ": rc = %d\n", ofd_name(ofd), PFID(fid), rc);
1128 ofd_seq_last_oid_set(oseq, oid);
1129 /* update last_id on disk periodically so that if we
1130 * restart * we don't need to re-scan all of the just
1131 * deleted objects. */
1132 if ((oid & 511) == 0)
1133 ofd_seq_last_oid_write(env, ofd, oseq);
1137 CDEBUG(D_HA, "%s: after destroy: set last_id to "DOSTID"\n",
1138 ofd_obd(ofd)->obd_name, seq, oid);
1141 rc = ofd_seq_last_oid_write(env, ofd, oseq);
1143 /* don't reuse orphan object, return last used objid */
1144 ostid_set_id(oi, last);
1151 ofd_seq_put(env, oseq);
1155 int ofd_create(const struct lu_env *env, struct obd_export *exp,
1156 struct obdo *oa, struct lov_stripe_md **ea,
1157 struct obd_trans_info *oti)
1159 struct ofd_device *ofd = ofd_exp(exp);
1160 struct ofd_thread_info *info;
1161 obd_seq seq = ostid_seq(&oa->o_oi);
1162 struct ofd_seq *oseq;
1168 info = ofd_info_init(env, exp);
1169 ofd_oti2info(info, oti);
1171 LASSERT(ostid_seq(&oa->o_oi) >= FID_SEQ_OST_MDT0);
1172 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
1174 CDEBUG(D_INFO, "ofd_create("DOSTID")\n", POSTID(&oa->o_oi));
1176 oseq = ofd_seq_load(env, ofd, seq);
1178 CERROR("%s: Can't find FID Sequence "LPX64": rc = %ld\n",
1179 ofd_name(ofd), seq, PTR_ERR(oseq));
1183 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1184 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1185 if (!ofd_obd(ofd)->obd_recovering ||
1186 ostid_id(&oa->o_oi) > ofd_seq_last_oid(oseq)) {
1187 CERROR("recreate objid "DOSTID" > last id "LPU64"\n",
1188 POSTID(&oa->o_oi), ofd_seq_last_oid(oseq));
1189 GOTO(out_nolock, rc = -EINVAL);
1191 /* do nothing because we create objects during first write */
1192 GOTO(out_nolock, rc = 0);
1194 /* former ofd_handle_precreate */
1195 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1196 (oa->o_flags & OBD_FL_DELORPHAN)) {
1197 /* destroy orphans */
1198 if (oti->oti_conn_cnt < exp->exp_conn_cnt) {
1199 CERROR("%s: dropping old orphan cleanup request\n",
1201 GOTO(out_nolock, rc = 0);
1203 /* This causes inflight precreates to abort and drop lock */
1204 oseq->os_destroys_in_progress = 1;
1205 mutex_lock(&oseq->os_create_lock);
1206 if (!oseq->os_destroys_in_progress) {
1207 CERROR("%s:["LPU64"] destroys_in_progress already"
1208 " cleared\n", exp->exp_obd->obd_name,
1209 ostid_seq(&oa->o_oi));
1210 ostid_set_id(&oa->o_oi, ofd_seq_last_oid(oseq));
1213 diff = ostid_id(&oa->o_oi) - ofd_seq_last_oid(oseq);
1214 CDEBUG(D_HA, "ofd_last_id() = "LPU64" -> diff = %d\n",
1215 ofd_seq_last_oid(oseq), diff);
1216 if (-diff > OST_MAX_PRECREATE) {
1217 /* FIXME: should reset precreate_next_id on MDS */
1219 } else if (diff < 0) {
1220 rc = ofd_orphans_destroy(env, exp, ofd, oa);
1221 oseq->os_destroys_in_progress = 0;
1223 /* XXX: Used by MDS for the first time! */
1224 oseq->os_destroys_in_progress = 0;
1227 mutex_lock(&oseq->os_create_lock);
1228 if (oti->oti_conn_cnt < exp->exp_conn_cnt) {
1229 CERROR("%s: dropping old precreate request\n",
1230 ofd_obd(ofd)->obd_name);
1233 /* only precreate if seq is 0, IDIF or normal and also o_id
1234 * must be specfied */
1235 if ((!fid_seq_is_mdt(ostid_seq(&oa->o_oi)) &&
1236 !fid_seq_is_norm(ostid_seq(&oa->o_oi)) &&
1237 !fid_seq_is_idif(ostid_seq(&oa->o_oi))) ||
1238 ostid_id(&oa->o_oi) == 0) {
1239 diff = 1; /* shouldn't we create this right now? */
1241 diff = ostid_id(&oa->o_oi) - ofd_seq_last_oid(oseq);
1242 /* Do sync create if the seq is about to used up */
1243 if (fid_seq_is_idif(ostid_seq(&oa->o_oi)) ||
1244 fid_seq_is_mdt0(ostid_seq(&oa->o_oi))) {
1245 if (unlikely(ostid_id(&oa->o_oi) >= IDIF_MAX_OID - 1))
1247 } else if (fid_seq_is_norm(ostid_seq(&oa->o_oi))) {
1248 if (unlikely(ostid_id(&oa->o_oi) >=
1249 LUSTRE_DATA_SEQ_MAX_WIDTH - 1))
1252 CERROR("%s : invalid o_seq "DOSTID": rc = %d\n",
1253 ofd_name(ofd), POSTID(&oa->o_oi), -EINVAL);
1254 GOTO(out, rc = -EINVAL);
1259 cfs_time_t enough_time = cfs_time_shift(DISK_TIMEOUT);
1264 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1265 !(oa->o_flags & OBD_FL_DELORPHAN)) {
1266 /* don't enforce grant during orphan recovery */
1267 rc = ofd_grant_create(env,
1268 ofd_obd(ofd)->obd_self_export,
1271 CDEBUG(D_HA, "%s: failed to acquire grant "
1272 "space for precreate (%d): rc = %d\n",
1273 ofd_name(ofd), diff, rc);
1278 /* This can happen if a new OST is formatted and installed
1279 * in place of an old one at the same index. Instead of
1280 * precreating potentially millions of deleted old objects
1281 * (possibly filling the OST), only precreate the last batch.
1282 * LFSCK will eventually clean up any orphans. LU-14 */
1283 if (diff > 5 * OST_MAX_PRECREATE) {
1284 diff = OST_MAX_PRECREATE / 2;
1285 LCONSOLE_WARN("%s: precreate FID "DOSTID" is over %u "
1286 "larger than the LAST_ID "DOSTID", only "
1287 "precreating the last %u objects.\n",
1288 ofd_name(ofd), POSTID(&oa->o_oi),
1289 5 * OST_MAX_PRECREATE,
1290 POSTID(&oseq->os_oi), diff);
1291 ofd_seq_last_oid_set(oseq, ostid_id(&oa->o_oi) - diff);
1295 next_id = ofd_seq_last_oid(oseq) + 1;
1296 count = ofd_precreate_batch(ofd, diff);
1298 CDEBUG(D_HA, "%s: reserve %d objects in group "LPX64
1299 " at "LPU64"\n", ofd_obd(ofd)->obd_name,
1300 count, ostid_seq(&oa->o_oi), next_id);
1302 if (cfs_time_after(jiffies, enough_time)) {
1303 LCONSOLE_WARN("%s: Slow creates, %d/%d objects"
1304 " created at a rate of %d/s\n",
1305 ofd_obd(ofd)->obd_name,
1306 created, diff + created,
1307 created / DISK_TIMEOUT);
1311 rc = ofd_precreate_objects(env, ofd, next_id,
1312 oseq, count, sync_trans);
1316 } else if (rc < 0) {
1321 /* some objects got created, we can return
1322 * them, even if last creation failed */
1325 CERROR("%s: unable to precreate: rc = %d\n",
1328 ostid_set_id(&oa->o_oi, ofd_seq_last_oid(oseq));
1329 oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
1331 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1332 !(oa->o_flags & OBD_FL_DELORPHAN))
1333 ofd_grant_commit(env, ofd_obd(ofd)->obd_self_export,
1337 ofd_info2oti(info, oti);
1339 mutex_unlock(&oseq->os_create_lock);
1341 if (rc == 0 && ea != NULL) {
1342 struct lov_stripe_md *lsm = *ea;
1344 lsm->lsm_oi = oa->o_oi;
1346 ofd_seq_put(env, oseq);
1350 int ofd_getattr(const struct lu_env *env, struct obd_export *exp,
1351 struct obd_info *oinfo)
1353 struct ofd_device *ofd = ofd_exp(exp);
1354 struct ofd_thread_info *info;
1355 struct ofd_object *fo;
1360 info = ofd_info_init(env, exp);
1362 info->fti_fid = oinfo->oi_oa->o_oi.oi_fid;
1363 rc = ofd_auth_capa(exp, &info->fti_fid, ostid_seq(&oinfo->oi_oa->o_oi),
1364 oinfo_capa(oinfo), CAPA_OPC_META_READ);
1368 fo = ofd_object_find(env, ofd, &info->fti_fid);
1370 GOTO(out, rc = PTR_ERR(fo));
1371 if (!ofd_object_exists(fo))
1372 GOTO(out_put, rc = -ENOENT);
1374 LASSERT(fo != NULL);
1375 rc = ofd_attr_get(env, fo, &info->fti_attr);
1376 oinfo->oi_oa->o_valid = OBD_MD_FLID;
1380 obdo_from_la(oinfo->oi_oa, &info->fti_attr,
1381 OFD_VALID_FLAGS | LA_UID | LA_GID);
1383 /* Store object version in reply */
1384 curr_version = dt_version_get(env, ofd_object_child(fo));
1385 if ((__s64)curr_version != -EOPNOTSUPP) {
1386 oinfo->oi_oa->o_valid |= OBD_MD_FLDATAVERSION;
1387 oinfo->oi_oa->o_data_version = curr_version;
1392 ofd_object_put(env, fo);
1397 static int ofd_sync(const struct lu_env *env, struct obd_export *exp,
1398 struct obd_info *oinfo, obd_size start, obd_size end,
1399 struct ptlrpc_request_set *set)
1401 struct ofd_device *ofd = ofd_exp(exp);
1402 struct ofd_thread_info *info;
1403 struct ofd_object *fo;
1408 /* if no objid is specified, it means "sync whole filesystem" */
1409 if (oinfo->oi_oa == NULL || !(oinfo->oi_oa->o_valid & OBD_MD_FLID)) {
1410 rc = dt_sync(env, ofd->ofd_osd);
1414 info = ofd_info_init(env, exp);
1415 info->fti_fid = oinfo->oi_oa->o_oi.oi_fid;
1416 rc = ofd_auth_capa(exp, &info->fti_fid, ostid_seq(&oinfo->oi_oa->o_oi),
1417 oinfo_capa(oinfo), CAPA_OPC_OSS_TRUNC);
1421 fo = ofd_object_find(env, ofd, &info->fti_fid);
1423 CERROR("%s: error finding object "DFID": rc = %ld\n",
1424 exp->exp_obd->obd_name, PFID(&info->fti_fid),
1426 GOTO(out, rc = PTR_ERR(fo));
1429 if (!ofd_object_exists(fo))
1430 GOTO(put, rc = -ENOENT);
1432 if (dt_version_get(env, ofd_object_child(fo)) >
1433 ofd_obd(ofd)->obd_last_committed) {
1434 rc = dt_object_sync(env, ofd_object_child(fo));
1439 oinfo->oi_oa->o_valid = OBD_MD_FLID;
1440 rc = ofd_attr_get(env, fo, &info->fti_attr);
1441 obdo_from_la(oinfo->oi_oa, &info->fti_attr, OFD_VALID_FLAGS);
1443 ofd_counter_incr(exp, LPROC_OFD_STATS_SYNC, oinfo->oi_jobid, 1);
1446 ofd_object_put(env, fo);
1451 static int ofd_ioc_get_obj_version(const struct lu_env *env,
1452 struct ofd_device *ofd, void *karg)
1454 struct obd_ioctl_data *data = karg;
1456 struct ofd_object *fo;
1457 dt_obj_version_t version;
1462 if (data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
1463 GOTO(out, rc = -EINVAL);
1465 if (data->ioc_inlbuf1 != NULL && data->ioc_inllen1 == sizeof(fid)) {
1466 fid = *(struct lu_fid *)data->ioc_inlbuf1;
1467 } else if (data->ioc_inlbuf3 != NULL &&
1468 data->ioc_inllen3 == sizeof(__u64) &&
1469 data->ioc_inlbuf4 != NULL &&
1470 data->ioc_inllen4 == sizeof(__u64)) {
1471 struct ost_id ostid;
1473 ostid_set_seq(&ostid, *(__u64 *)data->ioc_inlbuf4);
1474 ostid_set_id(&ostid, *(__u64 *)data->ioc_inlbuf3);
1475 rc = ostid_to_fid(&fid, &ostid,
1476 ofd->ofd_lut.lut_lsd.lsd_osd_index);
1480 GOTO(out, rc = -EINVAL);
1483 if (!fid_is_sane(&fid))
1484 GOTO(out, rc = -EINVAL);
1486 fo = ofd_object_find(env, ofd, &fid);
1488 GOTO(out, rc = PTR_ERR(fo));
1490 if (!ofd_object_exists(fo))
1491 GOTO(out_fo, rc = -ENOENT);
1493 if (lu_object_remote(&fo->ofo_obj.do_lu))
1494 GOTO(out_fo, rc = -EREMOTE);
1496 version = dt_version_get(env, ofd_object_child(fo));
1498 GOTO(out_fo, rc = -EIO);
1500 *(dt_obj_version_t *)data->ioc_inlbuf2 = version;
1504 ofd_object_put(env, fo);
1509 int ofd_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1510 void *karg, void *uarg)
1513 struct ofd_device *ofd = ofd_exp(exp);
1514 struct obd_device *obd = ofd_obd(ofd);
1519 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
1520 rc = lu_env_init(&env, LCT_DT_THREAD);
1525 case OBD_IOC_ABORT_RECOVERY:
1526 CERROR("%s: aborting recovery\n", obd->obd_name);
1527 target_stop_recovery_thread(obd);
1530 CDEBUG(D_RPCTRACE, "syncing ost %s\n", obd->obd_name);
1531 rc = dt_sync(&env, ofd->ofd_osd);
1533 case OBD_IOC_SET_READONLY:
1534 rc = dt_sync(&env, ofd->ofd_osd);
1536 rc = dt_ro(&env, ofd->ofd_osd);
1538 case OBD_IOC_START_LFSCK: {
1539 struct obd_ioctl_data *data = karg;
1540 struct lfsck_start_param lsp;
1542 if (unlikely(data == NULL)) {
1547 lsp.lsp_start = (struct lfsck_start *)(data->ioc_inlbuf1);
1548 lsp.lsp_namespace = ofd->ofd_namespace;
1549 rc = lfsck_start(&env, ofd->ofd_osd, &lsp);
1552 case OBD_IOC_STOP_LFSCK: {
1553 rc = lfsck_stop(&env, ofd->ofd_osd, false);
1556 case OBD_IOC_GET_OBJ_VERSION:
1557 rc = ofd_ioc_get_obj_version(&env, ofd, karg);
1560 CERROR("%s: not supported cmd = %d\n", obd->obd_name, cmd);
1568 static int ofd_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1575 case OBD_CLEANUP_EARLY:
1577 case OBD_CLEANUP_EXPORTS:
1578 target_cleanup_recovery(obd);
1584 static int ofd_ping(const struct lu_env *env, struct obd_export *exp)
1586 ofd_fmd_expire(exp);
1590 static int ofd_health_check(const struct lu_env *nul, struct obd_device *obd)
1592 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
1593 struct ofd_thread_info *info;
1595 #ifdef USE_HEALTH_CHECK_WRITE
1600 /* obd_proc_read_health pass NULL env, we need real one */
1601 rc = lu_env_init(&env, LCT_DT_THREAD);
1605 info = ofd_info_init(&env, NULL);
1606 rc = dt_statfs(&env, ofd->ofd_osd, &info->fti_u.osfs);
1610 if (info->fti_u.osfs.os_state == OS_STATE_READONLY)
1611 GOTO(out, rc = -EROFS);
1613 #ifdef USE_HEALTH_CHECK_WRITE
1614 OBD_ALLOC(info->fti_buf.lb_buf, PAGE_CACHE_SIZE);
1615 if (info->fti_buf.lb_buf == NULL)
1616 GOTO(out, rc = -ENOMEM);
1618 info->fti_buf.lb_len = PAGE_CACHE_SIZE;
1621 th = dt_trans_create(&env, ofd->ofd_osd);
1623 GOTO(out, rc = PTR_ERR(th));
1625 rc = dt_declare_record_write(&env, ofd->ofd_health_check_file,
1626 info->fti_buf.lb_len, info->fti_off, th);
1628 th->th_sync = 1; /* sync IO is needed */
1629 rc = dt_trans_start_local(&env, ofd->ofd_osd, th);
1631 rc = dt_record_write(&env, ofd->ofd_health_check_file,
1632 &info->fti_buf, &info->fti_off,
1635 dt_trans_stop(&env, ofd->ofd_osd, th);
1637 OBD_FREE(info->fti_buf.lb_buf, PAGE_CACHE_SIZE);
1639 CDEBUG(D_INFO, "write 1 page synchronously for checking io rc %d\n",rc);
1647 * Handle quota control requests to consult current usage/limit.
1649 * \param obd - is the obd device associated with the ofd
1650 * \param exp - is the client's export
1651 * \param oqctl - is the obd_quotactl request to be processed
1653 static int ofd_quotactl(struct obd_device *obd, struct obd_export *exp,
1654 struct obd_quotactl *oqctl)
1656 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
1661 /* report success for quota on/off for interoperability with current MDT
1663 if (oqctl->qc_cmd == Q_QUOTAON || oqctl->qc_cmd == Q_QUOTAOFF)
1666 rc = lu_env_init(&env, LCT_DT_THREAD);
1670 rc = lquotactl_slv(&env, ofd->ofd_osd, oqctl);
1676 struct obd_ops ofd_obd_ops = {
1677 .o_owner = THIS_MODULE,
1678 .o_connect = ofd_obd_connect,
1679 .o_reconnect = ofd_obd_reconnect,
1680 .o_disconnect = ofd_obd_disconnect,
1681 .o_set_info_async = ofd_set_info_async,
1682 .o_get_info = ofd_get_info,
1683 .o_create = ofd_create,
1684 .o_statfs = ofd_statfs,
1685 .o_setattr = ofd_setattr,
1686 .o_preprw = ofd_preprw,
1687 .o_commitrw = ofd_commitrw,
1688 .o_destroy = ofd_destroy,
1689 .o_init_export = ofd_init_export,
1690 .o_destroy_export = ofd_destroy_export,
1691 .o_postrecov = ofd_obd_postrecov,
1692 .o_punch = ofd_punch,
1693 .o_getattr = ofd_getattr,
1695 .o_iocontrol = ofd_iocontrol,
1696 .o_precleanup = ofd_precleanup,
1698 .o_health_check = ofd_health_check,
1699 .o_quotactl = ofd_quotactl,