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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LMV
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/pagemap.h>
39 #include <asm/div64.h>
40 #include <linux/seq_file.h>
41 #include <linux/namei.h>
42 #include <linux/uaccess.h>
44 #include "../include/lustre/lustre_idl.h"
45 #include "../include/obd_support.h"
46 #include "../include/lustre_net.h"
47 #include "../include/obd_class.h"
48 #include "../include/lustre_lmv.h"
49 #include "../include/lprocfs_status.h"
50 #include "../include/cl_object.h"
51 #include "../include/lustre_fid.h"
52 #include "../include/lustre/lustre_ioctl.h"
53 #include "../include/lustre_kernelcomm.h"
54 #include "lmv_internal.h"
56 static void lmv_activate_target(struct lmv_obd *lmv,
57 struct lmv_tgt_desc *tgt,
60 if (tgt->ltd_active == activate)
63 tgt->ltd_active = activate;
64 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
70 * -EINVAL : UUID can't be found in the LMV's target list
71 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
72 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
74 static int lmv_set_mdc_active(struct lmv_obd *lmv, const struct obd_uuid *uuid,
77 struct lmv_tgt_desc *uninitialized_var(tgt);
78 struct obd_device *obd;
82 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
83 lmv, uuid->uuid, activate);
85 spin_lock(&lmv->lmv_lock);
86 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
88 if (!tgt || !tgt->ltd_exp)
91 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
92 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
94 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
98 if (i == lmv->desc.ld_tgt_count) {
103 obd = class_exp2obd(tgt->ltd_exp);
109 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
110 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
111 obd->obd_type->typ_name, i);
112 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
114 if (tgt->ltd_active == activate) {
115 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
116 activate ? "" : "in");
120 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
121 activate ? "" : "in");
122 lmv_activate_target(lmv, tgt, activate);
125 spin_unlock(&lmv->lmv_lock);
129 static struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
131 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
132 struct lmv_tgt_desc *tgt = lmv->tgts[0];
134 return tgt ? obd_get_uuid(tgt->ltd_exp) : NULL;
137 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
138 enum obd_notify_event ev, void *data)
140 struct obd_connect_data *conn_data;
141 struct lmv_obd *lmv = &obd->u.lmv;
142 struct obd_uuid *uuid;
145 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
146 CERROR("unexpected notification of %s %s!\n",
147 watched->obd_type->typ_name,
152 uuid = &watched->u.cli.cl_target_uuid;
153 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
155 * Set MDC as active before notifying the observer, so the
156 * observer can use the MDC normally.
158 rc = lmv_set_mdc_active(lmv, uuid,
159 ev == OBD_NOTIFY_ACTIVE);
161 CERROR("%sactivation of %s failed: %d\n",
162 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
166 } else if (ev == OBD_NOTIFY_OCD) {
167 conn_data = &watched->u.cli.cl_import->imp_connect_data;
169 * XXX: Make sure that ocd_connect_flags from all targets are
170 * the same. Otherwise one of MDTs runs wrong version or
171 * something like this. --umka
173 obd->obd_self_export->exp_connect_data = *conn_data;
176 else if (ev == OBD_NOTIFY_DISCON) {
178 * For disconnect event, flush fld cache for failout MDS case.
180 fld_client_flush(&lmv->lmv_fld);
184 * Pass the notification up the chain.
186 if (obd->obd_observer)
187 rc = obd_notify(obd->obd_observer, watched, ev, data);
193 * This is fake connect function. Its purpose is to initialize lmv and say
194 * caller that everything is okay. Real connection will be performed later.
196 static int lmv_connect(const struct lu_env *env,
197 struct obd_export **exp, struct obd_device *obd,
198 struct obd_uuid *cluuid, struct obd_connect_data *data,
201 struct lmv_obd *lmv = &obd->u.lmv;
202 struct lustre_handle conn = { 0 };
206 * We don't want to actually do the underlying connections more than
207 * once, so keep track.
210 if (lmv->refcount > 1) {
215 rc = class_connect(&conn, obd, cluuid);
217 CERROR("class_connection() returned %d\n", rc);
221 *exp = class_conn2export(&conn);
222 class_export_get(*exp);
226 lmv->cluuid = *cluuid;
229 lmv->conn_data = *data;
231 lmv->lmv_tgts_kobj = kobject_create_and_add("target_obds",
234 * All real clients should perform actual connection right away, because
235 * it is possible, that LMV will not have opportunity to connect targets
236 * and MDC stuff will be called directly, for instance while reading
237 * ../mdc/../kbytesfree procfs file, etc.
239 if (data && data->ocd_connect_flags & OBD_CONNECT_REAL)
240 rc = lmv_check_connect(obd);
242 if (rc && lmv->lmv_tgts_kobj)
243 kobject_put(lmv->lmv_tgts_kobj);
248 static int lmv_init_ea_size(struct obd_export *exp, u32 easize, u32 def_easize,
249 u32 cookiesize, u32 def_cookiesize)
251 struct obd_device *obd = exp->exp_obd;
252 struct lmv_obd *lmv = &obd->u.lmv;
257 if (lmv->max_easize < easize) {
258 lmv->max_easize = easize;
261 if (lmv->max_def_easize < def_easize) {
262 lmv->max_def_easize = def_easize;
265 if (lmv->max_cookiesize < cookiesize) {
266 lmv->max_cookiesize = cookiesize;
269 if (lmv->max_def_cookiesize < def_cookiesize) {
270 lmv->max_def_cookiesize = def_cookiesize;
276 if (lmv->connected == 0)
279 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
280 struct lmv_tgt_desc *tgt = lmv->tgts[i];
282 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active) {
283 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
287 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize,
288 cookiesize, def_cookiesize);
290 CERROR("%s: obd_init_ea_size() failed on MDT target %d: rc = %d\n",
291 obd->obd_name, i, rc);
298 #define MAX_STRING_SIZE 128
300 static int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
302 struct lmv_obd *lmv = &obd->u.lmv;
303 struct obd_uuid *cluuid = &lmv->cluuid;
304 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
305 struct obd_device *mdc_obd;
306 struct obd_export *mdc_exp;
307 struct lu_fld_target target;
310 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
313 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
317 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
318 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
319 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid, cluuid->uuid);
321 if (!mdc_obd->obd_set_up) {
322 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
326 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
327 &lmv->conn_data, NULL);
329 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
334 * Init fid sequence client for this mdc and add new fld target.
336 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
340 target.ft_srv = NULL;
341 target.ft_exp = mdc_exp;
342 target.ft_idx = tgt->ltd_idx;
344 fld_client_add_target(&lmv->lmv_fld, &target);
346 rc = obd_register_observer(mdc_obd, obd);
348 obd_disconnect(mdc_exp);
349 CERROR("target %s register_observer error %d\n",
350 tgt->ltd_uuid.uuid, rc);
354 if (obd->obd_observer) {
356 * Tell the observer about the new target.
358 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
360 (void *)(tgt - lmv->tgts[0]));
362 obd_disconnect(mdc_exp);
368 tgt->ltd_exp = mdc_exp;
369 lmv->desc.ld_active_tgt_count++;
371 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize,
372 lmv->max_cookiesize, lmv->max_def_cookiesize);
374 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
375 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
376 atomic_read(&obd->obd_refcount));
378 if (lmv->lmv_tgts_kobj)
379 /* Even if we failed to create the link, that's fine */
380 rc = sysfs_create_link(lmv->lmv_tgts_kobj, &mdc_obd->obd_kobj,
385 static void lmv_del_target(struct lmv_obd *lmv, int index)
387 if (!lmv->tgts[index])
390 kfree(lmv->tgts[index]);
391 lmv->tgts[index] = NULL;
395 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
396 __u32 index, int gen)
398 struct lmv_obd *lmv = &obd->u.lmv;
399 struct lmv_tgt_desc *tgt;
400 int orig_tgt_count = 0;
403 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
405 mutex_lock(&lmv->lmv_init_mutex);
407 if (lmv->desc.ld_tgt_count == 0) {
408 struct obd_device *mdc_obd;
410 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
413 mutex_unlock(&lmv->lmv_init_mutex);
414 CERROR("%s: Target %s not attached: rc = %d\n",
415 obd->obd_name, uuidp->uuid, -EINVAL);
420 if ((index < lmv->tgts_size) && lmv->tgts[index]) {
421 tgt = lmv->tgts[index];
422 CERROR("%s: UUID %s already assigned at LOV target index %d: rc = %d\n",
424 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
425 mutex_unlock(&lmv->lmv_init_mutex);
429 if (index >= lmv->tgts_size) {
430 /* We need to reallocate the lmv target array. */
431 struct lmv_tgt_desc **newtgts, **old = NULL;
435 while (newsize < index + 1)
437 newtgts = kcalloc(newsize, sizeof(*newtgts), GFP_NOFS);
439 mutex_unlock(&lmv->lmv_init_mutex);
443 if (lmv->tgts_size) {
444 memcpy(newtgts, lmv->tgts,
445 sizeof(*newtgts) * lmv->tgts_size);
447 oldsize = lmv->tgts_size;
451 lmv->tgts_size = newsize;
455 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
459 tgt = kzalloc(sizeof(*tgt), GFP_NOFS);
461 mutex_unlock(&lmv->lmv_init_mutex);
465 mutex_init(&tgt->ltd_fid_mutex);
466 tgt->ltd_idx = index;
467 tgt->ltd_uuid = *uuidp;
469 lmv->tgts[index] = tgt;
470 if (index >= lmv->desc.ld_tgt_count) {
471 orig_tgt_count = lmv->desc.ld_tgt_count;
472 lmv->desc.ld_tgt_count = index + 1;
475 if (lmv->connected) {
476 rc = lmv_connect_mdc(obd, tgt);
478 spin_lock(&lmv->lmv_lock);
479 if (lmv->desc.ld_tgt_count == index + 1)
480 lmv->desc.ld_tgt_count = orig_tgt_count;
481 memset(tgt, 0, sizeof(*tgt));
482 spin_unlock(&lmv->lmv_lock);
484 int easize = sizeof(struct lmv_stripe_md) +
485 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
486 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
490 mutex_unlock(&lmv->lmv_init_mutex);
494 int lmv_check_connect(struct obd_device *obd)
496 struct lmv_obd *lmv = &obd->u.lmv;
497 struct lmv_tgt_desc *tgt;
505 mutex_lock(&lmv->lmv_init_mutex);
506 if (lmv->connected) {
507 mutex_unlock(&lmv->lmv_init_mutex);
511 if (lmv->desc.ld_tgt_count == 0) {
512 mutex_unlock(&lmv->lmv_init_mutex);
513 CERROR("%s: no targets configured.\n", obd->obd_name);
520 mutex_unlock(&lmv->lmv_init_mutex);
521 CERROR("%s: no target configured for index 0.\n",
526 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
527 lmv->cluuid.uuid, obd->obd_name);
529 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
533 rc = lmv_connect_mdc(obd, tgt);
538 class_export_put(lmv->exp);
540 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
541 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
542 mutex_unlock(&lmv->lmv_init_mutex);
554 --lmv->desc.ld_active_tgt_count;
555 rc2 = obd_disconnect(tgt->ltd_exp);
557 CERROR("LMV target %s disconnect on MDC idx %d: error %d\n",
558 tgt->ltd_uuid.uuid, i, rc2);
562 class_disconnect(lmv->exp);
563 mutex_unlock(&lmv->lmv_init_mutex);
567 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
569 struct lmv_obd *lmv = &obd->u.lmv;
570 struct obd_device *mdc_obd;
573 mdc_obd = class_exp2obd(tgt->ltd_exp);
576 mdc_obd->obd_force = obd->obd_force;
577 mdc_obd->obd_fail = obd->obd_fail;
578 mdc_obd->obd_no_recov = obd->obd_no_recov;
580 if (lmv->lmv_tgts_kobj)
581 sysfs_remove_link(lmv->lmv_tgts_kobj,
585 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
587 CERROR("Can't finalize fids factory\n");
589 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
590 tgt->ltd_exp->exp_obd->obd_name,
591 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
593 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
594 rc = obd_disconnect(tgt->ltd_exp);
596 if (tgt->ltd_active) {
597 CERROR("Target %s disconnect error %d\n",
598 tgt->ltd_uuid.uuid, rc);
602 lmv_activate_target(lmv, tgt, 0);
607 static int lmv_disconnect(struct obd_export *exp)
609 struct obd_device *obd = class_exp2obd(exp);
610 struct lmv_obd *lmv = &obd->u.lmv;
618 * Only disconnect the underlying layers on the final disconnect.
621 if (lmv->refcount != 0)
624 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
625 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
628 lmv_disconnect_mdc(obd, lmv->tgts[i]);
631 if (lmv->lmv_tgts_kobj)
632 kobject_put(lmv->lmv_tgts_kobj);
636 * This is the case when no real connection is established by
637 * lmv_check_connect().
640 class_export_put(exp);
641 rc = class_disconnect(exp);
642 if (lmv->refcount == 0)
647 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
650 struct obd_device *obddev = class_exp2obd(exp);
651 struct lmv_obd *lmv = &obddev->u.lmv;
652 struct getinfo_fid2path *gf;
653 struct lmv_tgt_desc *tgt;
654 struct getinfo_fid2path *remote_gf = NULL;
655 int remote_gf_size = 0;
658 gf = (struct getinfo_fid2path *)karg;
659 tgt = lmv_find_target(lmv, &gf->gf_fid);
664 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
665 if (rc != 0 && rc != -EREMOTE)
668 /* If remote_gf != NULL, it means just building the
669 * path on the remote MDT, copy this path segment to gf
672 struct getinfo_fid2path *ori_gf;
675 ori_gf = (struct getinfo_fid2path *)karg;
676 if (strlen(ori_gf->gf_path) +
677 strlen(gf->gf_path) > ori_gf->gf_pathlen) {
682 ptr = ori_gf->gf_path;
684 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
685 strlen(ori_gf->gf_path));
687 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
688 ptr += strlen(gf->gf_path);
692 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
693 tgt->ltd_exp->exp_obd->obd_name,
694 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
700 /* sigh, has to go to another MDT to do path building further */
702 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
703 remote_gf = kzalloc(remote_gf_size, GFP_NOFS);
708 remote_gf->gf_pathlen = PATH_MAX;
711 if (!fid_is_sane(&gf->gf_fid)) {
712 CERROR("%s: invalid FID "DFID": rc = %d\n",
713 tgt->ltd_exp->exp_obd->obd_name,
714 PFID(&gf->gf_fid), -EINVAL);
719 tgt = lmv_find_target(lmv, &gf->gf_fid);
725 remote_gf->gf_fid = gf->gf_fid;
726 remote_gf->gf_recno = -1;
727 remote_gf->gf_linkno = -1;
728 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
730 goto repeat_fid2path;
737 static int lmv_hsm_req_count(struct lmv_obd *lmv,
738 const struct hsm_user_request *hur,
739 const struct lmv_tgt_desc *tgt_mds)
742 struct lmv_tgt_desc *curr_tgt;
744 /* count how many requests must be sent to the given target */
745 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
746 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
747 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
753 static void lmv_hsm_req_build(struct lmv_obd *lmv,
754 struct hsm_user_request *hur_in,
755 const struct lmv_tgt_desc *tgt_mds,
756 struct hsm_user_request *hur_out)
759 struct lmv_tgt_desc *curr_tgt;
761 /* build the hsm_user_request for the given target */
762 hur_out->hur_request = hur_in->hur_request;
764 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
765 curr_tgt = lmv_find_target(lmv,
766 &hur_in->hur_user_item[i].hui_fid);
767 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
768 hur_out->hur_user_item[nr_out] =
769 hur_in->hur_user_item[i];
773 hur_out->hur_request.hr_itemcount = nr_out;
774 memcpy(hur_data(hur_out), hur_data(hur_in),
775 hur_in->hur_request.hr_data_len);
778 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
779 struct lustre_kernelcomm *lk,
785 /* unregister request (call from llapi_hsm_copytool_fini) */
786 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
787 struct lmv_tgt_desc *tgt = lmv->tgts[i];
789 if (!tgt || !tgt->ltd_exp)
792 /* best effort: try to clean as much as possible
793 * (continue on error)
795 obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len, lk, uarg);
798 /* Whatever the result, remove copytool from kuc groups.
799 * Unreached coordinators will get EPIPE on next requests
800 * and will unregister automatically.
802 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
807 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
808 struct lustre_kernelcomm *lk, void __user *uarg)
813 bool any_set = false;
814 struct kkuc_ct_data kcd = { 0 };
816 /* All or nothing: try to register to all MDS.
817 * In case of failure, unregister from previous MDS,
818 * except if it because of inactive target.
820 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
821 struct lmv_tgt_desc *tgt = lmv->tgts[i];
823 if (!tgt || !tgt->ltd_exp)
826 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
828 if (tgt->ltd_active) {
829 /* permanent error */
830 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
831 tgt->ltd_uuid.uuid, i, cmd, err);
833 lk->lk_flags |= LK_FLG_STOP;
834 /* unregister from previous MDS */
835 for (j = 0; j < i; j++) {
838 if (!tgt || !tgt->ltd_exp)
840 obd_iocontrol(cmd, tgt->ltd_exp, len,
845 /* else: transient error.
846 * kuc will register to the missing MDT when it is back
854 /* no registration done: return error */
857 /* at least one registration done, with no failure */
858 filp = fget(lk->lk_wfd);
862 kcd.kcd_magic = KKUC_CT_DATA_MAGIC;
863 kcd.kcd_uuid = lmv->cluuid;
864 kcd.kcd_archive = lk->lk_data;
866 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group,
874 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
875 int len, void *karg, void __user *uarg)
877 struct obd_device *obddev = class_exp2obd(exp);
878 struct lmv_obd *lmv = &obddev->u.lmv;
879 struct lmv_tgt_desc *tgt = NULL;
883 u32 count = lmv->desc.ld_tgt_count;
889 case IOC_OBD_STATFS: {
890 struct obd_ioctl_data *data = karg;
891 struct obd_device *mdc_obd;
892 struct obd_statfs stat_buf = {0};
895 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
899 tgt = lmv->tgts[index];
900 if (!tgt || !tgt->ltd_active)
903 mdc_obd = class_exp2obd(tgt->ltd_exp);
908 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
909 min((int)data->ioc_plen2,
910 (int)sizeof(struct obd_uuid))))
913 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
914 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
918 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
919 min((int)data->ioc_plen1,
920 (int)sizeof(stat_buf))))
924 case OBD_IOC_QUOTACTL: {
925 struct if_quotactl *qctl = karg;
926 struct obd_quotactl *oqctl;
928 if (qctl->qc_valid == QC_MDTIDX) {
929 if (count <= qctl->qc_idx)
932 tgt = lmv->tgts[qctl->qc_idx];
933 if (!tgt || !tgt->ltd_exp)
935 } else if (qctl->qc_valid == QC_UUID) {
936 for (i = 0; i < count; i++) {
940 if (!obd_uuid_equals(&tgt->ltd_uuid,
956 LASSERT(tgt && tgt->ltd_exp);
957 oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
961 QCTL_COPY(oqctl, qctl);
962 rc = obd_quotactl(tgt->ltd_exp, oqctl);
964 QCTL_COPY(qctl, oqctl);
965 qctl->qc_valid = QC_MDTIDX;
966 qctl->obd_uuid = tgt->ltd_uuid;
971 case OBD_IOC_CHANGELOG_SEND:
972 case OBD_IOC_CHANGELOG_CLEAR: {
973 struct ioc_changelog *icc = karg;
975 if (icc->icc_mdtindex >= count)
978 tgt = lmv->tgts[icc->icc_mdtindex];
979 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
981 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
984 case LL_IOC_GET_CONNECT_FLAGS: {
987 if (!tgt || !tgt->ltd_exp)
989 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
992 case LL_IOC_FID2MDTIDX: {
993 struct lu_fid *fid = karg;
996 rc = lmv_fld_lookup(lmv, fid, &mdt_index);
1001 * Note: this is from llite(see ll_dir_ioctl()), @uarg does not
1002 * point to user space memory for FID2MDTIDX.
1004 *(__u32 *)uarg = mdt_index;
1007 case OBD_IOC_FID2PATH: {
1008 rc = lmv_fid2path(exp, len, karg, uarg);
1011 case LL_IOC_HSM_STATE_GET:
1012 case LL_IOC_HSM_STATE_SET:
1013 case LL_IOC_HSM_ACTION: {
1014 struct md_op_data *op_data = karg;
1016 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1018 return PTR_ERR(tgt);
1023 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1026 case LL_IOC_HSM_PROGRESS: {
1027 const struct hsm_progress_kernel *hpk = karg;
1029 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1031 return PTR_ERR(tgt);
1032 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1035 case LL_IOC_HSM_REQUEST: {
1036 struct hsm_user_request *hur = karg;
1037 unsigned int reqcount = hur->hur_request.hr_itemcount;
1042 /* if the request is about a single fid
1043 * or if there is a single MDS, no need to split
1046 if (reqcount == 1 || count == 1) {
1047 tgt = lmv_find_target(lmv,
1048 &hur->hur_user_item[0].hui_fid);
1050 return PTR_ERR(tgt);
1051 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1053 /* split fid list to their respective MDS */
1054 for (i = 0; i < count; i++) {
1055 unsigned int nr, reqlen;
1057 struct hsm_user_request *req;
1060 if (!tgt || !tgt->ltd_exp)
1063 nr = lmv_hsm_req_count(lmv, hur, tgt);
1064 if (nr == 0) /* nothing for this MDS */
1067 /* build a request with fids for this MDS */
1068 reqlen = offsetof(typeof(*hur),
1070 + hur->hur_request.hr_data_len;
1071 req = libcfs_kvzalloc(reqlen, GFP_NOFS);
1075 lmv_hsm_req_build(lmv, hur, tgt, req);
1077 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1079 if (rc1 != 0 && rc == 0)
1086 case LL_IOC_LOV_SWAP_LAYOUTS: {
1087 struct md_op_data *op_data = karg;
1088 struct lmv_tgt_desc *tgt1, *tgt2;
1090 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1092 return PTR_ERR(tgt1);
1094 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1096 return PTR_ERR(tgt2);
1098 if (!tgt1->ltd_exp || !tgt2->ltd_exp)
1101 /* only files on same MDT can have their layouts swapped */
1102 if (tgt1->ltd_idx != tgt2->ltd_idx)
1105 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1108 case LL_IOC_HSM_CT_START: {
1109 struct lustre_kernelcomm *lk = karg;
1111 if (lk->lk_flags & LK_FLG_STOP)
1112 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1114 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1118 for (i = 0; i < count; i++) {
1119 struct obd_device *mdc_obd;
1123 if (!tgt || !tgt->ltd_exp)
1125 /* ll_umount_begin() sets force flag but for lmv, not
1126 * mdc. Let's pass it through
1128 mdc_obd = class_exp2obd(tgt->ltd_exp);
1129 mdc_obd->obd_force = obddev->obd_force;
1130 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1131 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1134 if (tgt->ltd_active) {
1135 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
1136 tgt->ltd_uuid.uuid, i, cmd, err);
1151 * This is _inode_ placement policy function (not name).
1153 static int lmv_placement_policy(struct obd_device *obd,
1154 struct md_op_data *op_data, u32 *mds)
1156 struct lmv_obd *lmv = &obd->u.lmv;
1160 if (lmv->desc.ld_tgt_count == 1) {
1165 if (op_data->op_default_stripe_offset != -1) {
1166 *mds = op_data->op_default_stripe_offset;
1171 * If stripe_offset is provided during setdirstripe
1172 * (setdirstripe -i xx), xx MDS will be chosen.
1174 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data) {
1175 struct lmv_user_md *lum;
1177 lum = op_data->op_data;
1178 if (le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1179 *mds = le32_to_cpu(lum->lum_stripe_offset);
1182 * -1 means default, which will be in the same MDT with
1185 *mds = op_data->op_mds;
1186 lum->lum_stripe_offset = cpu_to_le32(op_data->op_mds);
1190 * Allocate new fid on target according to operation type and
1193 *mds = op_data->op_mds;
1199 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1201 struct lmv_tgt_desc *tgt;
1204 tgt = lmv_get_target(lmv, mds, NULL);
1206 return PTR_ERR(tgt);
1209 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1210 * on server that seq in new allocated fid is not yet known.
1212 mutex_lock(&tgt->ltd_fid_mutex);
1214 if (tgt->ltd_active == 0 || !tgt->ltd_exp) {
1220 * Asking underlaying tgt layer to allocate new fid.
1222 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1224 LASSERT(fid_is_sane(fid));
1229 mutex_unlock(&tgt->ltd_fid_mutex);
1233 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1234 struct lu_fid *fid, struct md_op_data *op_data)
1236 struct obd_device *obd = class_exp2obd(exp);
1237 struct lmv_obd *lmv = &obd->u.lmv;
1244 rc = lmv_placement_policy(obd, op_data, &mds);
1246 CERROR("Can't get target for allocating fid, rc %d\n",
1251 rc = __lmv_fid_alloc(lmv, fid, mds);
1253 CERROR("Can't alloc new fid, rc %d\n", rc);
1260 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1262 struct lmv_obd *lmv = &obd->u.lmv;
1263 struct lprocfs_static_vars lvars = { NULL };
1264 struct lmv_desc *desc;
1267 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1268 CERROR("LMV setup requires a descriptor\n");
1272 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1273 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1274 CERROR("Lmv descriptor size wrong: %d > %d\n",
1275 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1279 lmv->tgts_size = 32U;
1280 lmv->tgts = kcalloc(lmv->tgts_size, sizeof(*lmv->tgts), GFP_NOFS);
1284 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1285 lmv->desc.ld_tgt_count = 0;
1286 lmv->desc.ld_active_tgt_count = 0;
1287 lmv->max_cookiesize = 0;
1288 lmv->max_def_easize = 0;
1289 lmv->max_easize = 0;
1290 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1292 spin_lock_init(&lmv->lmv_lock);
1293 mutex_init(&lmv->lmv_init_mutex);
1295 lprocfs_lmv_init_vars(&lvars);
1297 lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars);
1298 rc = ldebugfs_seq_create(obd->obd_debugfs_entry, "target_obd",
1299 0444, &lmv_proc_target_fops, obd);
1301 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1303 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1304 LUSTRE_CLI_FLD_HASH_DHT);
1306 CERROR("Can't init FLD, err %d\n", rc);
1316 static int lmv_cleanup(struct obd_device *obd)
1318 struct lmv_obd *lmv = &obd->u.lmv;
1320 fld_client_fini(&lmv->lmv_fld);
1324 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1327 lmv_del_target(lmv, i);
1335 static int lmv_process_config(struct obd_device *obd, u32 len, void *buf)
1337 struct lustre_cfg *lcfg = buf;
1338 struct obd_uuid obd_uuid;
1343 switch (lcfg->lcfg_command) {
1345 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1346 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID
1348 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid)) {
1353 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1355 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1) {
1359 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1) {
1363 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1366 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1374 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1375 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1377 struct obd_device *obd = class_exp2obd(exp);
1378 struct lmv_obd *lmv = &obd->u.lmv;
1379 struct obd_statfs *temp;
1383 rc = lmv_check_connect(obd);
1387 temp = kzalloc(sizeof(*temp), GFP_NOFS);
1391 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1392 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1395 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1398 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1399 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1406 /* If the statfs is from mount, it will needs
1407 * retrieve necessary information from MDT0.
1408 * i.e. mount does not need the merged osfs
1410 * And also clients can be mounted as long as
1411 * MDT0 is in service
1413 if (flags & OBD_STATFS_FOR_MDT0)
1416 osfs->os_bavail += temp->os_bavail;
1417 osfs->os_blocks += temp->os_blocks;
1418 osfs->os_ffree += temp->os_ffree;
1419 osfs->os_files += temp->os_files;
1428 static int lmv_getstatus(struct obd_export *exp,
1431 struct obd_device *obd = exp->exp_obd;
1432 struct lmv_obd *lmv = &obd->u.lmv;
1435 rc = lmv_check_connect(obd);
1439 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid);
1443 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1444 u64 valid, const char *name,
1445 const char *input, int input_size, int output_size,
1446 int flags, struct ptlrpc_request **request)
1448 struct obd_device *obd = exp->exp_obd;
1449 struct lmv_obd *lmv = &obd->u.lmv;
1450 struct lmv_tgt_desc *tgt;
1453 rc = lmv_check_connect(obd);
1457 tgt = lmv_find_target(lmv, fid);
1459 return PTR_ERR(tgt);
1461 rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input,
1462 input_size, output_size, flags, request);
1467 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1468 u64 valid, const char *name,
1469 const char *input, int input_size, int output_size,
1470 int flags, __u32 suppgid,
1471 struct ptlrpc_request **request)
1473 struct obd_device *obd = exp->exp_obd;
1474 struct lmv_obd *lmv = &obd->u.lmv;
1475 struct lmv_tgt_desc *tgt;
1478 rc = lmv_check_connect(obd);
1482 tgt = lmv_find_target(lmv, fid);
1484 return PTR_ERR(tgt);
1486 rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1487 input_size, output_size, flags, suppgid,
1493 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1494 struct ptlrpc_request **request)
1496 struct obd_device *obd = exp->exp_obd;
1497 struct lmv_obd *lmv = &obd->u.lmv;
1498 struct lmv_tgt_desc *tgt;
1501 rc = lmv_check_connect(obd);
1505 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1507 return PTR_ERR(tgt);
1509 if (op_data->op_flags & MF_GET_MDT_IDX) {
1510 op_data->op_mds = tgt->ltd_idx;
1514 rc = md_getattr(tgt->ltd_exp, op_data, request);
1519 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1521 struct obd_device *obd = exp->exp_obd;
1522 struct lmv_obd *lmv = &obd->u.lmv;
1526 rc = lmv_check_connect(obd);
1530 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1533 * With DNE every object can have two locks in different namespaces:
1534 * lookup lock in space of MDT storing direntry and update/open lock in
1535 * space of MDT storing inode.
1537 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1538 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1540 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1546 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1547 struct md_open_data *mod, struct ptlrpc_request **request)
1549 struct obd_device *obd = exp->exp_obd;
1550 struct lmv_obd *lmv = &obd->u.lmv;
1551 struct lmv_tgt_desc *tgt;
1554 rc = lmv_check_connect(obd);
1558 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1560 return PTR_ERR(tgt);
1562 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1563 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1568 * Choosing the MDT by name or FID in @op_data.
1569 * For non-striped directory, it will locate MDT by fid.
1570 * For striped-directory, it will locate MDT by name. And also
1571 * it will reset op_fid1 with the FID of the chosen stripe.
1573 static struct lmv_tgt_desc *
1574 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1575 const char *name, int namelen, struct lu_fid *fid,
1578 const struct lmv_oinfo *oinfo;
1579 struct lmv_tgt_desc *tgt;
1581 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
1582 if (cfs_fail_val >= lsm->lsm_md_stripe_count)
1583 return ERR_PTR(-EBADF);
1584 oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
1586 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1588 return ERR_CAST(oinfo);
1592 *fid = oinfo->lmo_fid;
1594 *mds = oinfo->lmo_mds;
1596 tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
1598 CDEBUG(D_INFO, "locate on mds %u " DFID "\n", oinfo->lmo_mds,
1599 PFID(&oinfo->lmo_fid));
1604 * Locate mds by fid or name
1606 * For striped directory (lsm != NULL), it will locate the stripe
1607 * by name hash (see lsm_name_to_stripe_info()). Note: if the hash_type
1608 * is unknown, it will return -EBADFD, and lmv_intent_lookup might need
1609 * walk through all of stripes to locate the entry.
1611 * For normal direcotry, it will locate MDS by FID directly.
1612 * \param[in] lmv LMV device
1613 * \param[in] op_data client MD stack parameters, name, namelen
1615 * \param[in] fid object FID used to locate MDS.
1617 * retval pointer to the lmv_tgt_desc if succeed.
1618 * ERR_PTR(errno) if failed.
1620 struct lmv_tgt_desc*
1621 lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1624 struct lmv_stripe_md *lsm = op_data->op_mea1;
1625 struct lmv_tgt_desc *tgt;
1628 * During creating VOLATILE file, it should honor the mdt
1629 * index if the file under striped dir is being restored, see
1632 if (op_data->op_bias & MDS_CREATE_VOLATILE &&
1633 (int)op_data->op_mds != -1 && lsm) {
1636 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
1640 /* refill the right parent fid */
1641 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1642 struct lmv_oinfo *oinfo;
1644 oinfo = &lsm->lsm_md_oinfo[i];
1645 if (oinfo->lmo_mds == op_data->op_mds) {
1646 *fid = oinfo->lmo_fid;
1651 /* Hmm, can not find the stripe by mdt_index(op_mds) */
1652 if (i == lsm->lsm_md_stripe_count)
1653 tgt = ERR_PTR(-EINVAL);
1658 if (!lsm || !op_data->op_namelen) {
1659 tgt = lmv_find_target(lmv, fid);
1663 op_data->op_mds = tgt->ltd_idx;
1668 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1669 op_data->op_namelen, fid,
1673 static int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1674 const void *data, size_t datalen, umode_t mode,
1675 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1676 __u64 rdev, struct ptlrpc_request **request)
1678 struct obd_device *obd = exp->exp_obd;
1679 struct lmv_obd *lmv = &obd->u.lmv;
1680 struct lmv_tgt_desc *tgt;
1683 rc = lmv_check_connect(obd);
1687 if (!lmv->desc.ld_active_tgt_count)
1690 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1692 return PTR_ERR(tgt);
1694 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1695 (int)op_data->op_namelen, op_data->op_name,
1696 PFID(&op_data->op_fid1), op_data->op_mds);
1698 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1702 if (exp_connect_flags(exp) & OBD_CONNECT_DIR_STRIPE) {
1704 * Send the create request to the MDT where the object
1707 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1709 return PTR_ERR(tgt);
1711 op_data->op_mds = tgt->ltd_idx;
1713 CDEBUG(D_CONFIG, "Server doesn't support striped dirs\n");
1716 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1717 PFID(&op_data->op_fid1), op_data->op_mds);
1719 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1720 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1721 cap_effective, rdev, request);
1726 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1731 static int lmv_done_writing(struct obd_export *exp,
1732 struct md_op_data *op_data,
1733 struct md_open_data *mod)
1735 struct obd_device *obd = exp->exp_obd;
1736 struct lmv_obd *lmv = &obd->u.lmv;
1737 struct lmv_tgt_desc *tgt;
1740 rc = lmv_check_connect(obd);
1744 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1746 return PTR_ERR(tgt);
1748 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1753 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1754 const ldlm_policy_data_t *policy,
1755 struct lookup_intent *it, struct md_op_data *op_data,
1756 struct lustre_handle *lockh, __u64 extra_lock_flags)
1758 struct obd_device *obd = exp->exp_obd;
1759 struct lmv_obd *lmv = &obd->u.lmv;
1760 struct lmv_tgt_desc *tgt;
1763 rc = lmv_check_connect(obd);
1767 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1768 LL_IT2STR(it), PFID(&op_data->op_fid1));
1770 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1772 return PTR_ERR(tgt);
1774 CDEBUG(D_INODE, "ENQUEUE '%s' on " DFID " -> mds #%u\n",
1775 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1777 rc = md_enqueue(tgt->ltd_exp, einfo, policy, it, op_data, lockh,
1784 lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
1785 struct ptlrpc_request **preq)
1787 struct ptlrpc_request *req = NULL;
1788 struct obd_device *obd = exp->exp_obd;
1789 struct lmv_obd *lmv = &obd->u.lmv;
1790 struct lmv_tgt_desc *tgt;
1791 struct mdt_body *body;
1794 rc = lmv_check_connect(obd);
1798 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1800 return PTR_ERR(tgt);
1802 CDEBUG(D_INODE, "GETATTR_NAME for %*s on " DFID " -> mds #%u\n",
1803 (int)op_data->op_namelen, op_data->op_name,
1804 PFID(&op_data->op_fid1), tgt->ltd_idx);
1806 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1810 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1811 if (body->mbo_valid & OBD_MD_MDS) {
1812 struct lu_fid rid = body->mbo_fid1;
1814 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1817 tgt = lmv_find_target(lmv, &rid);
1819 ptlrpc_req_finished(*preq);
1821 return PTR_ERR(tgt);
1824 op_data->op_fid1 = rid;
1825 op_data->op_valid |= OBD_MD_FLCROSSREF;
1826 op_data->op_namelen = 0;
1827 op_data->op_name = NULL;
1828 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1829 ptlrpc_req_finished(*preq);
1836 #define md_op_data_fid(op_data, fl) \
1837 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1838 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1839 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1840 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1843 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
1844 struct md_op_data *op_data, int op_tgt,
1845 enum ldlm_mode mode, int bits, int flag)
1847 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1848 struct obd_device *obd = exp->exp_obd;
1849 struct lmv_obd *lmv = &obd->u.lmv;
1850 ldlm_policy_data_t policy = { {0} };
1853 if (!fid_is_sane(fid))
1857 tgt = lmv_find_target(lmv, fid);
1859 return PTR_ERR(tgt);
1862 if (tgt->ltd_idx != op_tgt) {
1863 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1864 policy.l_inodebits.bits = bits;
1865 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1866 mode, LCF_ASYNC, NULL);
1869 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1871 op_data->op_flags |= flag;
1879 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1882 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1883 struct ptlrpc_request **request)
1885 struct obd_device *obd = exp->exp_obd;
1886 struct lmv_obd *lmv = &obd->u.lmv;
1887 struct lmv_tgt_desc *tgt;
1890 rc = lmv_check_connect(obd);
1894 LASSERT(op_data->op_namelen != 0);
1896 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1897 PFID(&op_data->op_fid2), (int)op_data->op_namelen,
1898 op_data->op_name, PFID(&op_data->op_fid1));
1900 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1901 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1902 op_data->op_cap = cfs_curproc_cap_pack();
1903 if (op_data->op_mea2) {
1904 struct lmv_stripe_md *lsm = op_data->op_mea2;
1905 const struct lmv_oinfo *oinfo;
1907 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1908 op_data->op_namelen);
1910 return PTR_ERR(oinfo);
1912 op_data->op_fid2 = oinfo->lmo_fid;
1915 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1917 return PTR_ERR(tgt);
1920 * Cancel UPDATE lock on child (fid1).
1922 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1923 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
1924 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1928 rc = md_link(tgt->ltd_exp, op_data, request);
1933 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1934 const char *old, size_t oldlen,
1935 const char *new, size_t newlen,
1936 struct ptlrpc_request **request)
1938 struct obd_device *obd = exp->exp_obd;
1939 struct lmv_obd *lmv = &obd->u.lmv;
1940 struct lmv_tgt_desc *src_tgt;
1943 LASSERT(oldlen != 0);
1945 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
1946 (int)oldlen, old, PFID(&op_data->op_fid1),
1947 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
1948 (int)newlen, new, PFID(&op_data->op_fid2),
1949 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
1951 rc = lmv_check_connect(obd);
1955 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1956 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1957 op_data->op_cap = cfs_curproc_cap_pack();
1959 if (op_data->op_cli_flags & CLI_MIGRATE) {
1960 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
1961 PFID(&op_data->op_fid3));
1963 if (op_data->op_mea1) {
1964 struct lmv_stripe_md *lsm = op_data->op_mea1;
1965 struct lmv_tgt_desc *tmp;
1967 /* Fix the parent fid for striped dir */
1968 tmp = lmv_locate_target_for_name(lmv, lsm, old,
1973 return PTR_ERR(tmp);
1976 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1979 src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
1981 if (op_data->op_mea1) {
1982 struct lmv_stripe_md *lsm = op_data->op_mea1;
1984 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
1988 if (IS_ERR(src_tgt))
1989 return PTR_ERR(src_tgt);
1991 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
1992 if (IS_ERR(src_tgt))
1993 return PTR_ERR(src_tgt);
1995 op_data->op_mds = src_tgt->ltd_idx;
1998 if (op_data->op_mea2) {
1999 struct lmv_stripe_md *lsm = op_data->op_mea2;
2000 const struct lmv_oinfo *oinfo;
2002 oinfo = lsm_name_to_stripe_info(lsm, new, newlen);
2004 return PTR_ERR(oinfo);
2006 op_data->op_fid2 = oinfo->lmo_fid;
2009 if (IS_ERR(src_tgt))
2010 return PTR_ERR(src_tgt);
2013 * LOOKUP lock on src child (fid3) should also be cancelled for
2014 * src_tgt in mdc_rename.
2016 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2019 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2022 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2023 LCK_EX, MDS_INODELOCK_UPDATE,
2024 MF_MDC_CANCEL_FID2);
2028 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
2030 if (fid_is_sane(&op_data->op_fid3)) {
2031 struct lmv_tgt_desc *tgt;
2033 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2035 return PTR_ERR(tgt);
2037 /* Cancel LOOKUP lock on its parent */
2038 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
2039 LCK_EX, MDS_INODELOCK_LOOKUP,
2040 MF_MDC_CANCEL_FID3);
2044 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2045 LCK_EX, MDS_INODELOCK_FULL,
2046 MF_MDC_CANCEL_FID3);
2052 * Cancel all the locks on tgt child (fid4).
2054 if (fid_is_sane(&op_data->op_fid4))
2055 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2056 LCK_EX, MDS_INODELOCK_FULL,
2057 MF_MDC_CANCEL_FID4);
2059 CDEBUG(D_INODE, DFID":m%d to "DFID"\n", PFID(&op_data->op_fid1),
2060 op_data->op_mds, PFID(&op_data->op_fid2));
2062 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
2063 new, newlen, request);
2067 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2068 void *ea, size_t ealen, void *ea2, size_t ea2len,
2069 struct ptlrpc_request **request,
2070 struct md_open_data **mod)
2072 struct obd_device *obd = exp->exp_obd;
2073 struct lmv_obd *lmv = &obd->u.lmv;
2074 struct lmv_tgt_desc *tgt;
2077 rc = lmv_check_connect(obd);
2081 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2082 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2084 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2085 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2087 return PTR_ERR(tgt);
2089 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2090 ea2len, request, mod);
2095 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
2096 struct ptlrpc_request **request)
2098 struct obd_device *obd = exp->exp_obd;
2099 struct lmv_obd *lmv = &obd->u.lmv;
2100 struct lmv_tgt_desc *tgt;
2103 rc = lmv_check_connect(obd);
2107 tgt = lmv_find_target(lmv, fid);
2109 return PTR_ERR(tgt);
2111 rc = md_sync(tgt->ltd_exp, fid, request);
2116 * Get current minimum entry from striped directory
2118 * This function will search the dir entry, whose hash value is the
2119 * closest(>=) to @hash_offset, from all of sub-stripes, and it is
2120 * only being called for striped directory.
2122 * \param[in] exp export of LMV
2123 * \param[in] op_data parameters transferred beween client MD stack
2124 * stripe_information will be included in this
2126 * \param[in] cb_op ldlm callback being used in enqueue in
2128 * \param[in] hash_offset the hash value, which is used to locate
2129 * minum(closet) dir entry
2130 * \param[in|out] stripe_offset the caller use this to indicate the stripe
2131 * index of last entry, so to avoid hash conflict
2132 * between stripes. It will also be used to
2133 * return the stripe index of current dir entry.
2134 * \param[in|out] entp the minum entry and it also is being used
2135 * to input the last dir entry to resolve the
2138 * \param[out] ppage the page which holds the minum entry
2140 * \retval = 0 get the entry successfully
2141 * negative errno (< 0) does not get the entry
2143 static int lmv_get_min_striped_entry(struct obd_export *exp,
2144 struct md_op_data *op_data,
2145 struct md_callback *cb_op,
2146 __u64 hash_offset, int *stripe_offset,
2147 struct lu_dirent **entp,
2148 struct page **ppage)
2150 struct lmv_stripe_md *lsm = op_data->op_mea1;
2151 struct obd_device *obd = exp->exp_obd;
2152 struct lmv_obd *lmv = &obd->u.lmv;
2153 struct lu_dirent *min_ent = NULL;
2154 struct page *min_page = NULL;
2155 struct lmv_tgt_desc *tgt;
2161 stripe_count = lsm->lsm_md_stripe_count;
2162 for (i = 0; i < stripe_count; i++) {
2163 __u64 stripe_hash = hash_offset;
2164 struct lu_dirent *ent = NULL;
2165 struct page *page = NULL;
2166 struct lu_dirpage *dp;
2168 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds, NULL);
2175 * op_data will be shared by each stripe, so we need
2176 * reset these value for each stripe
2178 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2179 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2180 op_data->op_data = lsm->lsm_md_oinfo[i].lmo_root;
2182 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, stripe_hash,
2187 dp = page_address(page);
2188 for (ent = lu_dirent_start(dp); ent;
2189 ent = lu_dirent_next(ent)) {
2190 /* Skip dummy entry */
2191 if (!le16_to_cpu(ent->lde_namelen))
2194 if (le64_to_cpu(ent->lde_hash) < hash_offset)
2197 if (le64_to_cpu(ent->lde_hash) == hash_offset &&
2198 (*entp == ent || i < *stripe_offset))
2201 /* skip . and .. for other stripes */
2202 if (i && (!strncmp(ent->lde_name, ".",
2203 le16_to_cpu(ent->lde_namelen)) ||
2204 !strncmp(ent->lde_name, "..",
2205 le16_to_cpu(ent->lde_namelen))))
2211 stripe_hash = le64_to_cpu(dp->ldp_hash_end);
2218 * reach the end of current stripe, go to next stripe
2220 if (stripe_hash == MDS_DIR_END_OFF)
2227 if (le64_to_cpu(min_ent->lde_hash) >
2228 le64_to_cpu(ent->lde_hash)) {
2251 *stripe_offset = min_idx;
2258 * Build dir entry page from a striped directory
2260 * This function gets one entry by @offset from a striped directory. It will
2261 * read entries from all of stripes, and choose one closest to the required
2262 * offset(&offset). A few notes
2263 * 1. skip . and .. for non-zero stripes, because there can only have one .
2264 * and .. in a directory.
2265 * 2. op_data will be shared by all of stripes, instead of allocating new
2266 * one, so need to restore before reusing.
2267 * 3. release the entry page if that is not being chosen.
2269 * \param[in] exp obd export refer to LMV
2270 * \param[in] op_data hold those MD parameters of read_entry
2271 * \param[in] cb_op ldlm callback being used in enqueue in mdc_read_entry
2272 * \param[out] ldp the entry being read
2273 * \param[out] ppage the page holding the entry. Note: because the entry
2274 * will be accessed in upper layer, so we need hold the
2275 * page until the usages of entry is finished, see
2276 * ll_dir_entry_next.
2278 * retval =0 if get entry successfully
2279 * <0 cannot get entry
2281 static int lmv_read_striped_page(struct obd_export *exp,
2282 struct md_op_data *op_data,
2283 struct md_callback *cb_op,
2284 __u64 offset, struct page **ppage)
2286 struct inode *master_inode = op_data->op_data;
2287 struct lu_fid master_fid = op_data->op_fid1;
2288 struct obd_device *obd = exp->exp_obd;
2289 __u64 hash_offset = offset;
2290 struct page *min_ent_page = NULL;
2291 struct page *ent_page = NULL;
2292 struct lu_dirent *min_ent = NULL;
2293 struct lu_dirent *last_ent;
2294 struct lu_dirent *ent;
2295 struct lu_dirpage *dp;
2301 rc = lmv_check_connect(obd);
2306 * Allocate a page and read entries from all of stripes and fill
2307 * the page by hash order
2309 ent_page = alloc_page(GFP_KERNEL);
2313 /* Initialize the entry page */
2314 dp = kmap(ent_page);
2315 memset(dp, 0, sizeof(*dp));
2316 dp->ldp_hash_start = cpu_to_le64(offset);
2317 dp->ldp_flags |= LDF_COLLIDE;
2320 left_bytes = PAGE_SIZE - sizeof(*dp);
2326 /* Find the minum entry from all sub-stripes */
2327 rc = lmv_get_min_striped_entry(exp, op_data, cb_op, hash_offset,
2334 * If it can not get minum entry, it means it already reaches
2335 * the end of this directory
2338 last_ent->lde_reclen = 0;
2339 hash_offset = MDS_DIR_END_OFF;
2343 ent_size = le16_to_cpu(min_ent->lde_reclen);
2346 * the last entry lde_reclen is 0, but it might not
2347 * the end of this entry of this temporay entry
2350 ent_size = lu_dirent_calc_size(
2351 le16_to_cpu(min_ent->lde_namelen),
2352 le32_to_cpu(min_ent->lde_attrs));
2353 if (ent_size > left_bytes) {
2354 last_ent->lde_reclen = cpu_to_le16(0);
2355 hash_offset = le64_to_cpu(min_ent->lde_hash);
2359 memcpy(ent, min_ent, ent_size);
2362 * Replace . with master FID and Replace .. with the parent FID
2365 if (!strncmp(ent->lde_name, ".",
2366 le16_to_cpu(ent->lde_namelen)) &&
2367 le16_to_cpu(ent->lde_namelen) == 1)
2368 fid_cpu_to_le(&ent->lde_fid, &master_fid);
2369 else if (!strncmp(ent->lde_name, "..",
2370 le16_to_cpu(ent->lde_namelen)) &&
2371 le16_to_cpu(ent->lde_namelen) == 2)
2372 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid3);
2374 left_bytes -= ent_size;
2375 ent->lde_reclen = cpu_to_le16(ent_size);
2377 ent = (void *)ent + ent_size;
2378 hash_offset = le64_to_cpu(min_ent->lde_hash);
2379 if (hash_offset == MDS_DIR_END_OFF) {
2380 last_ent->lde_reclen = 0;
2386 kunmap(min_ent_page);
2387 put_page(min_ent_page);
2391 __free_page(ent_page);
2395 dp->ldp_flags |= LDF_EMPTY;
2396 dp->ldp_flags = cpu_to_le32(dp->ldp_flags);
2397 dp->ldp_hash_end = cpu_to_le64(hash_offset);
2401 * We do not want to allocate md_op_data during each
2402 * dir entry reading, so op_data will be shared by every stripe,
2403 * then we need to restore it back to original value before
2404 * return to the upper layer
2406 op_data->op_fid1 = master_fid;
2407 op_data->op_fid2 = master_fid;
2408 op_data->op_data = master_inode;
2415 static int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2416 struct md_callback *cb_op, __u64 offset,
2417 struct page **ppage)
2419 struct lmv_stripe_md *lsm = op_data->op_mea1;
2420 struct obd_device *obd = exp->exp_obd;
2421 struct lmv_obd *lmv = &obd->u.lmv;
2422 struct lmv_tgt_desc *tgt;
2425 rc = lmv_check_connect(obd);
2429 if (unlikely(lsm)) {
2430 rc = lmv_read_striped_page(exp, op_data, cb_op, offset, ppage);
2434 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2436 return PTR_ERR(tgt);
2438 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2444 * Unlink a file/directory
2446 * Unlink a file or directory under the parent dir. The unlink request
2447 * usually will be sent to the MDT where the child is located, but if
2448 * the client does not have the child FID then request will be sent to the
2449 * MDT where the parent is located.
2451 * If the parent is a striped directory then it also needs to locate which
2452 * stripe the name of the child is located, and replace the parent FID
2453 * (@op->op_fid1) with the stripe FID. Note: if the stripe is unknown,
2454 * it will walk through all of sub-stripes until the child is being
2457 * \param[in] exp export refer to LMV
2458 * \param[in] op_data different parameters transferred beween client
2459 * MD stacks, name, namelen, FIDs etc.
2460 * op_fid1 is the parent FID, op_fid2 is the child
2462 * \param[out] request point to the request of unlink.
2464 * retval 0 if succeed
2465 * negative errno if failed.
2467 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2468 struct ptlrpc_request **request)
2470 struct lmv_stripe_md *lsm = op_data->op_mea1;
2471 struct obd_device *obd = exp->exp_obd;
2472 struct lmv_obd *lmv = &obd->u.lmv;
2473 struct lmv_tgt_desc *parent_tgt = NULL;
2474 struct lmv_tgt_desc *tgt = NULL;
2475 struct mdt_body *body;
2476 int stripe_index = 0;
2479 rc = lmv_check_connect(obd);
2483 /* For striped dir, we need to locate the parent as well */
2485 struct lmv_tgt_desc *tmp;
2487 LASSERT(op_data->op_name && op_data->op_namelen);
2489 tmp = lmv_locate_target_for_name(lmv, lsm,
2491 op_data->op_namelen,
2496 * return -EBADFD means unknown hash type, might
2497 * need try all sub-stripe here
2499 if (IS_ERR(tmp) && PTR_ERR(tmp) != -EBADFD)
2500 return PTR_ERR(tmp);
2503 * Note: both migrating dir and unknown hash dir need to
2504 * try all of sub-stripes, so we need start search the
2505 * name from stripe 0, but migrating dir is already handled
2506 * inside lmv_locate_target_for_name(), so we only check
2507 * unknown hash type directory here
2509 if (!lmv_is_known_hash_type(lsm->lsm_md_hash_type)) {
2510 struct lmv_oinfo *oinfo;
2512 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2514 op_data->op_fid1 = oinfo->lmo_fid;
2515 op_data->op_mds = oinfo->lmo_mds;
2520 /* Send unlink requests to the MDT where the child is located */
2521 if (likely(!fid_is_zero(&op_data->op_fid2)))
2522 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2524 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
2526 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2529 return PTR_ERR(tgt);
2531 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2532 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2533 op_data->op_cap = cfs_curproc_cap_pack();
2536 * If child's fid is given, cancel unused locks for it if it is from
2537 * another export than parent.
2539 * LOOKUP lock for child (fid3) should also be cancelled on parent
2540 * tgt_tgt in mdc_unlink().
2542 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2545 * Cancel FULL locks on child (fid3).
2547 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2548 if (IS_ERR(parent_tgt))
2549 return PTR_ERR(parent_tgt);
2551 if (parent_tgt != tgt) {
2552 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2553 LCK_EX, MDS_INODELOCK_LOOKUP,
2554 MF_MDC_CANCEL_FID3);
2557 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2558 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2562 CDEBUG(D_INODE, "unlink with fid=" DFID "/" DFID " -> mds #%u\n",
2563 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2565 rc = md_unlink(tgt->ltd_exp, op_data, request);
2566 if (rc != 0 && rc != -EREMOTE && rc != -ENOENT)
2569 /* Try next stripe if it is needed. */
2570 if (rc == -ENOENT && lsm && lmv_need_try_all_stripes(lsm)) {
2571 struct lmv_oinfo *oinfo;
2574 if (stripe_index >= lsm->lsm_md_stripe_count)
2577 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2579 op_data->op_fid1 = oinfo->lmo_fid;
2580 op_data->op_mds = oinfo->lmo_mds;
2582 ptlrpc_req_finished(*request);
2585 goto try_next_stripe;
2588 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2592 /* Not cross-ref case, just get out of here. */
2593 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2596 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2597 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2599 /* This is a remote object, try remote MDT, Note: it may
2600 * try more than 1 time here, Considering following case
2601 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2602 * 1. Initially A does not know where remote1 is, it send
2603 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2604 * resend unlink RPC to MDT1 (retry 1st time).
2606 * 2. During the unlink RPC in flight,
2607 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2608 * and create new remote1, but on MDT0
2610 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2611 * /mnt/lustre, then lookup get fid of remote1, and find
2612 * it is remote dir again, and replay -EREMOTE again.
2614 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2616 * In theory, it might try unlimited time here, but it should
2617 * be very rare case.
2619 op_data->op_fid2 = body->mbo_fid1;
2620 ptlrpc_req_finished(*request);
2626 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2628 struct lmv_obd *lmv = &obd->u.lmv;
2631 case OBD_CLEANUP_EARLY:
2632 /* XXX: here should be calling obd_precleanup() down to
2636 case OBD_CLEANUP_EXPORTS:
2637 fld_client_debugfs_fini(&lmv->lmv_fld);
2638 lprocfs_obd_cleanup(obd);
2647 * Get by key a value associated with a LMV device.
2649 * Dispatch request to lower-layer devices as needed.
2651 * \param[in] env execution environment for this thread
2652 * \param[in] exp export for the LMV device
2653 * \param[in] keylen length of key identifier
2654 * \param[in] key identifier of key to get value for
2655 * \param[in] vallen size of \a val
2656 * \param[out] val pointer to storage location for value
2657 * \param[in] lsm optional striping metadata of object
2659 * \retval 0 on success
2660 * \retval negative negated errno on failure
2662 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2663 __u32 keylen, void *key, __u32 *vallen, void *val,
2664 struct lov_stripe_md *lsm)
2666 struct obd_device *obd;
2667 struct lmv_obd *lmv;
2670 obd = class_exp2obd(exp);
2672 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2673 exp->exp_handle.h_cookie);
2678 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2681 rc = lmv_check_connect(obd);
2685 LASSERT(*vallen == sizeof(__u32));
2686 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2687 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2690 * All tgts should be connected when this gets called.
2692 if (!tgt || !tgt->ltd_exp)
2695 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2700 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2701 KEY_IS(KEY_DEFAULT_EASIZE) ||
2702 KEY_IS(KEY_CONN_DATA)) {
2703 rc = lmv_check_connect(obd);
2708 * Forwarding this request to first MDS, it should know LOV
2711 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2713 if (!rc && KEY_IS(KEY_CONN_DATA))
2714 exp->exp_connect_data = *(struct obd_connect_data *)val;
2716 } else if (KEY_IS(KEY_TGT_COUNT)) {
2717 *((int *)val) = lmv->desc.ld_tgt_count;
2721 CDEBUG(D_IOCTL, "Invalid key\n");
2726 * Asynchronously set by key a value associated with a LMV device.
2728 * Dispatch request to lower-layer devices as needed.
2730 * \param[in] env execution environment for this thread
2731 * \param[in] exp export for the LMV device
2732 * \param[in] keylen length of key identifier
2733 * \param[in] key identifier of key to store value for
2734 * \param[in] vallen size of value to store
2735 * \param[in] val pointer to data to be stored
2736 * \param[in] set optional list of related ptlrpc requests
2738 * \retval 0 on success
2739 * \retval negative negated errno on failure
2741 static int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2742 u32 keylen, void *key, u32 vallen,
2743 void *val, struct ptlrpc_request_set *set)
2745 struct lmv_tgt_desc *tgt;
2746 struct obd_device *obd;
2747 struct lmv_obd *lmv;
2750 obd = class_exp2obd(exp);
2752 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2753 exp->exp_handle.h_cookie);
2758 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2759 KEY_IS(KEY_DEFAULT_EASIZE)) {
2762 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2765 if (!tgt || !tgt->ltd_exp)
2768 err = obd_set_info_async(env, tgt->ltd_exp,
2769 keylen, key, vallen, val, set);
2780 static int lmv_pack_md_v1(const struct lmv_stripe_md *lsm,
2781 struct lmv_mds_md_v1 *lmm1)
2786 lmm1->lmv_magic = cpu_to_le32(lsm->lsm_md_magic);
2787 lmm1->lmv_stripe_count = cpu_to_le32(lsm->lsm_md_stripe_count);
2788 lmm1->lmv_master_mdt_index = cpu_to_le32(lsm->lsm_md_master_mdt_index);
2789 lmm1->lmv_hash_type = cpu_to_le32(lsm->lsm_md_hash_type);
2790 cplen = strlcpy(lmm1->lmv_pool_name, lsm->lsm_md_pool_name,
2791 sizeof(lmm1->lmv_pool_name));
2792 if (cplen >= sizeof(lmm1->lmv_pool_name))
2795 for (i = 0; i < lsm->lsm_md_stripe_count; i++)
2796 fid_cpu_to_le(&lmm1->lmv_stripe_fids[i],
2797 &lsm->lsm_md_oinfo[i].lmo_fid);
2802 lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
2805 int lmm_size = 0, rc = 0;
2806 bool allocated = false;
2811 if (*lmmp && !lsm) {
2814 stripe_cnt = lmv_mds_md_stripe_count_get(*lmmp);
2815 lmm_size = lmv_mds_md_size(stripe_cnt,
2816 le32_to_cpu((*lmmp)->lmv_magic));
2825 if (!*lmmp && !lsm) {
2826 lmm_size = lmv_mds_md_size(stripe_count, LMV_MAGIC);
2827 LASSERT(lmm_size > 0);
2828 *lmmp = libcfs_kvzalloc(lmm_size, GFP_NOFS);
2831 lmv_mds_md_stripe_count_set(*lmmp, stripe_count);
2832 (*lmmp)->lmv_magic = cpu_to_le32(LMV_MAGIC);
2838 lmm_size = lmv_mds_md_size(lsm->lsm_md_stripe_count,
2841 *lmmp = libcfs_kvzalloc(lmm_size, GFP_NOFS);
2847 switch (lsm->lsm_md_magic) {
2849 rc = lmv_pack_md_v1(lsm, &(*lmmp)->lmv_md_v1);
2856 if (rc && allocated) {
2864 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2865 const struct lmv_mds_md_v1 *lmm1)
2867 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2873 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2874 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2875 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2876 if (OBD_FAIL_CHECK(OBD_FAIL_UNKNOWN_LMV_STRIPE))
2877 lsm->lsm_md_hash_type = LMV_HASH_TYPE_UNKNOWN;
2879 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2880 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2881 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2882 sizeof(lsm->lsm_md_pool_name));
2884 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2887 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d layout_version %d\n",
2888 lsm->lsm_md_stripe_count, lsm->lsm_md_master_mdt_index,
2889 lsm->lsm_md_hash_type, lsm->lsm_md_layout_version);
2891 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2892 for (i = 0; i < stripe_count; i++) {
2893 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2894 &lmm1->lmv_stripe_fids[i]);
2895 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2896 &lsm->lsm_md_oinfo[i].lmo_mds);
2899 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2900 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2906 int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2907 const union lmv_mds_md *lmm, int stripe_count)
2909 struct lmv_stripe_md *lsm;
2910 bool allocated = false;
2920 for (i = 1; i < lsm->lsm_md_stripe_count; i++) {
2922 * For migrating inode, the master stripe and master
2923 * object will be the same, so do not need iput, see
2926 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2927 !i) && lsm->lsm_md_oinfo[i].lmo_root)
2928 iput(lsm->lsm_md_oinfo[i].lmo_root);
2938 lsm_size = lmv_stripe_md_size(stripe_count);
2939 lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS);
2942 lsm->lsm_md_stripe_count = stripe_count;
2947 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
2951 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2952 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2953 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2954 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2959 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2960 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2963 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2964 * stripecount should be 0 then.
2966 lsm_size = lmv_stripe_md_size(0);
2969 lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS);
2976 switch (le32_to_cpu(lmm->lmv_magic)) {
2978 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2981 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2982 le32_to_cpu(lmm->lmv_magic));
2987 if (rc && allocated) {
2994 EXPORT_SYMBOL(lmv_unpack_md);
2996 static int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2997 struct lov_mds_md *lmm, int disk_len)
2999 return lmv_unpack_md(exp, (struct lmv_stripe_md **)lsmp,
3000 (union lmv_mds_md *)lmm, disk_len);
3003 static int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
3004 struct lov_stripe_md *lsm)
3006 const struct lmv_stripe_md *lmv = (struct lmv_stripe_md *)lsm;
3007 struct obd_device *obd = exp->exp_obd;
3008 struct lmv_obd *lmv_obd = &obd->u.lmv;
3013 stripe_count = lmv->lsm_md_stripe_count;
3015 stripe_count = lmv_obd->desc.ld_tgt_count;
3017 return lmv_mds_md_size(stripe_count, LMV_MAGIC_V1);
3020 return lmv_pack_md((union lmv_mds_md **)lmmp, lmv, 0);
3023 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
3024 ldlm_policy_data_t *policy, enum ldlm_mode mode,
3025 enum ldlm_cancel_flags flags, void *opaque)
3027 struct obd_device *obd = exp->exp_obd;
3028 struct lmv_obd *lmv = &obd->u.lmv;
3035 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3036 struct lmv_tgt_desc *tgt = lmv->tgts[i];
3038 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
3041 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
3049 static int lmv_set_lock_data(struct obd_export *exp,
3050 const struct lustre_handle *lockh,
3051 void *data, __u64 *bits)
3053 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3054 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3057 if (!tgt || !tgt->ltd_exp)
3060 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
3064 static enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
3065 const struct lu_fid *fid,
3066 enum ldlm_type type,
3067 ldlm_policy_data_t *policy,
3068 enum ldlm_mode mode,
3069 struct lustre_handle *lockh)
3071 struct obd_device *obd = exp->exp_obd;
3072 struct lmv_obd *lmv = &obd->u.lmv;
3077 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
3080 * With DNE every object can have two locks in different namespaces:
3081 * lookup lock in space of MDT storing direntry and update/open lock in
3082 * space of MDT storing inode. Try the MDT that the FID maps to first,
3083 * since this can be easily found, and only try others if that fails.
3085 for (i = 0, tgt = lmv_find_target_index(lmv, fid);
3086 i < lmv->desc.ld_tgt_count;
3087 i++, tgt = (tgt + 1) % lmv->desc.ld_tgt_count) {
3089 CDEBUG(D_HA, "%s: "DFID" is inaccessible: rc = %d\n",
3090 obd->obd_name, PFID(fid), tgt);
3094 if (!lmv->tgts[tgt] || !lmv->tgts[tgt]->ltd_exp ||
3095 !lmv->tgts[tgt]->ltd_active)
3098 rc = md_lock_match(lmv->tgts[tgt]->ltd_exp, flags, fid,
3099 type, policy, mode, lockh);
3107 static int lmv_get_lustre_md(struct obd_export *exp,
3108 struct ptlrpc_request *req,
3109 struct obd_export *dt_exp,
3110 struct obd_export *md_exp,
3111 struct lustre_md *md)
3113 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3114 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3116 if (!tgt || !tgt->ltd_exp)
3118 return md_get_lustre_md(tgt->ltd_exp, req, dt_exp, md_exp, md);
3121 static int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
3123 struct obd_device *obd = exp->exp_obd;
3124 struct lmv_obd *lmv = &obd->u.lmv;
3125 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3128 lmv_free_memmd(md->lmv);
3131 if (!tgt || !tgt->ltd_exp)
3133 return md_free_lustre_md(tgt->ltd_exp, md);
3136 static int lmv_set_open_replay_data(struct obd_export *exp,
3137 struct obd_client_handle *och,
3138 struct lookup_intent *it)
3140 struct obd_device *obd = exp->exp_obd;
3141 struct lmv_obd *lmv = &obd->u.lmv;
3142 struct lmv_tgt_desc *tgt;
3144 tgt = lmv_find_target(lmv, &och->och_fid);
3146 return PTR_ERR(tgt);
3148 return md_set_open_replay_data(tgt->ltd_exp, och, it);
3151 static int lmv_clear_open_replay_data(struct obd_export *exp,
3152 struct obd_client_handle *och)
3154 struct obd_device *obd = exp->exp_obd;
3155 struct lmv_obd *lmv = &obd->u.lmv;
3156 struct lmv_tgt_desc *tgt;
3158 tgt = lmv_find_target(lmv, &och->och_fid);
3160 return PTR_ERR(tgt);
3162 return md_clear_open_replay_data(tgt->ltd_exp, och);
3165 static int lmv_intent_getattr_async(struct obd_export *exp,
3166 struct md_enqueue_info *minfo,
3167 struct ldlm_enqueue_info *einfo)
3169 struct md_op_data *op_data = &minfo->mi_data;
3170 struct obd_device *obd = exp->exp_obd;
3171 struct lmv_obd *lmv = &obd->u.lmv;
3172 struct lmv_tgt_desc *tgt = NULL;
3175 rc = lmv_check_connect(obd);
3179 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3181 return PTR_ERR(tgt);
3183 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
3187 static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3188 struct lu_fid *fid, __u64 *bits)
3190 struct obd_device *obd = exp->exp_obd;
3191 struct lmv_obd *lmv = &obd->u.lmv;
3192 struct lmv_tgt_desc *tgt;
3195 rc = lmv_check_connect(obd);
3199 tgt = lmv_find_target(lmv, fid);
3201 return PTR_ERR(tgt);
3203 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3208 lmv_get_fid_from_lsm(struct obd_export *exp,
3209 const struct lmv_stripe_md *lsm,
3210 const char *name, int namelen, struct lu_fid *fid)
3212 const struct lmv_oinfo *oinfo;
3215 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
3217 return PTR_ERR(oinfo);
3219 *fid = oinfo->lmo_fid;
3225 * For lmv, only need to send request to master MDT, and the master MDT will
3226 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3227 * we directly fetch data from the slave MDTs.
3229 static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3230 struct obd_quotactl *oqctl)
3232 struct obd_device *obd = class_exp2obd(exp);
3233 struct lmv_obd *lmv = &obd->u.lmv;
3234 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3236 __u64 curspace = 0, curinodes = 0;
3239 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active ||
3240 !lmv->desc.ld_tgt_count) {
3241 CERROR("master lmv inactive\n");
3245 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3246 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3250 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3255 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
3258 err = obd_quotactl(tgt->ltd_exp, oqctl);
3260 CERROR("getquota on mdt %d failed. %d\n", i, err);
3264 curspace += oqctl->qc_dqblk.dqb_curspace;
3265 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3268 oqctl->qc_dqblk.dqb_curspace = curspace;
3269 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3274 static int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
3275 struct obd_quotactl *oqctl)
3277 struct obd_device *obd = class_exp2obd(exp);
3278 struct lmv_obd *lmv = &obd->u.lmv;
3279 struct lmv_tgt_desc *tgt;
3283 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3287 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active) {
3288 CERROR("lmv idx %d inactive\n", i);
3292 err = obd_quotacheck(tgt->ltd_exp, oqctl);
3300 static int lmv_merge_attr(struct obd_export *exp,
3301 const struct lmv_stripe_md *lsm,
3302 struct cl_attr *attr,
3303 ldlm_blocking_callback cb_blocking)
3307 rc = lmv_revalidate_slaves(exp, lsm, cb_blocking, 0);
3311 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3312 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3314 CDEBUG(D_INFO, ""DFID" size %llu, blocks %llu nlink %u, atime %lu ctime %lu, mtime %lu.\n",
3315 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3316 i_size_read(inode), (unsigned long long)inode->i_blocks,
3317 inode->i_nlink, LTIME_S(inode->i_atime),
3318 LTIME_S(inode->i_ctime), LTIME_S(inode->i_mtime));
3320 /* for slave stripe, it needs to subtract nlink for . and .. */
3322 attr->cat_nlink += inode->i_nlink - 2;
3324 attr->cat_nlink = inode->i_nlink;
3326 attr->cat_size += i_size_read(inode);
3327 attr->cat_blocks += inode->i_blocks;
3329 if (attr->cat_atime < LTIME_S(inode->i_atime))
3330 attr->cat_atime = LTIME_S(inode->i_atime);
3332 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3333 attr->cat_ctime = LTIME_S(inode->i_ctime);
3335 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3336 attr->cat_mtime = LTIME_S(inode->i_mtime);
3341 static struct obd_ops lmv_obd_ops = {
3342 .owner = THIS_MODULE,
3344 .cleanup = lmv_cleanup,
3345 .precleanup = lmv_precleanup,
3346 .process_config = lmv_process_config,
3347 .connect = lmv_connect,
3348 .disconnect = lmv_disconnect,
3349 .statfs = lmv_statfs,
3350 .get_info = lmv_get_info,
3351 .set_info_async = lmv_set_info_async,
3352 .packmd = lmv_packmd,
3353 .unpackmd = lmv_unpackmd,
3354 .notify = lmv_notify,
3355 .get_uuid = lmv_get_uuid,
3356 .iocontrol = lmv_iocontrol,
3357 .quotacheck = lmv_quotacheck,
3358 .quotactl = lmv_quotactl
3361 static struct md_ops lmv_md_ops = {
3362 .getstatus = lmv_getstatus,
3363 .null_inode = lmv_null_inode,
3365 .create = lmv_create,
3366 .done_writing = lmv_done_writing,
3367 .enqueue = lmv_enqueue,
3368 .getattr = lmv_getattr,
3369 .getxattr = lmv_getxattr,
3370 .getattr_name = lmv_getattr_name,
3371 .intent_lock = lmv_intent_lock,
3373 .rename = lmv_rename,
3374 .setattr = lmv_setattr,
3375 .setxattr = lmv_setxattr,
3377 .read_page = lmv_read_page,
3378 .unlink = lmv_unlink,
3379 .init_ea_size = lmv_init_ea_size,
3380 .cancel_unused = lmv_cancel_unused,
3381 .set_lock_data = lmv_set_lock_data,
3382 .lock_match = lmv_lock_match,
3383 .get_lustre_md = lmv_get_lustre_md,
3384 .free_lustre_md = lmv_free_lustre_md,
3385 .merge_attr = lmv_merge_attr,
3386 .set_open_replay_data = lmv_set_open_replay_data,
3387 .clear_open_replay_data = lmv_clear_open_replay_data,
3388 .intent_getattr_async = lmv_intent_getattr_async,
3389 .revalidate_lock = lmv_revalidate_lock,
3390 .get_fid_from_lsm = lmv_get_fid_from_lsm,
3393 static int __init lmv_init(void)
3395 struct lprocfs_static_vars lvars;
3398 lprocfs_lmv_init_vars(&lvars);
3400 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
3401 LUSTRE_LMV_NAME, NULL);
3405 static void lmv_exit(void)
3407 class_unregister_type(LUSTRE_LMV_NAME);
3410 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3411 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
3412 MODULE_VERSION(LUSTRE_VERSION_STRING);
3413 MODULE_LICENSE("GPL");
3415 module_init(lmv_init);
3416 module_exit(lmv_exit);