1d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao/* 2d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * GPL HEADER START 3d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * 4d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * 6d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * This program is free software; you can redistribute it and/or modify 7d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * it under the terms of the GNU General Public License version 2 only, 8d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * as published by the Free Software Foundation. 9d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * 10d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * This program is distributed in the hope that it will be useful, but 11d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * WITHOUT ANY WARRANTY; without even the implied warranty of 12d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * General Public License version 2 for more details (a copy is included 14d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * in the LICENSE file that accompanied this code). 15d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * 16d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * You should have received a copy of the GNU General Public License 17d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * version 2 along with this program; If not, see 18d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 19d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * 20d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 21d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * CA 95054 USA or visit www.sun.com if you need additional information or 22d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * have any questions. 23d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * 24d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * GPL HEADER END 25d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao */ 26d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao/* 27d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. 28d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * Use is subject to license terms. 29d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * 30d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * Copyright (c) 2011, 2012, Intel Corporation. 31d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao */ 32d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao/* 33d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * This file is part of Lustre, http://www.lustre.org/ 34d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * Lustre is a trademark of Sun Microsystems, Inc. 35d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao */ 36d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 37d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao#define DEBUG_SUBSYSTEM S_MDC 38d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 39d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao# include <linux/module.h> 40d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao# include <linux/kernel.h> 41d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 4205932307435e66978f82c16fb479fd43d0f69311Greg Kroah-Hartman#include "../include/obd_class.h" 43d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao#include "mdc_internal.h" 4405932307435e66978f82c16fb479fd43d0f69311Greg Kroah-Hartman#include "../include/lustre_fid.h" 45d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 46d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao/* mdc_setattr does its own semaphore handling */ 47d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Taostatic int mdc_reint(struct ptlrpc_request *request, 48d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct mdc_rpc_lock *rpc_lock, 49d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int level) 50d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao{ 51d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int rc; 52d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 53d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao request->rq_send_state = level; 54d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 55d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_get_rpc_lock(rpc_lock, NULL); 56d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = ptlrpc_queue_wait(request); 57d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_put_rpc_lock(rpc_lock, NULL); 58d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc) 59d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao CDEBUG(D_INFO, "error in handling %d\n", rc); 6022403d9eae75ae0f86c92b9f0a8bda1aa2e069e3Sun Wang else if (!req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY)) 61d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = -EPROTO; 6222403d9eae75ae0f86c92b9f0a8bda1aa2e069e3Sun Wang 63d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao return rc; 64d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao} 65d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 66d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao/* Find and cancel locally locks matched by inode @bits & @mode in the resource 67d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * found by @fid. Found locks are added into @cancel list. Returns the amount of 68d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * locks added to @cancels list. */ 69e93a3082fc30dd648989f0986e482e0c914a502cAndrew Perepechkoint mdc_resource_get_unused(struct obd_export *exp, const struct lu_fid *fid, 70d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct list_head *cancels, ldlm_mode_t mode, 71d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao __u64 bits) 72d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao{ 73d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ldlm_namespace *ns = exp->exp_obd->obd_namespace; 74301af9068dd1b72ee80d0321b67eb5d76e08b3c0Srikrishan Malik ldlm_policy_data_t policy = {}; 75d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ldlm_res_id res_id; 76d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ldlm_resource *res; 77d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int count; 78d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 79d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* Return, i.e. cancel nothing, only if ELC is supported (flag in 80d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * export) but disabled through procfs (flag in NS). 81d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * 82d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * This distinguishes from a case when ELC is not supported originally, 83d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * when we still want to cancel locks in advance and just cancel them 84d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * locally, without sending any RPC. */ 85d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (exp_connect_cancelset(exp) && !ns_connect_cancelset(ns)) 860a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return 0; 87d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 88d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao fid_build_reg_res_name(fid, &res_id); 89d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao res = ldlm_resource_get(exp->exp_obd->obd_namespace, 90d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao NULL, &res_id, 0, 0); 91d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (res == NULL) 920a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return 0; 93d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LDLM_RESOURCE_ADDREF(res); 94d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* Initialize ibits lock policy. */ 95d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao policy.l_inodebits.bits = bits; 96d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count = ldlm_cancel_resource_local(res, cancels, &policy, 97d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mode, 0, 0, NULL); 98d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LDLM_RESOURCE_DELREF(res); 99d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ldlm_resource_putref(res); 1000a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return count; 101d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao} 102d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 103d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Taoint mdc_setattr(struct obd_export *exp, struct md_op_data *op_data, 104d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao void *ea, int ealen, void *ea2, int ea2len, 105d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request **request, struct md_open_data **mod) 106d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao{ 107d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LIST_HEAD(cancels); 108d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request *req; 109d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct mdc_rpc_lock *rpc_lock; 110d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct obd_device *obd = exp->exp_obd; 111d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int count = 0, rc; 112d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao __u64 bits; 113d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 114d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LASSERT(op_data != NULL); 115d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 116d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao bits = MDS_INODELOCK_UPDATE; 117d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (op_data->op_attr.ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) 118d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao bits |= MDS_INODELOCK_LOOKUP; 119d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID1) && 120d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid1)) && 121d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao !OBD_FAIL_CHECK(OBD_FAIL_LDLM_BL_CALLBACK_NET)) 122d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count = mdc_resource_get_unused(exp, &op_data->op_fid1, 123d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, bits); 124d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req = ptlrpc_request_alloc(class_exp2cliimp(exp), 125d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &RQF_MDS_REINT_SETATTR); 126d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (req == NULL) { 127d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ldlm_lock_list_put(&cancels, l_bl_ast, count); 1280a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return -ENOMEM; 129d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 130d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); 131d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & (MF_SOM_CHANGE | MF_EPOCH_OPEN)) == 0) 132d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_MDT_EPOCH, RCL_CLIENT, 133d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 0); 134d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT, ealen); 135d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_CLIENT, 136d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ea2len); 137d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 138d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count); 139d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc) { 140d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_free(req); 1410a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 142d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 143d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 144d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rpc_lock = obd->u.cli.cl_rpc_lock; 145d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 146d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (op_data->op_attr.ia_valid & (ATTR_MTIME | ATTR_CTIME)) 147d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao CDEBUG(D_INODE, "setting mtime "CFS_TIME_T 148d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ", ctime "CFS_TIME_T"\n", 149d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LTIME_S(op_data->op_attr.ia_mtime), 150d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LTIME_S(op_data->op_attr.ia_ctime)); 151d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_setattr_pack(req, op_data, ea, ealen, ea2, ea2len); 152d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 153d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_set_replen(req); 154d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (mod && (op_data->op_flags & MF_EPOCH_OPEN) && 1551a4cd3e9d53d786367c30e3a2a0864b69d370b3cSrikrishan Malik req->rq_import->imp_replayable) { 156d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LASSERT(*mod == NULL); 157d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 158d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao *mod = obd_mod_alloc(); 159d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (*mod == NULL) { 160ee990b3368d678611fd4d28ae702a3c24ea1d76cSrikrishan Malik DEBUG_REQ(D_ERROR, req, "Can't allocate md_open_data"); 161d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } else { 162d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req->rq_replay = 1; 163d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req->rq_cb_data = *mod; 164d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (*mod)->mod_open_req = req; 165d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req->rq_commit_cb = mdc_commit_open; 16663d42578d5797fb6aa77d44d33d4d6f3ed330b40Hongchao Zhang (*mod)->mod_is_create = true; 167d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /** 168d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * Take an extra reference on \var mod, it protects \var 169d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * mod from being freed on eviction (commit callback is 170d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * called despite rq_replay flag). 171d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * Will be put on mdc_done_writing(). 172d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao */ 173d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao obd_mod_get(*mod); 174d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 175d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 176d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 177d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_reint(req, rpc_lock, LUSTRE_IMP_FULL); 178d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 179d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* Save the obtained info in the original RPC for the replay case. */ 180d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc == 0 && (op_data->op_flags & MF_EPOCH_OPEN)) { 181d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct mdt_ioepoch *epoch; 182d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct mdt_body *body; 183d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 184d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH); 185d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); 186d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LASSERT(epoch != NULL); 187d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LASSERT(body != NULL); 188d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao epoch->handle = body->handle; 189d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao epoch->ioepoch = body->ioepoch; 190d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req->rq_replay_cb = mdc_replay_open; 191d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /** bug 3633, open may be committed and estale answer is not error */ 192d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } else if (rc == -ESTALE && (op_data->op_flags & MF_SOM_CHANGE)) { 193d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = 0; 194d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } else if (rc == -ERESTARTSYS) { 195d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = 0; 196d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 197d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao *request = req; 198d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc && req->rq_commit_cb) { 199d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* Put an extra reference on \var mod on error case. */ 200ba0e1b53726d233360960e7ae7f65b3be32042a9Dmitry Eremin if (mod != NULL && *mod != NULL) 201ba0e1b53726d233360960e7ae7f65b3be32042a9Dmitry Eremin obd_mod_put(*mod); 202d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req->rq_commit_cb(req); 203d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 2040a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 205d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao} 206d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 207d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Taoint mdc_create(struct obd_export *exp, struct md_op_data *op_data, 208d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao const void *data, int datalen, int mode, __u32 uid, __u32 gid, 209d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao cfs_cap_t cap_effective, __u64 rdev, 210d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request **request) 211d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao{ 212d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request *req; 213d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int level, rc; 214d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int count, resends = 0; 215d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct obd_import *import = exp->exp_obd->u.cli.cl_import; 216d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int generation = import->imp_generation; 217d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LIST_HEAD(cancels); 218d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 219d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* For case if upper layer did not alloc fid, do it now. */ 220d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (!fid_is_sane(&op_data->op_fid2)) { 221d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* 222d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * mdc_fid_alloc() may return errno 1 in case of switch to new 223d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * sequence, handle this. 224d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao */ 225d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_fid_alloc(exp, &op_data->op_fid2, op_data); 226d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc < 0) { 227d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao CERROR("Can't alloc new fid, rc %d\n", rc); 2280a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 229d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 230d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 231d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 232d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Taorebuild: 233d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count = 0; 234d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID1) && 235d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid1))) 236d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count = mdc_resource_get_unused(exp, &op_data->op_fid1, 237d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 238d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_UPDATE); 239d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 240d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req = ptlrpc_request_alloc(class_exp2cliimp(exp), 241d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &RQF_MDS_REINT_CREATE_RMT_ACL); 242d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (req == NULL) { 243d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ldlm_lock_list_put(&cancels, l_bl_ast, count); 2440a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return -ENOMEM; 245d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 246d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); 247d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, 248d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao op_data->op_namelen + 1); 249d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT, 250d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao data && datalen ? datalen : 0); 251d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 252d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count); 253d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc) { 254d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_free(req); 2550a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 256d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 257d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 258d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* 259d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * mdc_create_pack() fills msg->bufs[1] with name and msg->bufs[2] with 260d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * tgt, for symlinks or lov MD data. 261d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao */ 262d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_create_pack(req, op_data, data, datalen, mode, uid, 263d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao gid, cap_effective, rdev); 264d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 265d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_set_replen(req); 266d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 267d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* ask ptlrpc not to resend on EINPROGRESS since we have our own retry 268d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * logic here */ 269d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req->rq_no_retry_einprogress = 1; 270d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 271d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (resends) { 272d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req->rq_generation_set = 1; 273d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req->rq_import_generation = generation; 2747264b8a5db30b717b39394234fd3bb7dabdbda92Greg Kroah-Hartman req->rq_sent = get_seconds() + resends; 275d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 276d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao level = LUSTRE_IMP_FULL; 277d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao resend: 278d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_reint(req, exp->exp_obd->u.cli.cl_rpc_lock, level); 279d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 280d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* Resend if we were told to. */ 281d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc == -ERESTARTSYS) { 282d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao level = LUSTRE_IMP_RECOVER; 283d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao goto resend; 284d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } else if (rc == -EINPROGRESS) { 285d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao /* Retry create infinitely until succeed or get other 286d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao * error code. */ 287d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_req_finished(req); 288d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao resends++; 289d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 290d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao CDEBUG(D_HA, "%s: resend:%d create on "DFID"/"DFID"\n", 291d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao exp->exp_obd->obd_name, resends, 292d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao PFID(&op_data->op_fid1), PFID(&op_data->op_fid2)); 293d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 294d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (generation == import->imp_generation) { 295d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao goto rebuild; 296d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } else { 297d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao CDEBUG(D_HA, "resend cross eviction\n"); 2980a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return -EIO; 299d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 300d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } else if (rc == 0) { 301d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct mdt_body *body; 302d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct lustre_capa *capa; 303d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 304d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); 305d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LASSERT(body); 306d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (body->valid & OBD_MD_FLMDSCAPA) { 307d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao capa = req_capsule_server_get(&req->rq_pill, 308d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &RMF_CAPA1); 309d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (capa == NULL) 310d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = -EPROTO; 311d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 312d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 313d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 314d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao *request = req; 3150a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 316d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao} 317d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 318d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Taoint mdc_unlink(struct obd_export *exp, struct md_op_data *op_data, 319d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request **request) 320d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao{ 321d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LIST_HEAD(cancels); 322d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct obd_device *obd = class_exp2obd(exp); 323d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request *req = *request; 324d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int count = 0, rc; 325d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 326d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LASSERT(req == NULL); 327d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 328d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID1) && 329d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid1)) && 330d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao !OBD_FAIL_CHECK(OBD_FAIL_LDLM_BL_CALLBACK_NET)) 331d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count = mdc_resource_get_unused(exp, &op_data->op_fid1, 332d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 333d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_UPDATE); 334d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID3) && 335d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid3)) && 336d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao !OBD_FAIL_CHECK(OBD_FAIL_LDLM_BL_CALLBACK_NET)) 337d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count += mdc_resource_get_unused(exp, &op_data->op_fid3, 338d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 339d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_FULL); 340d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req = ptlrpc_request_alloc(class_exp2cliimp(exp), 341d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &RQF_MDS_REINT_UNLINK); 342d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (req == NULL) { 343d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ldlm_lock_list_put(&cancels, l_bl_ast, count); 3440a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return -ENOMEM; 345d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 346d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); 347d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, 348d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao op_data->op_namelen + 1); 349d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 350d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count); 351d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc) { 352d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_free(req); 3530a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 354d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 355d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 356d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_unlink_pack(req, op_data); 357d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 358d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, 35944779340c6dcb8c858955c02b3aeef7d6b28a684Brian Behlendorf obd->u.cli.cl_default_mds_easize); 360d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER, 36144779340c6dcb8c858955c02b3aeef7d6b28a684Brian Behlendorf obd->u.cli.cl_default_mds_cookiesize); 362d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_set_replen(req); 363d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 364d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao *request = req; 365d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 366d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL); 367d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc == -ERESTARTSYS) 368d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = 0; 3690a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 370d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao} 371d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 372d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Taoint mdc_link(struct obd_export *exp, struct md_op_data *op_data, 373d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request **request) 374d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao{ 375d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LIST_HEAD(cancels); 376d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct obd_device *obd = exp->exp_obd; 377d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request *req; 378d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int count = 0, rc; 379d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 380d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID2) && 381d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid2))) 382d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count = mdc_resource_get_unused(exp, &op_data->op_fid2, 383d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 384d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_UPDATE); 385d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID1) && 386d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid1))) 387d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count += mdc_resource_get_unused(exp, &op_data->op_fid1, 388d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 389d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_UPDATE); 390d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 391d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_REINT_LINK); 392d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (req == NULL) { 393d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ldlm_lock_list_put(&cancels, l_bl_ast, count); 3940a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return -ENOMEM; 395d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 396d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); 397d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2); 398d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, 399d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao op_data->op_namelen + 1); 400d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 401d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count); 402d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc) { 403d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_free(req); 4040a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 405d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 406d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 407d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_link_pack(req, op_data); 408d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_set_replen(req); 409d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 410d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL); 411d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao *request = req; 412d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc == -ERESTARTSYS) 413d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = 0; 414d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 4150a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 416d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao} 417d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 418d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Taoint mdc_rename(struct obd_export *exp, struct md_op_data *op_data, 419d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao const char *old, int oldlen, const char *new, int newlen, 420d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request **request) 421d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao{ 422d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao LIST_HEAD(cancels); 423d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct obd_device *obd = exp->exp_obd; 424d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao struct ptlrpc_request *req; 425d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao int count = 0, rc; 426d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 427d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID1) && 428d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid1))) 429d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count = mdc_resource_get_unused(exp, &op_data->op_fid1, 430d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 431d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_UPDATE); 432d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID2) && 433d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid2))) 434d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count += mdc_resource_get_unused(exp, &op_data->op_fid2, 435d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 436d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_UPDATE); 437d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID3) && 438d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid3))) 439d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count += mdc_resource_get_unused(exp, &op_data->op_fid3, 440d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 441d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_LOOKUP); 442d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if ((op_data->op_flags & MF_MDC_CANCEL_FID4) && 443d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao (fid_is_sane(&op_data->op_fid4))) 444d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao count += mdc_resource_get_unused(exp, &op_data->op_fid4, 445d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &cancels, LCK_EX, 446d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao MDS_INODELOCK_FULL); 447d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 448d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req = ptlrpc_request_alloc(class_exp2cliimp(exp), 449d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao &RQF_MDS_REINT_RENAME); 450d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (req == NULL) { 451d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ldlm_lock_list_put(&cancels, l_bl_ast, count); 4520a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return -ENOMEM; 453d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 454d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 455d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); 456d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2); 457d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, oldlen + 1); 458d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_SYMTGT, RCL_CLIENT, newlen+1); 459d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 460d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count); 461d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc) { 462d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_free(req); 4630a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 464d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao } 465d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 466d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (exp_connect_cancelset(exp) && req) 467d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ldlm_cli_cancel_list(&cancels, count, req, 0); 468d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 469d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao mdc_rename_pack(req, op_data, old, oldlen, new, newlen); 470d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 471d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, 47244779340c6dcb8c858955c02b3aeef7d6b28a684Brian Behlendorf obd->u.cli.cl_default_mds_easize); 473d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER, 47444779340c6dcb8c858955c02b3aeef7d6b28a684Brian Behlendorf obd->u.cli.cl_default_mds_cookiesize); 475d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao ptlrpc_request_set_replen(req); 476d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 477d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL); 478d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao *request = req; 479d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao if (rc == -ERESTARTSYS) 480d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao rc = 0; 481d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao 4820a3bdb00710bf253ba8ba8f645645f22297c7a04Greg Kroah-Hartman return rc; 483d7e09d0397e84eefbabfd9cb353221f3c6448d83Peng Tao} 484