Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1 | /* |
| 2 | * GPL HEADER START |
| 3 | * |
| 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | * |
| 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. |
| 9 | * |
| 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). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * version 2 along with this program; If not, see |
| 18 | * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf |
| 19 | * |
| 20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 21 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 22 | * have any questions. |
| 23 | * |
| 24 | * GPL HEADER END |
| 25 | */ |
| 26 | /* |
| 27 | * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
| 28 | * Use is subject to license terms. |
| 29 | * |
| 30 | * Copyright (c) 2011, 2012, Intel Corporation. |
| 31 | */ |
| 32 | /* |
| 33 | * This file is part of Lustre, http://www.lustre.org/ |
| 34 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 35 | */ |
| 36 | |
| 37 | #define DEBUG_SUBSYSTEM S_MDC |
| 38 | |
| 39 | # include <linux/module.h> |
| 40 | # include <linux/pagemap.h> |
| 41 | # include <linux/miscdevice.h> |
| 42 | # include <linux/init.h> |
| 43 | # include <linux/utsname.h> |
| 44 | |
| 45 | #include <lustre_acl.h> |
| 46 | #include <obd_class.h> |
| 47 | #include <lustre_fid.h> |
| 48 | #include <lprocfs_status.h> |
| 49 | #include <lustre_param.h> |
| 50 | #include <lustre_log.h> |
| 51 | |
| 52 | #include "mdc_internal.h" |
| 53 | |
| 54 | #define REQUEST_MINOR 244 |
| 55 | |
| 56 | struct mdc_renew_capa_args { |
| 57 | struct obd_capa *ra_oc; |
| 58 | renew_capa_cb_t ra_cb; |
| 59 | }; |
| 60 | |
| 61 | static int mdc_cleanup(struct obd_device *obd); |
| 62 | |
| 63 | int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req, |
| 64 | const struct req_msg_field *field, struct obd_capa **oc) |
| 65 | { |
| 66 | struct lustre_capa *capa; |
| 67 | struct obd_capa *c; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 68 | |
| 69 | /* swabbed already in mdc_enqueue */ |
| 70 | capa = req_capsule_server_get(&req->rq_pill, field); |
| 71 | if (capa == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 72 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 73 | |
| 74 | c = alloc_capa(CAPA_SITE_CLIENT); |
| 75 | if (IS_ERR(c)) { |
| 76 | CDEBUG(D_INFO, "alloc capa failed!\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 77 | return PTR_ERR(c); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 78 | } else { |
| 79 | c->c_capa = *capa; |
| 80 | *oc = c; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 81 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
| 85 | static inline int mdc_queue_wait(struct ptlrpc_request *req) |
| 86 | { |
| 87 | struct client_obd *cli = &req->rq_import->imp_obd->u.cli; |
| 88 | int rc; |
| 89 | |
| 90 | /* mdc_enter_request() ensures that this client has no more |
| 91 | * than cl_max_rpcs_in_flight RPCs simultaneously inf light |
| 92 | * against an MDT. */ |
| 93 | rc = mdc_enter_request(cli); |
| 94 | if (rc != 0) |
| 95 | return rc; |
| 96 | |
| 97 | rc = ptlrpc_queue_wait(req); |
| 98 | mdc_exit_request(cli); |
| 99 | |
| 100 | return rc; |
| 101 | } |
| 102 | |
| 103 | /* Helper that implements most of mdc_getstatus and signal_completed_replay. */ |
| 104 | /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */ |
| 105 | static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid, |
| 106 | struct obd_capa **pc, int level, int msg_flags) |
| 107 | { |
| 108 | struct ptlrpc_request *req; |
| 109 | struct mdt_body *body; |
| 110 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 111 | |
| 112 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS, |
| 113 | LUSTRE_MDS_VERSION, MDS_GETSTATUS); |
| 114 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 115 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 116 | |
| 117 | mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0); |
| 118 | lustre_msg_add_flags(req->rq_reqmsg, msg_flags); |
| 119 | req->rq_send_state = level; |
| 120 | |
| 121 | ptlrpc_request_set_replen(req); |
| 122 | |
| 123 | rc = ptlrpc_queue_wait(req); |
| 124 | if (rc) |
| 125 | GOTO(out, rc); |
| 126 | |
| 127 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); |
| 128 | if (body == NULL) |
| 129 | GOTO(out, rc = -EPROTO); |
| 130 | |
| 131 | if (body->valid & OBD_MD_FLMDSCAPA) { |
| 132 | rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc); |
| 133 | if (rc) |
| 134 | GOTO(out, rc); |
| 135 | } |
| 136 | |
| 137 | *rootfid = body->fid1; |
| 138 | CDEBUG(D_NET, |
| 139 | "root fid="DFID", last_committed="LPU64"\n", |
| 140 | PFID(rootfid), |
| 141 | lustre_msg_get_last_committed(req->rq_repmsg)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 142 | out: |
| 143 | ptlrpc_req_finished(req); |
| 144 | return rc; |
| 145 | } |
| 146 | |
| 147 | /* This should be mdc_get_info("rootfid") */ |
| 148 | int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid, |
| 149 | struct obd_capa **pc) |
| 150 | { |
| 151 | return send_getstatus(class_exp2cliimp(exp), rootfid, pc, |
| 152 | LUSTRE_IMP_FULL, 0); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | * This function now is known to always saying that it will receive 4 buffers |
| 157 | * from server. Even for cases when acl_size and md_size is zero, RPC header |
| 158 | * will contain 4 fields and RPC itself will contain zero size fields. This is |
| 159 | * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed |
| 160 | * and thus zero, it shrinks it, making zero size. The same story about |
| 161 | * md_size. And this is course of problem when client waits for smaller number |
| 162 | * of fields. This issue will be fixed later when client gets aware of RPC |
| 163 | * layouts. --umka |
| 164 | */ |
| 165 | static int mdc_getattr_common(struct obd_export *exp, |
| 166 | struct ptlrpc_request *req) |
| 167 | { |
| 168 | struct req_capsule *pill = &req->rq_pill; |
| 169 | struct mdt_body *body; |
| 170 | void *eadata; |
| 171 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 172 | |
| 173 | /* Request message already built. */ |
| 174 | rc = ptlrpc_queue_wait(req); |
| 175 | if (rc != 0) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 176 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 177 | |
| 178 | /* sanity check for the reply */ |
| 179 | body = req_capsule_server_get(pill, &RMF_MDT_BODY); |
| 180 | if (body == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 181 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 182 | |
| 183 | CDEBUG(D_NET, "mode: %o\n", body->mode); |
| 184 | |
| 185 | if (body->eadatasize != 0) { |
| 186 | mdc_update_max_ea_from_body(exp, body); |
| 187 | |
| 188 | eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD, |
| 189 | body->eadatasize); |
| 190 | if (eadata == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 191 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | if (body->valid & OBD_MD_FLRMTPERM) { |
| 195 | struct mdt_remote_perm *perm; |
| 196 | |
| 197 | LASSERT(client_is_remote(exp)); |
| 198 | perm = req_capsule_server_swab_get(pill, &RMF_ACL, |
| 199 | lustre_swab_mdt_remote_perm); |
| 200 | if (perm == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 201 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | if (body->valid & OBD_MD_FLMDSCAPA) { |
| 205 | struct lustre_capa *capa; |
| 206 | capa = req_capsule_server_get(pill, &RMF_CAPA1); |
| 207 | if (capa == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 208 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 209 | } |
| 210 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 211 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data, |
| 215 | struct ptlrpc_request **request) |
| 216 | { |
| 217 | struct ptlrpc_request *req; |
| 218 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 219 | |
| 220 | /* Single MDS without an LMV case */ |
| 221 | if (op_data->op_flags & MF_GET_MDT_IDX) { |
| 222 | op_data->op_mds = 0; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 223 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 224 | } |
| 225 | *request = NULL; |
| 226 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR); |
| 227 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 228 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 229 | |
| 230 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 231 | |
| 232 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR); |
| 233 | if (rc) { |
| 234 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 235 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1, |
| 239 | op_data->op_valid, op_data->op_mode, -1, 0); |
| 240 | |
| 241 | req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, |
| 242 | op_data->op_mode); |
| 243 | if (op_data->op_valid & OBD_MD_FLRMTPERM) { |
| 244 | LASSERT(client_is_remote(exp)); |
| 245 | req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER, |
| 246 | sizeof(struct mdt_remote_perm)); |
| 247 | } |
| 248 | ptlrpc_request_set_replen(req); |
| 249 | |
| 250 | rc = mdc_getattr_common(exp, req); |
| 251 | if (rc) |
| 252 | ptlrpc_req_finished(req); |
| 253 | else |
| 254 | *request = req; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 255 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data, |
| 259 | struct ptlrpc_request **request) |
| 260 | { |
| 261 | struct ptlrpc_request *req; |
| 262 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 263 | |
| 264 | *request = NULL; |
| 265 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), |
| 266 | &RQF_MDS_GETATTR_NAME); |
| 267 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 268 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 269 | |
| 270 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 271 | req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, |
| 272 | op_data->op_namelen + 1); |
| 273 | |
| 274 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME); |
| 275 | if (rc) { |
| 276 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 277 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1, |
| 281 | op_data->op_valid, op_data->op_mode, |
| 282 | op_data->op_suppgids[0], 0); |
| 283 | |
| 284 | if (op_data->op_name) { |
| 285 | char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME); |
| 286 | LASSERT(strnlen(op_data->op_name, op_data->op_namelen) == |
| 287 | op_data->op_namelen); |
| 288 | memcpy(name, op_data->op_name, op_data->op_namelen); |
| 289 | } |
| 290 | |
| 291 | req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, |
| 292 | op_data->op_mode); |
| 293 | ptlrpc_request_set_replen(req); |
| 294 | |
| 295 | rc = mdc_getattr_common(exp, req); |
| 296 | if (rc) |
| 297 | ptlrpc_req_finished(req); |
| 298 | else |
| 299 | *request = req; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 300 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static int mdc_is_subdir(struct obd_export *exp, |
| 304 | const struct lu_fid *pfid, |
| 305 | const struct lu_fid *cfid, |
| 306 | struct ptlrpc_request **request) |
| 307 | { |
| 308 | struct ptlrpc_request *req; |
| 309 | int rc; |
| 310 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 311 | *request = NULL; |
| 312 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), |
| 313 | &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION, |
| 314 | MDS_IS_SUBDIR); |
| 315 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 316 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 317 | |
| 318 | mdc_is_subdir_pack(req, pfid, cfid, 0); |
| 319 | ptlrpc_request_set_replen(req); |
| 320 | |
| 321 | rc = ptlrpc_queue_wait(req); |
| 322 | if (rc && rc != -EREMOTE) |
| 323 | ptlrpc_req_finished(req); |
| 324 | else |
| 325 | *request = req; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 326 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt, |
| 330 | const struct lu_fid *fid, |
| 331 | struct obd_capa *oc, int opcode, obd_valid valid, |
| 332 | const char *xattr_name, const char *input, |
| 333 | int input_size, int output_size, int flags, |
| 334 | __u32 suppgid, struct ptlrpc_request **request) |
| 335 | { |
| 336 | struct ptlrpc_request *req; |
| 337 | int xattr_namelen = 0; |
| 338 | char *tmp; |
| 339 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 340 | |
| 341 | *request = NULL; |
| 342 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt); |
| 343 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 344 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 345 | |
| 346 | mdc_set_capa_size(req, &RMF_CAPA1, oc); |
| 347 | if (xattr_name) { |
| 348 | xattr_namelen = strlen(xattr_name) + 1; |
| 349 | req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, |
| 350 | xattr_namelen); |
| 351 | } |
| 352 | if (input_size) { |
| 353 | LASSERT(input); |
| 354 | req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT, |
| 355 | input_size); |
| 356 | } |
| 357 | |
Andrew Perepechko | e93a308 | 2014-02-09 02:51:48 -0500 | [diff] [blame^] | 358 | /* Flush local XATTR locks to get rid of a possible cancel RPC */ |
| 359 | if (opcode == MDS_REINT && fid_is_sane(fid) && |
| 360 | exp->exp_connect_data.ocd_ibits_known & MDS_INODELOCK_XATTR) { |
| 361 | LIST_HEAD(cancels); |
| 362 | int count; |
| 363 | |
| 364 | /* Without that packing would fail */ |
| 365 | if (input_size == 0) |
| 366 | req_capsule_set_size(&req->rq_pill, &RMF_EADATA, |
| 367 | RCL_CLIENT, 0); |
| 368 | |
| 369 | count = mdc_resource_get_unused(exp, fid, |
| 370 | &cancels, LCK_EX, |
| 371 | MDS_INODELOCK_XATTR); |
| 372 | |
| 373 | rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count); |
| 374 | if (rc) { |
| 375 | ptlrpc_request_free(req); |
| 376 | return rc; |
| 377 | } |
| 378 | } else { |
| 379 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode); |
| 380 | if (rc) { |
| 381 | ptlrpc_request_free(req); |
| 382 | return rc; |
| 383 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | if (opcode == MDS_REINT) { |
| 387 | struct mdt_rec_setxattr *rec; |
| 388 | |
| 389 | CLASSERT(sizeof(struct mdt_rec_setxattr) == |
| 390 | sizeof(struct mdt_rec_reint)); |
| 391 | rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); |
| 392 | rec->sx_opcode = REINT_SETXATTR; |
Peng Tao | 4b1a25f | 2013-07-15 22:27:14 +0800 | [diff] [blame] | 393 | rec->sx_fsuid = from_kuid(&init_user_ns, current_fsuid()); |
| 394 | rec->sx_fsgid = from_kgid(&init_user_ns, current_fsgid()); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 395 | rec->sx_cap = cfs_curproc_cap_pack(); |
| 396 | rec->sx_suppgid1 = suppgid; |
| 397 | rec->sx_suppgid2 = -1; |
| 398 | rec->sx_fid = *fid; |
| 399 | rec->sx_valid = valid | OBD_MD_FLCTIME; |
| 400 | rec->sx_time = cfs_time_current_sec(); |
| 401 | rec->sx_size = output_size; |
| 402 | rec->sx_flags = flags; |
| 403 | |
| 404 | mdc_pack_capa(req, &RMF_CAPA1, oc); |
| 405 | } else { |
| 406 | mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags); |
| 407 | } |
| 408 | |
| 409 | if (xattr_name) { |
| 410 | tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME); |
| 411 | memcpy(tmp, xattr_name, xattr_namelen); |
| 412 | } |
| 413 | if (input_size) { |
| 414 | tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA); |
| 415 | memcpy(tmp, input, input_size); |
| 416 | } |
| 417 | |
| 418 | if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER)) |
| 419 | req_capsule_set_size(&req->rq_pill, &RMF_EADATA, |
| 420 | RCL_SERVER, output_size); |
| 421 | ptlrpc_request_set_replen(req); |
| 422 | |
| 423 | /* make rpc */ |
| 424 | if (opcode == MDS_REINT) |
| 425 | mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); |
| 426 | |
| 427 | rc = ptlrpc_queue_wait(req); |
| 428 | |
| 429 | if (opcode == MDS_REINT) |
| 430 | mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); |
| 431 | |
| 432 | if (rc) |
| 433 | ptlrpc_req_finished(req); |
| 434 | else |
| 435 | *request = req; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 436 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid, |
| 440 | struct obd_capa *oc, obd_valid valid, const char *xattr_name, |
| 441 | const char *input, int input_size, int output_size, |
| 442 | int flags, __u32 suppgid, struct ptlrpc_request **request) |
| 443 | { |
| 444 | return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR, |
| 445 | fid, oc, MDS_REINT, valid, xattr_name, |
| 446 | input, input_size, output_size, flags, |
| 447 | suppgid, request); |
| 448 | } |
| 449 | |
| 450 | int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid, |
| 451 | struct obd_capa *oc, obd_valid valid, const char *xattr_name, |
| 452 | const char *input, int input_size, int output_size, |
| 453 | int flags, struct ptlrpc_request **request) |
| 454 | { |
| 455 | return mdc_xattr_common(exp, &RQF_MDS_GETXATTR, |
| 456 | fid, oc, MDS_GETXATTR, valid, xattr_name, |
| 457 | input, input_size, output_size, flags, |
| 458 | -1, request); |
| 459 | } |
| 460 | |
| 461 | #ifdef CONFIG_FS_POSIX_ACL |
| 462 | static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md) |
| 463 | { |
| 464 | struct req_capsule *pill = &req->rq_pill; |
| 465 | struct mdt_body *body = md->body; |
| 466 | struct posix_acl *acl; |
| 467 | void *buf; |
| 468 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 469 | |
| 470 | if (!body->aclsize) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 471 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 472 | |
| 473 | buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize); |
| 474 | |
| 475 | if (!buf) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 476 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 477 | |
| 478 | acl = posix_acl_from_xattr(&init_user_ns, buf, body->aclsize); |
| 479 | if (IS_ERR(acl)) { |
| 480 | rc = PTR_ERR(acl); |
| 481 | CERROR("convert xattr to acl: %d\n", rc); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 482 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | rc = posix_acl_valid(acl); |
| 486 | if (rc) { |
| 487 | CERROR("validate acl: %d\n", rc); |
| 488 | posix_acl_release(acl); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 489 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | md->posix_acl = acl; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 493 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 494 | } |
| 495 | #else |
| 496 | #define mdc_unpack_acl(req, md) 0 |
| 497 | #endif |
| 498 | |
| 499 | int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req, |
| 500 | struct obd_export *dt_exp, struct obd_export *md_exp, |
| 501 | struct lustre_md *md) |
| 502 | { |
| 503 | struct req_capsule *pill = &req->rq_pill; |
| 504 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 505 | |
| 506 | LASSERT(md); |
| 507 | memset(md, 0, sizeof(*md)); |
| 508 | |
| 509 | md->body = req_capsule_server_get(pill, &RMF_MDT_BODY); |
| 510 | LASSERT(md->body != NULL); |
| 511 | |
| 512 | if (md->body->valid & OBD_MD_FLEASIZE) { |
| 513 | int lmmsize; |
| 514 | struct lov_mds_md *lmm; |
| 515 | |
| 516 | if (!S_ISREG(md->body->mode)) { |
| 517 | CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a " |
| 518 | "regular file, but is not\n"); |
| 519 | GOTO(out, rc = -EPROTO); |
| 520 | } |
| 521 | |
| 522 | if (md->body->eadatasize == 0) { |
| 523 | CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, " |
| 524 | "but eadatasize 0\n"); |
| 525 | GOTO(out, rc = -EPROTO); |
| 526 | } |
| 527 | lmmsize = md->body->eadatasize; |
| 528 | lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize); |
| 529 | if (!lmm) |
| 530 | GOTO(out, rc = -EPROTO); |
| 531 | |
| 532 | rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize); |
| 533 | if (rc < 0) |
| 534 | GOTO(out, rc); |
| 535 | |
| 536 | if (rc < sizeof(*md->lsm)) { |
| 537 | CDEBUG(D_INFO, "lsm size too small: " |
| 538 | "rc < sizeof (*md->lsm) (%d < %d)\n", |
| 539 | rc, (int)sizeof(*md->lsm)); |
| 540 | GOTO(out, rc = -EPROTO); |
| 541 | } |
| 542 | |
| 543 | } else if (md->body->valid & OBD_MD_FLDIREA) { |
| 544 | int lmvsize; |
| 545 | struct lov_mds_md *lmv; |
| 546 | |
| 547 | if(!S_ISDIR(md->body->mode)) { |
| 548 | CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a " |
| 549 | "directory, but is not\n"); |
| 550 | GOTO(out, rc = -EPROTO); |
| 551 | } |
| 552 | |
| 553 | if (md->body->eadatasize == 0) { |
| 554 | CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, " |
| 555 | "but eadatasize 0\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 556 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 557 | } |
| 558 | if (md->body->valid & OBD_MD_MEA) { |
| 559 | lmvsize = md->body->eadatasize; |
| 560 | lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD, |
| 561 | lmvsize); |
| 562 | if (!lmv) |
| 563 | GOTO(out, rc = -EPROTO); |
| 564 | |
| 565 | rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv, |
| 566 | lmvsize); |
| 567 | if (rc < 0) |
| 568 | GOTO(out, rc); |
| 569 | |
| 570 | if (rc < sizeof(*md->mea)) { |
| 571 | CDEBUG(D_INFO, "size too small: " |
| 572 | "rc < sizeof(*md->mea) (%d < %d)\n", |
| 573 | rc, (int)sizeof(*md->mea)); |
| 574 | GOTO(out, rc = -EPROTO); |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | rc = 0; |
| 579 | |
| 580 | if (md->body->valid & OBD_MD_FLRMTPERM) { |
| 581 | /* remote permission */ |
| 582 | LASSERT(client_is_remote(exp)); |
| 583 | md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL, |
| 584 | lustre_swab_mdt_remote_perm); |
| 585 | if (!md->remote_perm) |
| 586 | GOTO(out, rc = -EPROTO); |
| 587 | } |
| 588 | else if (md->body->valid & OBD_MD_FLACL) { |
| 589 | /* for ACL, it's possible that FLACL is set but aclsize is zero. |
| 590 | * only when aclsize != 0 there's an actual segment for ACL |
| 591 | * in reply buffer. |
| 592 | */ |
| 593 | if (md->body->aclsize) { |
| 594 | rc = mdc_unpack_acl(req, md); |
| 595 | if (rc) |
| 596 | GOTO(out, rc); |
| 597 | #ifdef CONFIG_FS_POSIX_ACL |
| 598 | } else { |
| 599 | md->posix_acl = NULL; |
| 600 | #endif |
| 601 | } |
| 602 | } |
| 603 | if (md->body->valid & OBD_MD_FLMDSCAPA) { |
| 604 | struct obd_capa *oc = NULL; |
| 605 | |
| 606 | rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc); |
| 607 | if (rc) |
| 608 | GOTO(out, rc); |
| 609 | md->mds_capa = oc; |
| 610 | } |
| 611 | |
| 612 | if (md->body->valid & OBD_MD_FLOSSCAPA) { |
| 613 | struct obd_capa *oc = NULL; |
| 614 | |
| 615 | rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc); |
| 616 | if (rc) |
| 617 | GOTO(out, rc); |
| 618 | md->oss_capa = oc; |
| 619 | } |
| 620 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 621 | out: |
| 622 | if (rc) { |
| 623 | if (md->oss_capa) { |
| 624 | capa_put(md->oss_capa); |
| 625 | md->oss_capa = NULL; |
| 626 | } |
| 627 | if (md->mds_capa) { |
| 628 | capa_put(md->mds_capa); |
| 629 | md->mds_capa = NULL; |
| 630 | } |
| 631 | #ifdef CONFIG_FS_POSIX_ACL |
| 632 | posix_acl_release(md->posix_acl); |
| 633 | #endif |
| 634 | if (md->lsm) |
| 635 | obd_free_memmd(dt_exp, &md->lsm); |
| 636 | } |
| 637 | return rc; |
| 638 | } |
| 639 | |
| 640 | int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md) |
| 641 | { |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 642 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING |
| 647 | * RPC chains. |
| 648 | */ |
| 649 | void mdc_replay_open(struct ptlrpc_request *req) |
| 650 | { |
| 651 | struct md_open_data *mod = req->rq_cb_data; |
| 652 | struct ptlrpc_request *close_req; |
| 653 | struct obd_client_handle *och; |
| 654 | struct lustre_handle old; |
| 655 | struct mdt_body *body; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 656 | |
| 657 | if (mod == NULL) { |
| 658 | DEBUG_REQ(D_ERROR, req, |
| 659 | "Can't properly replay without open data."); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 660 | return; |
| 661 | } |
| 662 | |
| 663 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); |
| 664 | LASSERT(body != NULL); |
| 665 | |
| 666 | och = mod->mod_och; |
| 667 | if (och != NULL) { |
| 668 | struct lustre_handle *file_fh; |
| 669 | |
| 670 | LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC); |
| 671 | |
| 672 | file_fh = &och->och_fh; |
| 673 | CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n", |
| 674 | file_fh->cookie, body->handle.cookie); |
| 675 | old = *file_fh; |
| 676 | *file_fh = body->handle; |
| 677 | } |
| 678 | close_req = mod->mod_close_req; |
| 679 | if (close_req != NULL) { |
| 680 | __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg); |
| 681 | struct mdt_ioepoch *epoch; |
| 682 | |
| 683 | LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING); |
| 684 | epoch = req_capsule_client_get(&close_req->rq_pill, |
| 685 | &RMF_MDT_EPOCH); |
| 686 | LASSERT(epoch); |
| 687 | |
| 688 | if (och != NULL) |
| 689 | LASSERT(!memcmp(&old, &epoch->handle, sizeof(old))); |
| 690 | DEBUG_REQ(D_HA, close_req, "updating close body with new fh"); |
| 691 | epoch->handle = body->handle; |
| 692 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | void mdc_commit_open(struct ptlrpc_request *req) |
| 696 | { |
| 697 | struct md_open_data *mod = req->rq_cb_data; |
| 698 | if (mod == NULL) |
| 699 | return; |
| 700 | |
| 701 | /** |
| 702 | * No need to touch md_open_data::mod_och, it holds a reference on |
| 703 | * \var mod and will zero references to each other, \var mod will be |
| 704 | * freed after that when md_open_data::mod_och will put the reference. |
| 705 | */ |
| 706 | |
| 707 | /** |
| 708 | * Do not let open request to disappear as it still may be needed |
| 709 | * for close rpc to happen (it may happen on evict only, otherwise |
| 710 | * ptlrpc_request::rq_replay does not let mdc_commit_open() to be |
| 711 | * called), just mark this rpc as committed to distinguish these 2 |
| 712 | * cases, see mdc_close() for details. The open request reference will |
| 713 | * be put along with freeing \var mod. |
| 714 | */ |
| 715 | ptlrpc_request_addref(req); |
| 716 | spin_lock(&req->rq_lock); |
| 717 | req->rq_committed = 1; |
| 718 | spin_unlock(&req->rq_lock); |
| 719 | req->rq_cb_data = NULL; |
| 720 | obd_mod_put(mod); |
| 721 | } |
| 722 | |
| 723 | int mdc_set_open_replay_data(struct obd_export *exp, |
| 724 | struct obd_client_handle *och, |
| 725 | struct ptlrpc_request *open_req) |
| 726 | { |
| 727 | struct md_open_data *mod; |
| 728 | struct mdt_rec_create *rec; |
| 729 | struct mdt_body *body; |
| 730 | struct obd_import *imp = open_req->rq_import; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 731 | |
| 732 | if (!open_req->rq_replay) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 733 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 734 | |
| 735 | rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT); |
| 736 | body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY); |
| 737 | LASSERT(rec != NULL); |
| 738 | /* Incoming message in my byte order (it's been swabbed). */ |
| 739 | /* Outgoing messages always in my byte order. */ |
| 740 | LASSERT(body != NULL); |
| 741 | |
| 742 | /* Only if the import is replayable, we set replay_open data */ |
| 743 | if (och && imp->imp_replayable) { |
| 744 | mod = obd_mod_alloc(); |
| 745 | if (mod == NULL) { |
| 746 | DEBUG_REQ(D_ERROR, open_req, |
| 747 | "Can't allocate md_open_data"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 748 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /** |
| 752 | * Take a reference on \var mod, to be freed on mdc_close(). |
| 753 | * It protects \var mod from being freed on eviction (commit |
| 754 | * callback is called despite rq_replay flag). |
| 755 | * Another reference for \var och. |
| 756 | */ |
| 757 | obd_mod_get(mod); |
| 758 | obd_mod_get(mod); |
| 759 | |
| 760 | spin_lock(&open_req->rq_lock); |
| 761 | och->och_mod = mod; |
| 762 | mod->mod_och = och; |
| 763 | mod->mod_open_req = open_req; |
| 764 | open_req->rq_cb_data = mod; |
| 765 | open_req->rq_commit_cb = mdc_commit_open; |
| 766 | spin_unlock(&open_req->rq_lock); |
| 767 | } |
| 768 | |
| 769 | rec->cr_fid2 = body->fid1; |
| 770 | rec->cr_ioepoch = body->ioepoch; |
| 771 | rec->cr_old_handle.cookie = body->handle.cookie; |
| 772 | open_req->rq_replay_cb = mdc_replay_open; |
| 773 | if (!fid_is_sane(&body->fid1)) { |
| 774 | DEBUG_REQ(D_ERROR, open_req, "Saving replay request with " |
| 775 | "insane fid"); |
| 776 | LBUG(); |
| 777 | } |
| 778 | |
| 779 | DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 780 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | int mdc_clear_open_replay_data(struct obd_export *exp, |
| 784 | struct obd_client_handle *och) |
| 785 | { |
| 786 | struct md_open_data *mod = och->och_mod; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 787 | |
| 788 | /** |
| 789 | * It is possible to not have \var mod in a case of eviction between |
| 790 | * lookup and ll_file_open(). |
| 791 | **/ |
| 792 | if (mod == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 793 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 794 | |
| 795 | LASSERT(mod != LP_POISON); |
| 796 | |
| 797 | mod->mod_och = NULL; |
| 798 | och->och_mod = NULL; |
| 799 | obd_mod_put(mod); |
| 800 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 801 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | /* Prepares the request for the replay by the given reply */ |
| 805 | static void mdc_close_handle_reply(struct ptlrpc_request *req, |
| 806 | struct md_op_data *op_data, int rc) { |
| 807 | struct mdt_body *repbody; |
| 808 | struct mdt_ioepoch *epoch; |
| 809 | |
| 810 | if (req && rc == -EAGAIN) { |
| 811 | repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); |
| 812 | epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH); |
| 813 | |
| 814 | epoch->flags |= MF_SOM_AU; |
| 815 | if (repbody->valid & OBD_MD_FLGETATTRLOCK) |
| 816 | op_data->op_flags |= MF_GETATTR_LOCK; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | int mdc_close(struct obd_export *exp, struct md_op_data *op_data, |
| 821 | struct md_open_data *mod, struct ptlrpc_request **request) |
| 822 | { |
| 823 | struct obd_device *obd = class_exp2obd(exp); |
| 824 | struct ptlrpc_request *req; |
Jinshan Xiong | 48d23e6 | 2013-12-03 21:58:48 +0800 | [diff] [blame] | 825 | struct req_format *req_fmt; |
| 826 | int rc; |
| 827 | int saved_rc = 0; |
| 828 | |
| 829 | |
| 830 | req_fmt = &RQF_MDS_CLOSE; |
| 831 | if (op_data->op_bias & MDS_HSM_RELEASE) { |
| 832 | req_fmt = &RQF_MDS_RELEASE_CLOSE; |
| 833 | |
| 834 | /* allocate a FID for volatile file */ |
| 835 | rc = mdc_fid_alloc(exp, &op_data->op_fid2, op_data); |
| 836 | if (rc < 0) { |
| 837 | CERROR("%s: "DFID" failed to allocate FID: %d\n", |
| 838 | obd->obd_name, PFID(&op_data->op_fid1), rc); |
| 839 | /* save the errcode and proceed to close */ |
| 840 | saved_rc = rc; |
| 841 | } |
| 842 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 843 | |
| 844 | *request = NULL; |
Jinshan Xiong | 48d23e6 | 2013-12-03 21:58:48 +0800 | [diff] [blame] | 845 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), req_fmt); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 846 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 847 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 848 | |
| 849 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 850 | |
| 851 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE); |
| 852 | if (rc) { |
| 853 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 854 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a |
| 858 | * portal whose threads are not taking any DLM locks and are therefore |
| 859 | * always progressing */ |
| 860 | req->rq_request_portal = MDS_READPAGE_PORTAL; |
| 861 | ptlrpc_at_set_req_timeout(req); |
| 862 | |
| 863 | /* Ensure that this close's handle is fixed up during replay. */ |
| 864 | if (likely(mod != NULL)) { |
| 865 | LASSERTF(mod->mod_open_req != NULL && |
| 866 | mod->mod_open_req->rq_type != LI_POISON, |
| 867 | "POISONED open %p!\n", mod->mod_open_req); |
| 868 | |
| 869 | mod->mod_close_req = req; |
| 870 | |
| 871 | DEBUG_REQ(D_HA, mod->mod_open_req, "matched open"); |
| 872 | /* We no longer want to preserve this open for replay even |
| 873 | * though the open was committed. b=3632, b=3633 */ |
| 874 | spin_lock(&mod->mod_open_req->rq_lock); |
| 875 | mod->mod_open_req->rq_replay = 0; |
| 876 | spin_unlock(&mod->mod_open_req->rq_lock); |
| 877 | } else { |
| 878 | CDEBUG(D_HA, "couldn't find open req; expecting close error\n"); |
| 879 | } |
| 880 | |
| 881 | mdc_close_pack(req, op_data); |
| 882 | |
| 883 | req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, |
| 884 | obd->u.cli.cl_max_mds_easize); |
| 885 | req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER, |
| 886 | obd->u.cli.cl_max_mds_cookiesize); |
| 887 | |
| 888 | ptlrpc_request_set_replen(req); |
| 889 | |
| 890 | mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL); |
| 891 | rc = ptlrpc_queue_wait(req); |
| 892 | mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL); |
| 893 | |
| 894 | if (req->rq_repmsg == NULL) { |
| 895 | CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req, |
| 896 | req->rq_status); |
| 897 | if (rc == 0) |
| 898 | rc = req->rq_status ?: -EIO; |
| 899 | } else if (rc == 0 || rc == -EAGAIN) { |
| 900 | struct mdt_body *body; |
| 901 | |
| 902 | rc = lustre_msg_get_status(req->rq_repmsg); |
| 903 | if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) { |
| 904 | DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err " |
| 905 | "= %d", rc); |
| 906 | if (rc > 0) |
| 907 | rc = -rc; |
| 908 | } |
| 909 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); |
| 910 | if (body == NULL) |
| 911 | rc = -EPROTO; |
| 912 | } else if (rc == -ESTALE) { |
| 913 | /** |
| 914 | * it can be allowed error after 3633 if open was committed and |
| 915 | * server failed before close was sent. Let's check if mod |
| 916 | * exists and return no error in that case |
| 917 | */ |
| 918 | if (mod) { |
| 919 | DEBUG_REQ(D_HA, req, "Reset ESTALE = %d", rc); |
| 920 | LASSERT(mod->mod_open_req != NULL); |
| 921 | if (mod->mod_open_req->rq_committed) |
| 922 | rc = 0; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | if (mod) { |
| 927 | if (rc != 0) |
| 928 | mod->mod_close_req = NULL; |
| 929 | /* Since now, mod is accessed through open_req only, |
| 930 | * thus close req does not keep a reference on mod anymore. */ |
| 931 | obd_mod_put(mod); |
| 932 | } |
| 933 | *request = req; |
| 934 | mdc_close_handle_reply(req, op_data, rc); |
Jinshan Xiong | 48d23e6 | 2013-12-03 21:58:48 +0800 | [diff] [blame] | 935 | return rc < 0 ? rc : saved_rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data, |
| 939 | struct md_open_data *mod) |
| 940 | { |
| 941 | struct obd_device *obd = class_exp2obd(exp); |
| 942 | struct ptlrpc_request *req; |
| 943 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 944 | |
| 945 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), |
| 946 | &RQF_MDS_DONE_WRITING); |
| 947 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 948 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 949 | |
| 950 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 951 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING); |
| 952 | if (rc) { |
| 953 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 954 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | if (mod != NULL) { |
| 958 | LASSERTF(mod->mod_open_req != NULL && |
| 959 | mod->mod_open_req->rq_type != LI_POISON, |
| 960 | "POISONED setattr %p!\n", mod->mod_open_req); |
| 961 | |
| 962 | mod->mod_close_req = req; |
| 963 | DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr"); |
| 964 | /* We no longer want to preserve this setattr for replay even |
| 965 | * though the open was committed. b=3632, b=3633 */ |
| 966 | spin_lock(&mod->mod_open_req->rq_lock); |
| 967 | mod->mod_open_req->rq_replay = 0; |
| 968 | spin_unlock(&mod->mod_open_req->rq_lock); |
| 969 | } |
| 970 | |
| 971 | mdc_close_pack(req, op_data); |
| 972 | ptlrpc_request_set_replen(req); |
| 973 | |
| 974 | mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL); |
| 975 | rc = ptlrpc_queue_wait(req); |
| 976 | mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL); |
| 977 | |
| 978 | if (rc == -ESTALE) { |
| 979 | /** |
| 980 | * it can be allowed error after 3633 if open or setattr were |
| 981 | * committed and server failed before close was sent. |
| 982 | * Let's check if mod exists and return no error in that case |
| 983 | */ |
| 984 | if (mod) { |
| 985 | LASSERT(mod->mod_open_req != NULL); |
| 986 | if (mod->mod_open_req->rq_committed) |
| 987 | rc = 0; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | if (mod) { |
| 992 | if (rc != 0) |
| 993 | mod->mod_close_req = NULL; |
| 994 | /* Since now, mod is accessed through setattr req only, |
| 995 | * thus DW req does not keep a reference on mod anymore. */ |
| 996 | obd_mod_put(mod); |
| 997 | } |
| 998 | |
| 999 | mdc_close_handle_reply(req, op_data, rc); |
| 1000 | ptlrpc_req_finished(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1001 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | int mdc_readpage(struct obd_export *exp, struct md_op_data *op_data, |
| 1006 | struct page **pages, struct ptlrpc_request **request) |
| 1007 | { |
| 1008 | struct ptlrpc_request *req; |
| 1009 | struct ptlrpc_bulk_desc *desc; |
| 1010 | int i; |
| 1011 | wait_queue_head_t waitq; |
| 1012 | int resends = 0; |
| 1013 | struct l_wait_info lwi; |
| 1014 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1015 | |
| 1016 | *request = NULL; |
| 1017 | init_waitqueue_head(&waitq); |
| 1018 | |
| 1019 | restart_bulk: |
| 1020 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE); |
| 1021 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1022 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1023 | |
| 1024 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 1025 | |
| 1026 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE); |
| 1027 | if (rc) { |
| 1028 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1029 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | req->rq_request_portal = MDS_READPAGE_PORTAL; |
| 1033 | ptlrpc_at_set_req_timeout(req); |
| 1034 | |
| 1035 | desc = ptlrpc_prep_bulk_imp(req, op_data->op_npages, 1, BULK_PUT_SINK, |
| 1036 | MDS_BULK_PORTAL); |
| 1037 | if (desc == NULL) { |
| 1038 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1039 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /* NB req now owns desc and will free it when it gets freed */ |
| 1043 | for (i = 0; i < op_data->op_npages; i++) |
| 1044 | ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE); |
| 1045 | |
| 1046 | mdc_readdir_pack(req, op_data->op_offset, |
| 1047 | PAGE_CACHE_SIZE * op_data->op_npages, |
| 1048 | &op_data->op_fid1, op_data->op_capa1); |
| 1049 | |
| 1050 | ptlrpc_request_set_replen(req); |
| 1051 | rc = ptlrpc_queue_wait(req); |
| 1052 | if (rc) { |
| 1053 | ptlrpc_req_finished(req); |
| 1054 | if (rc != -ETIMEDOUT) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1055 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1056 | |
| 1057 | resends++; |
| 1058 | if (!client_should_resend(resends, &exp->exp_obd->u.cli)) { |
| 1059 | CERROR("too many resend retries, returning error\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1060 | return -EIO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1061 | } |
| 1062 | lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL, NULL); |
| 1063 | l_wait_event(waitq, 0, &lwi); |
| 1064 | |
| 1065 | goto restart_bulk; |
| 1066 | } |
| 1067 | |
| 1068 | rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk, |
| 1069 | req->rq_bulk->bd_nob_transferred); |
| 1070 | if (rc < 0) { |
| 1071 | ptlrpc_req_finished(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1072 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | if (req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK) { |
| 1076 | CERROR("Unexpected # bytes transferred: %d (%ld expected)\n", |
| 1077 | req->rq_bulk->bd_nob_transferred, |
| 1078 | PAGE_CACHE_SIZE * op_data->op_npages); |
| 1079 | ptlrpc_req_finished(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1080 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | *request = req; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1084 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static int mdc_statfs(const struct lu_env *env, |
| 1088 | struct obd_export *exp, struct obd_statfs *osfs, |
| 1089 | __u64 max_age, __u32 flags) |
| 1090 | { |
| 1091 | struct obd_device *obd = class_exp2obd(exp); |
| 1092 | struct ptlrpc_request *req; |
| 1093 | struct obd_statfs *msfs; |
| 1094 | struct obd_import *imp = NULL; |
| 1095 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1096 | |
| 1097 | /* |
| 1098 | * Since the request might also come from lprocfs, so we need |
| 1099 | * sync this with client_disconnect_export Bug15684 |
| 1100 | */ |
| 1101 | down_read(&obd->u.cli.cl_sem); |
| 1102 | if (obd->u.cli.cl_import) |
| 1103 | imp = class_import_get(obd->u.cli.cl_import); |
| 1104 | up_read(&obd->u.cli.cl_sem); |
| 1105 | if (!imp) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1106 | return -ENODEV; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1107 | |
| 1108 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS, |
| 1109 | LUSTRE_MDS_VERSION, MDS_STATFS); |
| 1110 | if (req == NULL) |
| 1111 | GOTO(output, rc = -ENOMEM); |
| 1112 | |
| 1113 | ptlrpc_request_set_replen(req); |
| 1114 | |
| 1115 | if (flags & OBD_STATFS_NODELAY) { |
| 1116 | /* procfs requests not want stay in wait for avoid deadlock */ |
| 1117 | req->rq_no_resend = 1; |
| 1118 | req->rq_no_delay = 1; |
| 1119 | } |
| 1120 | |
| 1121 | rc = ptlrpc_queue_wait(req); |
| 1122 | if (rc) { |
| 1123 | /* check connection error first */ |
| 1124 | if (imp->imp_connect_error) |
| 1125 | rc = imp->imp_connect_error; |
| 1126 | GOTO(out, rc); |
| 1127 | } |
| 1128 | |
| 1129 | msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS); |
| 1130 | if (msfs == NULL) |
| 1131 | GOTO(out, rc = -EPROTO); |
| 1132 | |
| 1133 | *osfs = *msfs; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1134 | out: |
| 1135 | ptlrpc_req_finished(req); |
| 1136 | output: |
| 1137 | class_import_put(imp); |
| 1138 | return rc; |
| 1139 | } |
| 1140 | |
| 1141 | static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf) |
| 1142 | { |
| 1143 | __u32 keylen, vallen; |
| 1144 | void *key; |
| 1145 | int rc; |
| 1146 | |
| 1147 | if (gf->gf_pathlen > PATH_MAX) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1148 | return -ENAMETOOLONG; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1149 | if (gf->gf_pathlen < 2) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1150 | return -EOVERFLOW; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1151 | |
| 1152 | /* Key is KEY_FID2PATH + getinfo_fid2path description */ |
| 1153 | keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf); |
| 1154 | OBD_ALLOC(key, keylen); |
| 1155 | if (key == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1156 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1157 | memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH)); |
| 1158 | memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf)); |
| 1159 | |
| 1160 | CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n", |
| 1161 | PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno); |
| 1162 | |
| 1163 | if (!fid_is_sane(&gf->gf_fid)) |
| 1164 | GOTO(out, rc = -EINVAL); |
| 1165 | |
| 1166 | /* Val is struct getinfo_fid2path result plus path */ |
| 1167 | vallen = sizeof(*gf) + gf->gf_pathlen; |
| 1168 | |
| 1169 | rc = obd_get_info(NULL, exp, keylen, key, &vallen, gf, NULL); |
| 1170 | if (rc != 0 && rc != -EREMOTE) |
| 1171 | GOTO(out, rc); |
| 1172 | |
| 1173 | if (vallen <= sizeof(*gf)) |
| 1174 | GOTO(out, rc = -EPROTO); |
| 1175 | else if (vallen > sizeof(*gf) + gf->gf_pathlen) |
| 1176 | GOTO(out, rc = -EOVERFLOW); |
| 1177 | |
| 1178 | CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n%s\n", |
| 1179 | PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path); |
| 1180 | |
| 1181 | out: |
| 1182 | OBD_FREE(key, keylen); |
| 1183 | return rc; |
| 1184 | } |
| 1185 | |
| 1186 | static int mdc_ioc_hsm_progress(struct obd_export *exp, |
| 1187 | struct hsm_progress_kernel *hpk) |
| 1188 | { |
| 1189 | struct obd_import *imp = class_exp2cliimp(exp); |
| 1190 | struct hsm_progress_kernel *req_hpk; |
| 1191 | struct ptlrpc_request *req; |
| 1192 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1193 | |
| 1194 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_PROGRESS, |
| 1195 | LUSTRE_MDS_VERSION, MDS_HSM_PROGRESS); |
| 1196 | if (req == NULL) |
| 1197 | GOTO(out, rc = -ENOMEM); |
| 1198 | |
| 1199 | mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0); |
| 1200 | |
| 1201 | /* Copy hsm_progress struct */ |
| 1202 | req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS); |
| 1203 | if (req_hpk == NULL) |
| 1204 | GOTO(out, rc = -EPROTO); |
| 1205 | |
| 1206 | *req_hpk = *hpk; |
Li Wei | 2d58de7 | 2013-07-23 00:06:32 +0800 | [diff] [blame] | 1207 | req_hpk->hpk_errval = lustre_errno_hton(hpk->hpk_errval); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1208 | |
| 1209 | ptlrpc_request_set_replen(req); |
| 1210 | |
| 1211 | rc = mdc_queue_wait(req); |
| 1212 | GOTO(out, rc); |
| 1213 | out: |
| 1214 | ptlrpc_req_finished(req); |
| 1215 | return rc; |
| 1216 | } |
| 1217 | |
| 1218 | static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives) |
| 1219 | { |
| 1220 | __u32 *archive_mask; |
| 1221 | struct ptlrpc_request *req; |
| 1222 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1223 | |
| 1224 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_REGISTER, |
| 1225 | LUSTRE_MDS_VERSION, |
| 1226 | MDS_HSM_CT_REGISTER); |
| 1227 | if (req == NULL) |
| 1228 | GOTO(out, rc = -ENOMEM); |
| 1229 | |
| 1230 | mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0); |
| 1231 | |
| 1232 | /* Copy hsm_progress struct */ |
| 1233 | archive_mask = req_capsule_client_get(&req->rq_pill, |
| 1234 | &RMF_MDS_HSM_ARCHIVE); |
| 1235 | if (archive_mask == NULL) |
| 1236 | GOTO(out, rc = -EPROTO); |
| 1237 | |
| 1238 | *archive_mask = archives; |
| 1239 | |
| 1240 | ptlrpc_request_set_replen(req); |
| 1241 | |
| 1242 | rc = mdc_queue_wait(req); |
| 1243 | GOTO(out, rc); |
| 1244 | out: |
| 1245 | ptlrpc_req_finished(req); |
| 1246 | return rc; |
| 1247 | } |
| 1248 | |
| 1249 | static int mdc_ioc_hsm_current_action(struct obd_export *exp, |
| 1250 | struct md_op_data *op_data) |
| 1251 | { |
| 1252 | struct hsm_current_action *hca = op_data->op_data; |
| 1253 | struct hsm_current_action *req_hca; |
| 1254 | struct ptlrpc_request *req; |
| 1255 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1256 | |
| 1257 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), |
| 1258 | &RQF_MDS_HSM_ACTION); |
| 1259 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1260 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1261 | |
| 1262 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 1263 | |
| 1264 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_ACTION); |
| 1265 | if (rc) { |
| 1266 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1267 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1, |
| 1271 | OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0); |
| 1272 | |
| 1273 | ptlrpc_request_set_replen(req); |
| 1274 | |
| 1275 | rc = mdc_queue_wait(req); |
| 1276 | if (rc) |
| 1277 | GOTO(out, rc); |
| 1278 | |
| 1279 | req_hca = req_capsule_server_get(&req->rq_pill, |
| 1280 | &RMF_MDS_HSM_CURRENT_ACTION); |
| 1281 | if (req_hca == NULL) |
| 1282 | GOTO(out, rc = -EPROTO); |
| 1283 | |
| 1284 | *hca = *req_hca; |
| 1285 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1286 | out: |
| 1287 | ptlrpc_req_finished(req); |
| 1288 | return rc; |
| 1289 | } |
| 1290 | |
| 1291 | static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp) |
| 1292 | { |
| 1293 | struct ptlrpc_request *req; |
| 1294 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1295 | |
| 1296 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_UNREGISTER, |
| 1297 | LUSTRE_MDS_VERSION, |
| 1298 | MDS_HSM_CT_UNREGISTER); |
| 1299 | if (req == NULL) |
| 1300 | GOTO(out, rc = -ENOMEM); |
| 1301 | |
| 1302 | mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0); |
| 1303 | |
| 1304 | ptlrpc_request_set_replen(req); |
| 1305 | |
| 1306 | rc = mdc_queue_wait(req); |
| 1307 | GOTO(out, rc); |
| 1308 | out: |
| 1309 | ptlrpc_req_finished(req); |
| 1310 | return rc; |
| 1311 | } |
| 1312 | |
| 1313 | static int mdc_ioc_hsm_state_get(struct obd_export *exp, |
| 1314 | struct md_op_data *op_data) |
| 1315 | { |
| 1316 | struct hsm_user_state *hus = op_data->op_data; |
| 1317 | struct hsm_user_state *req_hus; |
| 1318 | struct ptlrpc_request *req; |
| 1319 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1320 | |
| 1321 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), |
| 1322 | &RQF_MDS_HSM_STATE_GET); |
| 1323 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1324 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1325 | |
| 1326 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 1327 | |
| 1328 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_GET); |
| 1329 | if (rc != 0) { |
| 1330 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1331 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1, |
| 1335 | OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0); |
| 1336 | |
| 1337 | ptlrpc_request_set_replen(req); |
| 1338 | |
| 1339 | rc = mdc_queue_wait(req); |
| 1340 | if (rc) |
| 1341 | GOTO(out, rc); |
| 1342 | |
| 1343 | req_hus = req_capsule_server_get(&req->rq_pill, &RMF_HSM_USER_STATE); |
| 1344 | if (req_hus == NULL) |
| 1345 | GOTO(out, rc = -EPROTO); |
| 1346 | |
| 1347 | *hus = *req_hus; |
| 1348 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1349 | out: |
| 1350 | ptlrpc_req_finished(req); |
| 1351 | return rc; |
| 1352 | } |
| 1353 | |
| 1354 | static int mdc_ioc_hsm_state_set(struct obd_export *exp, |
| 1355 | struct md_op_data *op_data) |
| 1356 | { |
| 1357 | struct hsm_state_set *hss = op_data->op_data; |
| 1358 | struct hsm_state_set *req_hss; |
| 1359 | struct ptlrpc_request *req; |
| 1360 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1361 | |
| 1362 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), |
| 1363 | &RQF_MDS_HSM_STATE_SET); |
| 1364 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1365 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1366 | |
| 1367 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 1368 | |
| 1369 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_SET); |
| 1370 | if (rc) { |
| 1371 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1372 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1, |
| 1376 | OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0); |
| 1377 | |
| 1378 | /* Copy states */ |
| 1379 | req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET); |
| 1380 | if (req_hss == NULL) |
| 1381 | GOTO(out, rc = -EPROTO); |
| 1382 | *req_hss = *hss; |
| 1383 | |
| 1384 | ptlrpc_request_set_replen(req); |
| 1385 | |
| 1386 | rc = mdc_queue_wait(req); |
| 1387 | GOTO(out, rc); |
| 1388 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1389 | out: |
| 1390 | ptlrpc_req_finished(req); |
| 1391 | return rc; |
| 1392 | } |
| 1393 | |
| 1394 | static int mdc_ioc_hsm_request(struct obd_export *exp, |
| 1395 | struct hsm_user_request *hur) |
| 1396 | { |
| 1397 | struct obd_import *imp = class_exp2cliimp(exp); |
| 1398 | struct ptlrpc_request *req; |
| 1399 | struct hsm_request *req_hr; |
| 1400 | struct hsm_user_item *req_hui; |
| 1401 | char *req_opaque; |
| 1402 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1403 | |
| 1404 | req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST); |
| 1405 | if (req == NULL) |
| 1406 | GOTO(out, rc = -ENOMEM); |
| 1407 | |
| 1408 | req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT, |
| 1409 | hur->hur_request.hr_itemcount |
| 1410 | * sizeof(struct hsm_user_item)); |
| 1411 | req_capsule_set_size(&req->rq_pill, &RMF_GENERIC_DATA, RCL_CLIENT, |
| 1412 | hur->hur_request.hr_data_len); |
| 1413 | |
| 1414 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_REQUEST); |
| 1415 | if (rc) { |
| 1416 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1417 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0); |
| 1421 | |
| 1422 | /* Copy hsm_request struct */ |
| 1423 | req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST); |
| 1424 | if (req_hr == NULL) |
| 1425 | GOTO(out, rc = -EPROTO); |
| 1426 | *req_hr = hur->hur_request; |
| 1427 | |
| 1428 | /* Copy hsm_user_item structs */ |
| 1429 | req_hui = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM); |
| 1430 | if (req_hui == NULL) |
| 1431 | GOTO(out, rc = -EPROTO); |
| 1432 | memcpy(req_hui, hur->hur_user_item, |
| 1433 | hur->hur_request.hr_itemcount * sizeof(struct hsm_user_item)); |
| 1434 | |
| 1435 | /* Copy opaque field */ |
| 1436 | req_opaque = req_capsule_client_get(&req->rq_pill, &RMF_GENERIC_DATA); |
| 1437 | if (req_opaque == NULL) |
| 1438 | GOTO(out, rc = -EPROTO); |
| 1439 | memcpy(req_opaque, hur_data(hur), hur->hur_request.hr_data_len); |
| 1440 | |
| 1441 | ptlrpc_request_set_replen(req); |
| 1442 | |
| 1443 | rc = mdc_queue_wait(req); |
| 1444 | GOTO(out, rc); |
| 1445 | |
| 1446 | out: |
| 1447 | ptlrpc_req_finished(req); |
| 1448 | return rc; |
| 1449 | } |
| 1450 | |
| 1451 | static struct kuc_hdr *changelog_kuc_hdr(char *buf, int len, int flags) |
| 1452 | { |
| 1453 | struct kuc_hdr *lh = (struct kuc_hdr *)buf; |
| 1454 | |
Oleg Drokin | 18e042f | 2014-01-23 23:45:07 -0500 | [diff] [blame] | 1455 | LASSERT(len <= KUC_CHANGELOG_MSG_MAXSIZE); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1456 | |
| 1457 | lh->kuc_magic = KUC_MAGIC; |
| 1458 | lh->kuc_transport = KUC_TRANSPORT_CHANGELOG; |
| 1459 | lh->kuc_flags = flags; |
| 1460 | lh->kuc_msgtype = CL_RECORD; |
| 1461 | lh->kuc_msglen = len; |
| 1462 | return lh; |
| 1463 | } |
| 1464 | |
| 1465 | #define D_CHANGELOG 0 |
| 1466 | |
| 1467 | struct changelog_show { |
| 1468 | __u64 cs_startrec; |
| 1469 | __u32 cs_flags; |
| 1470 | struct file *cs_fp; |
| 1471 | char *cs_buf; |
| 1472 | struct obd_device *cs_obd; |
| 1473 | }; |
| 1474 | |
Andreas Dilger | e377988 | 2013-06-03 21:40:52 +0800 | [diff] [blame] | 1475 | static int changelog_kkuc_cb(const struct lu_env *env, struct llog_handle *llh, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1476 | struct llog_rec_hdr *hdr, void *data) |
| 1477 | { |
| 1478 | struct changelog_show *cs = data; |
| 1479 | struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr; |
| 1480 | struct kuc_hdr *lh; |
| 1481 | int len, rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1482 | |
Andreas Dilger | e377988 | 2013-06-03 21:40:52 +0800 | [diff] [blame] | 1483 | if (rec->cr_hdr.lrh_type != CHANGELOG_REC) { |
| 1484 | rc = -EINVAL; |
| 1485 | CERROR("%s: not a changelog rec %x/%d: rc = %d\n", |
| 1486 | cs->cs_obd->obd_name, rec->cr_hdr.lrh_type, |
| 1487 | rec->cr.cr_type, rc); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1488 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | if (rec->cr.cr_index < cs->cs_startrec) { |
| 1492 | /* Skip entries earlier than what we are interested in */ |
| 1493 | CDEBUG(D_CHANGELOG, "rec="LPU64" start="LPU64"\n", |
| 1494 | rec->cr.cr_index, cs->cs_startrec); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1495 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | CDEBUG(D_CHANGELOG, LPU64" %02d%-5s "LPU64" 0x%x t="DFID" p="DFID |
| 1499 | " %.*s\n", rec->cr.cr_index, rec->cr.cr_type, |
| 1500 | changelog_type2str(rec->cr.cr_type), rec->cr.cr_time, |
| 1501 | rec->cr.cr_flags & CLF_FLAGMASK, |
| 1502 | PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid), |
| 1503 | rec->cr.cr_namelen, changelog_rec_name(&rec->cr)); |
| 1504 | |
| 1505 | len = sizeof(*lh) + changelog_rec_size(&rec->cr) + rec->cr.cr_namelen; |
| 1506 | |
| 1507 | /* Set up the message */ |
| 1508 | lh = changelog_kuc_hdr(cs->cs_buf, len, cs->cs_flags); |
| 1509 | memcpy(lh + 1, &rec->cr, len - sizeof(*lh)); |
| 1510 | |
| 1511 | rc = libcfs_kkuc_msg_put(cs->cs_fp, lh); |
| 1512 | CDEBUG(D_CHANGELOG, "kucmsg fp %p len %d rc %d\n", cs->cs_fp, len,rc); |
| 1513 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1514 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | static int mdc_changelog_send_thread(void *csdata) |
| 1518 | { |
| 1519 | struct changelog_show *cs = csdata; |
| 1520 | struct llog_ctxt *ctxt = NULL; |
| 1521 | struct llog_handle *llh = NULL; |
| 1522 | struct kuc_hdr *kuch; |
| 1523 | int rc; |
| 1524 | |
| 1525 | CDEBUG(D_CHANGELOG, "changelog to fp=%p start "LPU64"\n", |
| 1526 | cs->cs_fp, cs->cs_startrec); |
| 1527 | |
Oleg Drokin | 18e042f | 2014-01-23 23:45:07 -0500 | [diff] [blame] | 1528 | OBD_ALLOC(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1529 | if (cs->cs_buf == NULL) |
| 1530 | GOTO(out, rc = -ENOMEM); |
| 1531 | |
| 1532 | /* Set up the remote catalog handle */ |
| 1533 | ctxt = llog_get_context(cs->cs_obd, LLOG_CHANGELOG_REPL_CTXT); |
| 1534 | if (ctxt == NULL) |
| 1535 | GOTO(out, rc = -ENOENT); |
| 1536 | rc = llog_open(NULL, ctxt, &llh, NULL, CHANGELOG_CATALOG, |
| 1537 | LLOG_OPEN_EXISTS); |
| 1538 | if (rc) { |
| 1539 | CERROR("%s: fail to open changelog catalog: rc = %d\n", |
| 1540 | cs->cs_obd->obd_name, rc); |
| 1541 | GOTO(out, rc); |
| 1542 | } |
| 1543 | rc = llog_init_handle(NULL, llh, LLOG_F_IS_CAT, NULL); |
| 1544 | if (rc) { |
| 1545 | CERROR("llog_init_handle failed %d\n", rc); |
| 1546 | GOTO(out, rc); |
| 1547 | } |
| 1548 | |
Andreas Dilger | e377988 | 2013-06-03 21:40:52 +0800 | [diff] [blame] | 1549 | rc = llog_cat_process(NULL, llh, changelog_kkuc_cb, cs, 0, 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1550 | |
| 1551 | /* Send EOF no matter what our result */ |
| 1552 | if ((kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch), |
| 1553 | cs->cs_flags))) { |
| 1554 | kuch->kuc_msgtype = CL_EOF; |
| 1555 | libcfs_kkuc_msg_put(cs->cs_fp, kuch); |
| 1556 | } |
| 1557 | |
| 1558 | out: |
| 1559 | fput(cs->cs_fp); |
| 1560 | if (llh) |
| 1561 | llog_cat_close(NULL, llh); |
| 1562 | if (ctxt) |
| 1563 | llog_ctxt_put(ctxt); |
| 1564 | if (cs->cs_buf) |
Oleg Drokin | 18e042f | 2014-01-23 23:45:07 -0500 | [diff] [blame] | 1565 | OBD_FREE(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1566 | OBD_FREE_PTR(cs); |
| 1567 | return rc; |
| 1568 | } |
| 1569 | |
| 1570 | static int mdc_ioc_changelog_send(struct obd_device *obd, |
| 1571 | struct ioc_changelog *icc) |
| 1572 | { |
| 1573 | struct changelog_show *cs; |
| 1574 | int rc; |
| 1575 | |
| 1576 | /* Freed in mdc_changelog_send_thread */ |
| 1577 | OBD_ALLOC_PTR(cs); |
| 1578 | if (!cs) |
| 1579 | return -ENOMEM; |
| 1580 | |
| 1581 | cs->cs_obd = obd; |
| 1582 | cs->cs_startrec = icc->icc_recno; |
| 1583 | /* matching fput in mdc_changelog_send_thread */ |
| 1584 | cs->cs_fp = fget(icc->icc_id); |
| 1585 | cs->cs_flags = icc->icc_flags; |
| 1586 | |
| 1587 | /* |
| 1588 | * New thread because we should return to user app before |
| 1589 | * writing into our pipe |
| 1590 | */ |
| 1591 | rc = PTR_ERR(kthread_run(mdc_changelog_send_thread, cs, |
| 1592 | "mdc_clg_send_thread")); |
| 1593 | if (!IS_ERR_VALUE(rc)) { |
| 1594 | CDEBUG(D_CHANGELOG, "start changelog thread\n"); |
| 1595 | return 0; |
| 1596 | } |
| 1597 | |
| 1598 | CERROR("Failed to start changelog thread: %d\n", rc); |
| 1599 | OBD_FREE_PTR(cs); |
| 1600 | return rc; |
| 1601 | } |
| 1602 | |
| 1603 | static int mdc_ioc_hsm_ct_start(struct obd_export *exp, |
| 1604 | struct lustre_kernelcomm *lk); |
| 1605 | |
| 1606 | static int mdc_quotacheck(struct obd_device *unused, struct obd_export *exp, |
| 1607 | struct obd_quotactl *oqctl) |
| 1608 | { |
| 1609 | struct client_obd *cli = &exp->exp_obd->u.cli; |
| 1610 | struct ptlrpc_request *req; |
| 1611 | struct obd_quotactl *body; |
| 1612 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1613 | |
| 1614 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), |
| 1615 | &RQF_MDS_QUOTACHECK, LUSTRE_MDS_VERSION, |
| 1616 | MDS_QUOTACHECK); |
| 1617 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1618 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1619 | |
| 1620 | body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL); |
| 1621 | *body = *oqctl; |
| 1622 | |
| 1623 | ptlrpc_request_set_replen(req); |
| 1624 | |
| 1625 | /* the next poll will find -ENODATA, that means quotacheck is |
| 1626 | * going on */ |
| 1627 | cli->cl_qchk_stat = -ENODATA; |
| 1628 | rc = ptlrpc_queue_wait(req); |
| 1629 | if (rc) |
| 1630 | cli->cl_qchk_stat = rc; |
| 1631 | ptlrpc_req_finished(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1632 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | static int mdc_quota_poll_check(struct obd_export *exp, |
| 1636 | struct if_quotacheck *qchk) |
| 1637 | { |
| 1638 | struct client_obd *cli = &exp->exp_obd->u.cli; |
| 1639 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1640 | |
| 1641 | qchk->obd_uuid = cli->cl_target_uuid; |
| 1642 | memcpy(qchk->obd_type, LUSTRE_MDS_NAME, strlen(LUSTRE_MDS_NAME)); |
| 1643 | |
| 1644 | rc = cli->cl_qchk_stat; |
| 1645 | /* the client is not the previous one */ |
| 1646 | if (rc == CL_NOT_QUOTACHECKED) |
| 1647 | rc = -EINTR; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1648 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | static int mdc_quotactl(struct obd_device *unused, struct obd_export *exp, |
| 1652 | struct obd_quotactl *oqctl) |
| 1653 | { |
| 1654 | struct ptlrpc_request *req; |
| 1655 | struct obd_quotactl *oqc; |
| 1656 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1657 | |
| 1658 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), |
| 1659 | &RQF_MDS_QUOTACTL, LUSTRE_MDS_VERSION, |
| 1660 | MDS_QUOTACTL); |
| 1661 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1662 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1663 | |
| 1664 | oqc = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL); |
| 1665 | *oqc = *oqctl; |
| 1666 | |
| 1667 | ptlrpc_request_set_replen(req); |
| 1668 | ptlrpc_at_set_req_timeout(req); |
| 1669 | req->rq_no_resend = 1; |
| 1670 | |
| 1671 | rc = ptlrpc_queue_wait(req); |
| 1672 | if (rc) |
| 1673 | CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc); |
| 1674 | |
| 1675 | if (req->rq_repmsg && |
| 1676 | (oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL))) { |
| 1677 | *oqctl = *oqc; |
| 1678 | } else if (!rc) { |
| 1679 | CERROR ("Can't unpack obd_quotactl\n"); |
| 1680 | rc = -EPROTO; |
| 1681 | } |
| 1682 | ptlrpc_req_finished(req); |
| 1683 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1684 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | static int mdc_ioc_swap_layouts(struct obd_export *exp, |
| 1688 | struct md_op_data *op_data) |
| 1689 | { |
| 1690 | LIST_HEAD(cancels); |
| 1691 | struct ptlrpc_request *req; |
| 1692 | int rc, count; |
| 1693 | struct mdc_swap_layouts *msl, *payload; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1694 | |
| 1695 | msl = op_data->op_data; |
| 1696 | |
| 1697 | /* When the MDT will get the MDS_SWAP_LAYOUTS RPC the |
| 1698 | * first thing it will do is to cancel the 2 layout |
| 1699 | * locks hold by this client. |
| 1700 | * So the client must cancel its layout locks on the 2 fids |
| 1701 | * with the request RPC to avoid extra RPC round trips |
| 1702 | */ |
| 1703 | count = mdc_resource_get_unused(exp, &op_data->op_fid1, &cancels, |
| 1704 | LCK_CR, MDS_INODELOCK_LAYOUT); |
| 1705 | count += mdc_resource_get_unused(exp, &op_data->op_fid2, &cancels, |
| 1706 | LCK_CR, MDS_INODELOCK_LAYOUT); |
| 1707 | |
| 1708 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), |
| 1709 | &RQF_MDS_SWAP_LAYOUTS); |
| 1710 | if (req == NULL) { |
| 1711 | ldlm_lock_list_put(&cancels, l_bl_ast, count); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1712 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1); |
| 1716 | mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2); |
| 1717 | |
| 1718 | rc = mdc_prep_elc_req(exp, req, MDS_SWAP_LAYOUTS, &cancels, count); |
| 1719 | if (rc) { |
| 1720 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1721 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | mdc_swap_layouts_pack(req, op_data); |
| 1725 | |
| 1726 | payload = req_capsule_client_get(&req->rq_pill, &RMF_SWAP_LAYOUTS); |
| 1727 | LASSERT(payload); |
| 1728 | |
| 1729 | *payload = *msl; |
| 1730 | |
| 1731 | ptlrpc_request_set_replen(req); |
| 1732 | |
| 1733 | rc = ptlrpc_queue_wait(req); |
| 1734 | if (rc) |
| 1735 | GOTO(out, rc); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1736 | |
| 1737 | out: |
| 1738 | ptlrpc_req_finished(req); |
| 1739 | return rc; |
| 1740 | } |
| 1741 | |
| 1742 | static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, |
| 1743 | void *karg, void *uarg) |
| 1744 | { |
| 1745 | struct obd_device *obd = exp->exp_obd; |
| 1746 | struct obd_ioctl_data *data = karg; |
| 1747 | struct obd_import *imp = obd->u.cli.cl_import; |
| 1748 | struct llog_ctxt *ctxt; |
| 1749 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1750 | |
| 1751 | if (!try_module_get(THIS_MODULE)) { |
| 1752 | CERROR("Can't get module. Is it alive?"); |
| 1753 | return -EINVAL; |
| 1754 | } |
| 1755 | switch (cmd) { |
| 1756 | case OBD_IOC_CHANGELOG_SEND: |
| 1757 | rc = mdc_ioc_changelog_send(obd, karg); |
| 1758 | GOTO(out, rc); |
| 1759 | case OBD_IOC_CHANGELOG_CLEAR: { |
| 1760 | struct ioc_changelog *icc = karg; |
| 1761 | struct changelog_setinfo cs = |
| 1762 | {.cs_recno = icc->icc_recno, .cs_id = icc->icc_id}; |
| 1763 | rc = obd_set_info_async(NULL, exp, strlen(KEY_CHANGELOG_CLEAR), |
| 1764 | KEY_CHANGELOG_CLEAR, sizeof(cs), &cs, |
| 1765 | NULL); |
| 1766 | GOTO(out, rc); |
| 1767 | } |
| 1768 | case OBD_IOC_FID2PATH: |
| 1769 | rc = mdc_ioc_fid2path(exp, karg); |
| 1770 | GOTO(out, rc); |
| 1771 | case LL_IOC_HSM_CT_START: |
| 1772 | rc = mdc_ioc_hsm_ct_start(exp, karg); |
Thomas Leibovici | 78eb9092 | 2013-07-25 01:17:24 +0800 | [diff] [blame] | 1773 | /* ignore if it was already registered on this MDS. */ |
| 1774 | if (rc == -EEXIST) |
| 1775 | rc = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1776 | GOTO(out, rc); |
| 1777 | case LL_IOC_HSM_PROGRESS: |
| 1778 | rc = mdc_ioc_hsm_progress(exp, karg); |
| 1779 | GOTO(out, rc); |
| 1780 | case LL_IOC_HSM_STATE_GET: |
| 1781 | rc = mdc_ioc_hsm_state_get(exp, karg); |
| 1782 | GOTO(out, rc); |
| 1783 | case LL_IOC_HSM_STATE_SET: |
| 1784 | rc = mdc_ioc_hsm_state_set(exp, karg); |
John L. Hammond | c1f3d68 | 2013-11-26 10:04:59 +0800 | [diff] [blame] | 1785 | GOTO(out, rc); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1786 | case LL_IOC_HSM_ACTION: |
| 1787 | rc = mdc_ioc_hsm_current_action(exp, karg); |
| 1788 | GOTO(out, rc); |
| 1789 | case LL_IOC_HSM_REQUEST: |
| 1790 | rc = mdc_ioc_hsm_request(exp, karg); |
| 1791 | GOTO(out, rc); |
| 1792 | case OBD_IOC_CLIENT_RECOVER: |
| 1793 | rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0); |
| 1794 | if (rc < 0) |
| 1795 | GOTO(out, rc); |
| 1796 | GOTO(out, rc = 0); |
| 1797 | case IOC_OSC_SET_ACTIVE: |
| 1798 | rc = ptlrpc_set_import_active(imp, data->ioc_offset); |
| 1799 | GOTO(out, rc); |
| 1800 | case OBD_IOC_PARSE: { |
| 1801 | ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT); |
| 1802 | rc = class_config_parse_llog(NULL, ctxt, data->ioc_inlbuf1, |
| 1803 | NULL); |
| 1804 | llog_ctxt_put(ctxt); |
| 1805 | GOTO(out, rc); |
| 1806 | } |
| 1807 | case OBD_IOC_LLOG_INFO: |
| 1808 | case OBD_IOC_LLOG_PRINT: { |
| 1809 | ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT); |
| 1810 | rc = llog_ioctl(NULL, ctxt, cmd, data); |
| 1811 | llog_ctxt_put(ctxt); |
| 1812 | GOTO(out, rc); |
| 1813 | } |
| 1814 | case OBD_IOC_POLL_QUOTACHECK: |
| 1815 | rc = mdc_quota_poll_check(exp, (struct if_quotacheck *)karg); |
| 1816 | GOTO(out, rc); |
| 1817 | case OBD_IOC_PING_TARGET: |
| 1818 | rc = ptlrpc_obd_ping(obd); |
| 1819 | GOTO(out, rc); |
| 1820 | /* |
| 1821 | * Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by |
| 1822 | * LMV instead of MDC. But when the cluster is upgraded from 1.8, |
| 1823 | * there'd be no LMV layer thus we might be called here. Eventually |
| 1824 | * this code should be removed. |
| 1825 | * bz20731, LU-592. |
| 1826 | */ |
| 1827 | case IOC_OBD_STATFS: { |
| 1828 | struct obd_statfs stat_buf = {0}; |
| 1829 | |
| 1830 | if (*((__u32 *) data->ioc_inlbuf2) != 0) |
| 1831 | GOTO(out, rc = -ENODEV); |
| 1832 | |
| 1833 | /* copy UUID */ |
| 1834 | if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(obd), |
| 1835 | min((int) data->ioc_plen2, |
| 1836 | (int) sizeof(struct obd_uuid)))) |
| 1837 | GOTO(out, rc = -EFAULT); |
| 1838 | |
| 1839 | rc = mdc_statfs(NULL, obd->obd_self_export, &stat_buf, |
| 1840 | cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), |
| 1841 | 0); |
| 1842 | if (rc != 0) |
| 1843 | GOTO(out, rc); |
| 1844 | |
| 1845 | if (copy_to_user(data->ioc_pbuf1, &stat_buf, |
| 1846 | min((int) data->ioc_plen1, |
| 1847 | (int) sizeof(stat_buf)))) |
| 1848 | GOTO(out, rc = -EFAULT); |
| 1849 | |
| 1850 | GOTO(out, rc = 0); |
| 1851 | } |
| 1852 | case OBD_IOC_QUOTACTL: { |
| 1853 | struct if_quotactl *qctl = karg; |
| 1854 | struct obd_quotactl *oqctl; |
| 1855 | |
| 1856 | OBD_ALLOC_PTR(oqctl); |
John L. Hammond | c1f3d68 | 2013-11-26 10:04:59 +0800 | [diff] [blame] | 1857 | if (oqctl == NULL) |
| 1858 | GOTO(out, rc = -ENOMEM); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1859 | |
| 1860 | QCTL_COPY(oqctl, qctl); |
| 1861 | rc = obd_quotactl(exp, oqctl); |
| 1862 | if (rc == 0) { |
| 1863 | QCTL_COPY(qctl, oqctl); |
| 1864 | qctl->qc_valid = QC_MDTIDX; |
| 1865 | qctl->obd_uuid = obd->u.cli.cl_target_uuid; |
| 1866 | } |
John L. Hammond | c1f3d68 | 2013-11-26 10:04:59 +0800 | [diff] [blame] | 1867 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1868 | OBD_FREE_PTR(oqctl); |
John L. Hammond | c1f3d68 | 2013-11-26 10:04:59 +0800 | [diff] [blame] | 1869 | GOTO(out, rc); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1870 | } |
John L. Hammond | c1f3d68 | 2013-11-26 10:04:59 +0800 | [diff] [blame] | 1871 | case LL_IOC_GET_CONNECT_FLAGS: |
| 1872 | if (copy_to_user(uarg, exp_connect_flags_ptr(exp), |
| 1873 | sizeof(*exp_connect_flags_ptr(exp)))) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1874 | GOTO(out, rc = -EFAULT); |
John L. Hammond | c1f3d68 | 2013-11-26 10:04:59 +0800 | [diff] [blame] | 1875 | |
| 1876 | GOTO(out, rc = 0); |
| 1877 | case LL_IOC_LOV_SWAP_LAYOUTS: |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1878 | rc = mdc_ioc_swap_layouts(exp, karg); |
John L. Hammond | c1f3d68 | 2013-11-26 10:04:59 +0800 | [diff] [blame] | 1879 | GOTO(out, rc); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1880 | default: |
John L. Hammond | c1f3d68 | 2013-11-26 10:04:59 +0800 | [diff] [blame] | 1881 | CERROR("unrecognised ioctl: cmd = %#x\n", cmd); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1882 | GOTO(out, rc = -ENOTTY); |
| 1883 | } |
| 1884 | out: |
| 1885 | module_put(THIS_MODULE); |
| 1886 | |
| 1887 | return rc; |
| 1888 | } |
| 1889 | |
| 1890 | int mdc_get_info_rpc(struct obd_export *exp, |
| 1891 | obd_count keylen, void *key, |
| 1892 | int vallen, void *val) |
| 1893 | { |
| 1894 | struct obd_import *imp = class_exp2cliimp(exp); |
| 1895 | struct ptlrpc_request *req; |
| 1896 | char *tmp; |
| 1897 | int rc = -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1898 | |
| 1899 | req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO); |
| 1900 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1901 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1902 | |
| 1903 | req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY, |
| 1904 | RCL_CLIENT, keylen); |
| 1905 | req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN, |
| 1906 | RCL_CLIENT, sizeof(__u32)); |
| 1907 | |
| 1908 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO); |
| 1909 | if (rc) { |
| 1910 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1911 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY); |
| 1915 | memcpy(tmp, key, keylen); |
| 1916 | tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN); |
| 1917 | memcpy(tmp, &vallen, sizeof(__u32)); |
| 1918 | |
| 1919 | req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL, |
| 1920 | RCL_SERVER, vallen); |
| 1921 | ptlrpc_request_set_replen(req); |
| 1922 | |
| 1923 | rc = ptlrpc_queue_wait(req); |
| 1924 | /* -EREMOTE means the get_info result is partial, and it needs to |
| 1925 | * continue on another MDT, see fid2path part in lmv_iocontrol */ |
| 1926 | if (rc == 0 || rc == -EREMOTE) { |
| 1927 | tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL); |
| 1928 | memcpy(val, tmp, vallen); |
| 1929 | if (ptlrpc_rep_need_swab(req)) { |
| 1930 | if (KEY_IS(KEY_FID2PATH)) |
| 1931 | lustre_swab_fid2path(val); |
| 1932 | } |
| 1933 | } |
| 1934 | ptlrpc_req_finished(req); |
| 1935 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1936 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | static void lustre_swab_hai(struct hsm_action_item *h) |
| 1940 | { |
| 1941 | __swab32s(&h->hai_len); |
| 1942 | __swab32s(&h->hai_action); |
| 1943 | lustre_swab_lu_fid(&h->hai_fid); |
| 1944 | lustre_swab_lu_fid(&h->hai_dfid); |
| 1945 | __swab64s(&h->hai_cookie); |
| 1946 | __swab64s(&h->hai_extent.offset); |
| 1947 | __swab64s(&h->hai_extent.length); |
| 1948 | __swab64s(&h->hai_gid); |
| 1949 | } |
| 1950 | |
| 1951 | static void lustre_swab_hal(struct hsm_action_list *h) |
| 1952 | { |
| 1953 | struct hsm_action_item *hai; |
| 1954 | int i; |
| 1955 | |
| 1956 | __swab32s(&h->hal_version); |
| 1957 | __swab32s(&h->hal_count); |
| 1958 | __swab32s(&h->hal_archive_id); |
| 1959 | __swab64s(&h->hal_flags); |
| 1960 | hai = hai_zero(h); |
JC Lafoucriere | 18dfaeb | 2013-11-26 10:05:01 +0800 | [diff] [blame] | 1961 | for (i = 0; i < h->hal_count; i++, hai = hai_next(hai)) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1962 | lustre_swab_hai(hai); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | static void lustre_swab_kuch(struct kuc_hdr *l) |
| 1966 | { |
| 1967 | __swab16s(&l->kuc_magic); |
| 1968 | /* __u8 l->kuc_transport */ |
| 1969 | __swab16s(&l->kuc_msgtype); |
| 1970 | __swab16s(&l->kuc_msglen); |
| 1971 | } |
| 1972 | |
| 1973 | static int mdc_ioc_hsm_ct_start(struct obd_export *exp, |
| 1974 | struct lustre_kernelcomm *lk) |
| 1975 | { |
| 1976 | struct obd_import *imp = class_exp2cliimp(exp); |
| 1977 | __u32 archive = lk->lk_data; |
| 1978 | int rc = 0; |
| 1979 | |
| 1980 | if (lk->lk_group != KUC_GRP_HSM) { |
| 1981 | CERROR("Bad copytool group %d\n", lk->lk_group); |
| 1982 | return -EINVAL; |
| 1983 | } |
| 1984 | |
| 1985 | CDEBUG(D_HSM, "CT start r%d w%d u%d g%d f%#x\n", lk->lk_rfd, lk->lk_wfd, |
| 1986 | lk->lk_uid, lk->lk_group, lk->lk_flags); |
| 1987 | |
| 1988 | if (lk->lk_flags & LK_FLG_STOP) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1989 | /* Unregister with the coordinator */ |
Thomas Leibovici | 78eb9092 | 2013-07-25 01:17:24 +0800 | [diff] [blame] | 1990 | rc = mdc_ioc_hsm_ct_unregister(imp); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1991 | } else { |
Thomas Leibovici | 78eb9092 | 2013-07-25 01:17:24 +0800 | [diff] [blame] | 1992 | rc = mdc_ioc_hsm_ct_register(imp, archive); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | return rc; |
| 1996 | } |
| 1997 | |
| 1998 | /** |
| 1999 | * Send a message to any listening copytools |
| 2000 | * @param val KUC message (kuc_hdr + hsm_action_list) |
| 2001 | * @param len total length of message |
| 2002 | */ |
| 2003 | static int mdc_hsm_copytool_send(int len, void *val) |
| 2004 | { |
| 2005 | struct kuc_hdr *lh = (struct kuc_hdr *)val; |
| 2006 | struct hsm_action_list *hal = (struct hsm_action_list *)(lh + 1); |
| 2007 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2008 | |
| 2009 | if (len < sizeof(*lh) + sizeof(*hal)) { |
| 2010 | CERROR("Short HSM message %d < %d\n", len, |
| 2011 | (int) (sizeof(*lh) + sizeof(*hal))); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2012 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2013 | } |
| 2014 | if (lh->kuc_magic == __swab16(KUC_MAGIC)) { |
| 2015 | lustre_swab_kuch(lh); |
| 2016 | lustre_swab_hal(hal); |
| 2017 | } else if (lh->kuc_magic != KUC_MAGIC) { |
| 2018 | CERROR("Bad magic %x!=%x\n", lh->kuc_magic, KUC_MAGIC); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2019 | return -EPROTO; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | CDEBUG(D_HSM, " Received message mg=%x t=%d m=%d l=%d actions=%d " |
| 2023 | "on %s\n", |
| 2024 | lh->kuc_magic, lh->kuc_transport, lh->kuc_msgtype, |
| 2025 | lh->kuc_msglen, hal->hal_count, hal->hal_fsname); |
| 2026 | |
| 2027 | /* Broadcast to HSM listeners */ |
| 2028 | rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh); |
| 2029 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2030 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | /** |
| 2034 | * callback function passed to kuc for re-registering each HSM copytool |
| 2035 | * running on MDC, after MDT shutdown/recovery. |
| 2036 | * @param data archive id served by the copytool |
| 2037 | * @param cb_arg callback argument (obd_import) |
| 2038 | */ |
| 2039 | static int mdc_hsm_ct_reregister(__u32 data, void *cb_arg) |
| 2040 | { |
| 2041 | struct obd_import *imp = (struct obd_import *)cb_arg; |
| 2042 | __u32 archive = data; |
| 2043 | int rc; |
| 2044 | |
| 2045 | CDEBUG(D_HA, "recover copytool registration to MDT (archive=%#x)\n", |
| 2046 | archive); |
| 2047 | rc = mdc_ioc_hsm_ct_register(imp, archive); |
| 2048 | |
| 2049 | /* ignore error if the copytool is already registered */ |
| 2050 | return ((rc != 0) && (rc != -EEXIST)) ? rc : 0; |
| 2051 | } |
| 2052 | |
| 2053 | /** |
| 2054 | * Re-establish all kuc contexts with MDT |
| 2055 | * after MDT shutdown/recovery. |
| 2056 | */ |
| 2057 | static int mdc_kuc_reregister(struct obd_import *imp) |
| 2058 | { |
| 2059 | /* re-register HSM agents */ |
| 2060 | return libcfs_kkuc_group_foreach(KUC_GRP_HSM, mdc_hsm_ct_reregister, |
| 2061 | (void *)imp); |
| 2062 | } |
| 2063 | |
| 2064 | int mdc_set_info_async(const struct lu_env *env, |
| 2065 | struct obd_export *exp, |
| 2066 | obd_count keylen, void *key, |
| 2067 | obd_count vallen, void *val, |
| 2068 | struct ptlrpc_request_set *set) |
| 2069 | { |
| 2070 | struct obd_import *imp = class_exp2cliimp(exp); |
| 2071 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2072 | |
| 2073 | if (KEY_IS(KEY_READ_ONLY)) { |
| 2074 | if (vallen != sizeof(int)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2075 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2076 | |
| 2077 | spin_lock(&imp->imp_lock); |
| 2078 | if (*((int *)val)) { |
| 2079 | imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY; |
| 2080 | imp->imp_connect_data.ocd_connect_flags |= |
| 2081 | OBD_CONNECT_RDONLY; |
| 2082 | } else { |
| 2083 | imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY; |
| 2084 | imp->imp_connect_data.ocd_connect_flags &= |
| 2085 | ~OBD_CONNECT_RDONLY; |
| 2086 | } |
| 2087 | spin_unlock(&imp->imp_lock); |
| 2088 | |
| 2089 | rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION, |
| 2090 | keylen, key, vallen, val, set); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2091 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2092 | } |
| 2093 | if (KEY_IS(KEY_SPTLRPC_CONF)) { |
| 2094 | sptlrpc_conf_client_adapt(exp->exp_obd); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2095 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2096 | } |
| 2097 | if (KEY_IS(KEY_FLUSH_CTX)) { |
| 2098 | sptlrpc_import_flush_my_ctx(imp); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2099 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2100 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2101 | if (KEY_IS(KEY_CHANGELOG_CLEAR)) { |
| 2102 | rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION, |
| 2103 | keylen, key, vallen, val, set); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2104 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2105 | } |
| 2106 | if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) { |
| 2107 | rc = mdc_hsm_copytool_send(vallen, val); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2108 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | CERROR("Unknown key %s\n", (char *)key); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2112 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | int mdc_get_info(const struct lu_env *env, struct obd_export *exp, |
| 2116 | __u32 keylen, void *key, __u32 *vallen, void *val, |
| 2117 | struct lov_stripe_md *lsm) |
| 2118 | { |
| 2119 | int rc = -EINVAL; |
| 2120 | |
| 2121 | if (KEY_IS(KEY_MAX_EASIZE)) { |
| 2122 | int mdsize, *max_easize; |
| 2123 | |
| 2124 | if (*vallen != sizeof(int)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2125 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2126 | mdsize = *(int*)val; |
| 2127 | if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize) |
| 2128 | exp->exp_obd->u.cli.cl_max_mds_easize = mdsize; |
| 2129 | max_easize = val; |
| 2130 | *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2131 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2132 | } else if (KEY_IS(KEY_CONN_DATA)) { |
| 2133 | struct obd_import *imp = class_exp2cliimp(exp); |
| 2134 | struct obd_connect_data *data = val; |
| 2135 | |
| 2136 | if (*vallen != sizeof(*data)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2137 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2138 | |
| 2139 | *data = imp->imp_connect_data; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2140 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2141 | } else if (KEY_IS(KEY_TGT_COUNT)) { |
| 2142 | *((int *)val) = 1; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2143 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val); |
| 2147 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2148 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid, |
| 2152 | struct obd_capa *oc, struct obd_client_handle *handle, |
| 2153 | int flags) |
| 2154 | { |
| 2155 | struct ptlrpc_request *req; |
| 2156 | struct mdt_body *body; |
| 2157 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2158 | |
| 2159 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN); |
| 2160 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2161 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2162 | |
| 2163 | mdc_set_capa_size(req, &RMF_CAPA1, oc); |
| 2164 | |
| 2165 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN); |
| 2166 | if (rc) { |
| 2167 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2168 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | mdc_pack_body(req, fid, oc, 0, 0, -1, flags); |
| 2172 | |
| 2173 | ptlrpc_request_set_replen(req); |
| 2174 | |
| 2175 | mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); |
| 2176 | rc = ptlrpc_queue_wait(req); |
| 2177 | mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); |
| 2178 | if (rc) { |
| 2179 | CERROR("Pin failed: %d\n", rc); |
| 2180 | GOTO(err_out, rc); |
| 2181 | } |
| 2182 | |
| 2183 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); |
| 2184 | if (body == NULL) |
| 2185 | GOTO(err_out, rc = -EPROTO); |
| 2186 | |
| 2187 | handle->och_fh = body->handle; |
| 2188 | handle->och_magic = OBD_CLIENT_HANDLE_MAGIC; |
| 2189 | |
| 2190 | handle->och_mod = obd_mod_alloc(); |
| 2191 | if (handle->och_mod == NULL) { |
| 2192 | DEBUG_REQ(D_ERROR, req, "can't allocate md_open_data"); |
| 2193 | GOTO(err_out, rc = -ENOMEM); |
| 2194 | } |
| 2195 | handle->och_mod->mod_open_req = req; /* will be dropped by unpin */ |
| 2196 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2197 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2198 | |
| 2199 | err_out: |
| 2200 | ptlrpc_req_finished(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2201 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle, |
| 2205 | int flag) |
| 2206 | { |
| 2207 | struct ptlrpc_request *req; |
| 2208 | struct mdt_body *body; |
| 2209 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2210 | |
| 2211 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN, |
| 2212 | LUSTRE_MDS_VERSION, MDS_UNPIN); |
| 2213 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2214 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2215 | |
| 2216 | body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY); |
| 2217 | body->handle = handle->och_fh; |
| 2218 | body->flags = flag; |
| 2219 | |
| 2220 | ptlrpc_request_set_replen(req); |
| 2221 | |
| 2222 | mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); |
| 2223 | rc = ptlrpc_queue_wait(req); |
| 2224 | mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); |
| 2225 | |
| 2226 | if (rc != 0) |
| 2227 | CERROR("Unpin failed: %d\n", rc); |
| 2228 | |
| 2229 | ptlrpc_req_finished(req); |
| 2230 | ptlrpc_req_finished(handle->och_mod->mod_open_req); |
| 2231 | |
| 2232 | obd_mod_put(handle->och_mod); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2233 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | int mdc_sync(struct obd_export *exp, const struct lu_fid *fid, |
| 2237 | struct obd_capa *oc, struct ptlrpc_request **request) |
| 2238 | { |
| 2239 | struct ptlrpc_request *req; |
| 2240 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2241 | |
| 2242 | *request = NULL; |
| 2243 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC); |
| 2244 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2245 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2246 | |
| 2247 | mdc_set_capa_size(req, &RMF_CAPA1, oc); |
| 2248 | |
| 2249 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC); |
| 2250 | if (rc) { |
| 2251 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2252 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | mdc_pack_body(req, fid, oc, 0, 0, -1, 0); |
| 2256 | |
| 2257 | ptlrpc_request_set_replen(req); |
| 2258 | |
| 2259 | rc = ptlrpc_queue_wait(req); |
| 2260 | if (rc) |
| 2261 | ptlrpc_req_finished(req); |
| 2262 | else |
| 2263 | *request = req; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2264 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | static int mdc_import_event(struct obd_device *obd, struct obd_import *imp, |
| 2268 | enum obd_import_event event) |
| 2269 | { |
| 2270 | int rc = 0; |
| 2271 | |
| 2272 | LASSERT(imp->imp_obd == obd); |
| 2273 | |
| 2274 | switch (event) { |
| 2275 | case IMP_EVENT_DISCON: { |
| 2276 | #if 0 |
| 2277 | /* XXX Pass event up to OBDs stack. used only for FLD now */ |
| 2278 | rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL); |
| 2279 | #endif |
| 2280 | break; |
| 2281 | } |
| 2282 | case IMP_EVENT_INACTIVE: { |
| 2283 | struct client_obd *cli = &obd->u.cli; |
| 2284 | /* |
| 2285 | * Flush current sequence to make client obtain new one |
| 2286 | * from server in case of disconnect/reconnect. |
| 2287 | */ |
| 2288 | if (cli->cl_seq != NULL) |
| 2289 | seq_client_flush(cli->cl_seq); |
| 2290 | |
| 2291 | rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL); |
| 2292 | break; |
| 2293 | } |
| 2294 | case IMP_EVENT_INVALIDATE: { |
| 2295 | struct ldlm_namespace *ns = obd->obd_namespace; |
| 2296 | |
| 2297 | ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY); |
| 2298 | |
| 2299 | break; |
| 2300 | } |
| 2301 | case IMP_EVENT_ACTIVE: |
| 2302 | rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL); |
Thomas Leibovici | 78eb9092 | 2013-07-25 01:17:24 +0800 | [diff] [blame] | 2303 | /* redo the kuc registration after reconnecting */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2304 | if (rc == 0) |
| 2305 | rc = mdc_kuc_reregister(imp); |
| 2306 | break; |
| 2307 | case IMP_EVENT_OCD: |
| 2308 | rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL); |
| 2309 | break; |
| 2310 | case IMP_EVENT_DEACTIVATE: |
| 2311 | case IMP_EVENT_ACTIVATE: |
| 2312 | break; |
| 2313 | default: |
| 2314 | CERROR("Unknown import event %x\n", event); |
| 2315 | LBUG(); |
| 2316 | } |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2317 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid, |
| 2321 | struct md_op_data *op_data) |
| 2322 | { |
| 2323 | struct client_obd *cli = &exp->exp_obd->u.cli; |
| 2324 | struct lu_client_seq *seq = cli->cl_seq; |
Greg Kroah-Hartman | 29aaf49 | 2013-08-02 18:14:51 +0800 | [diff] [blame] | 2325 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2326 | return seq_client_alloc_fid(NULL, seq, fid); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | struct obd_uuid *mdc_get_uuid(struct obd_export *exp) { |
| 2330 | struct client_obd *cli = &exp->exp_obd->u.cli; |
| 2331 | return &cli->cl_target_uuid; |
| 2332 | } |
| 2333 | |
| 2334 | /** |
| 2335 | * Determine whether the lock can be canceled before replaying it during |
| 2336 | * recovery, non zero value will be return if the lock can be canceled, |
| 2337 | * or zero returned for not |
| 2338 | */ |
| 2339 | static int mdc_cancel_for_recovery(struct ldlm_lock *lock) |
| 2340 | { |
| 2341 | if (lock->l_resource->lr_type != LDLM_IBITS) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2342 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2343 | |
| 2344 | /* FIXME: if we ever get into a situation where there are too many |
| 2345 | * opened files with open locks on a single node, then we really |
| 2346 | * should replay these open locks to reget it */ |
| 2347 | if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_OPEN) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2348 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2349 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2350 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | static int mdc_resource_inode_free(struct ldlm_resource *res) |
| 2354 | { |
| 2355 | if (res->lr_lvb_inode) |
| 2356 | res->lr_lvb_inode = NULL; |
| 2357 | |
| 2358 | return 0; |
| 2359 | } |
| 2360 | |
| 2361 | struct ldlm_valblock_ops inode_lvbo = { |
Emil Goode | 805e517 | 2013-07-28 00:38:56 +0200 | [diff] [blame] | 2362 | .lvbo_free = mdc_resource_inode_free, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2363 | }; |
| 2364 | |
| 2365 | static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg) |
| 2366 | { |
| 2367 | struct client_obd *cli = &obd->u.cli; |
| 2368 | struct lprocfs_static_vars lvars = { 0 }; |
| 2369 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2370 | |
| 2371 | OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock)); |
| 2372 | if (!cli->cl_rpc_lock) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2373 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2374 | mdc_init_rpc_lock(cli->cl_rpc_lock); |
| 2375 | |
| 2376 | ptlrpcd_addref(); |
| 2377 | |
| 2378 | OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock)); |
| 2379 | if (!cli->cl_close_lock) |
| 2380 | GOTO(err_rpc_lock, rc = -ENOMEM); |
| 2381 | mdc_init_rpc_lock(cli->cl_close_lock); |
| 2382 | |
| 2383 | rc = client_obd_setup(obd, cfg); |
| 2384 | if (rc) |
| 2385 | GOTO(err_close_lock, rc); |
| 2386 | lprocfs_mdc_init_vars(&lvars); |
| 2387 | lprocfs_obd_setup(obd, lvars.obd_vars); |
| 2388 | sptlrpc_lprocfs_cliobd_attach(obd); |
| 2389 | ptlrpc_lprocfs_register_obd(obd); |
| 2390 | |
| 2391 | ns_register_cancel(obd->obd_namespace, mdc_cancel_for_recovery); |
| 2392 | |
| 2393 | obd->obd_namespace->ns_lvbo = &inode_lvbo; |
| 2394 | |
| 2395 | rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL); |
| 2396 | if (rc) { |
| 2397 | mdc_cleanup(obd); |
| 2398 | CERROR("failed to setup llogging subsystems\n"); |
| 2399 | } |
| 2400 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2401 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2402 | |
| 2403 | err_close_lock: |
| 2404 | OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock)); |
| 2405 | err_rpc_lock: |
| 2406 | OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock)); |
| 2407 | ptlrpcd_decref(); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2408 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | /* Initialize the default and maximum LOV EA and cookie sizes. This allows |
| 2412 | * us to make MDS RPCs with large enough reply buffers to hold the |
| 2413 | * maximum-sized (= maximum striped) EA and cookie without having to |
| 2414 | * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */ |
| 2415 | static int mdc_init_ea_size(struct obd_export *exp, int easize, |
| 2416 | int def_easize, int cookiesize) |
| 2417 | { |
| 2418 | struct obd_device *obd = exp->exp_obd; |
| 2419 | struct client_obd *cli = &obd->u.cli; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2420 | |
| 2421 | if (cli->cl_max_mds_easize < easize) |
| 2422 | cli->cl_max_mds_easize = easize; |
| 2423 | |
| 2424 | if (cli->cl_default_mds_easize < def_easize) |
| 2425 | cli->cl_default_mds_easize = def_easize; |
| 2426 | |
| 2427 | if (cli->cl_max_mds_cookiesize < cookiesize) |
| 2428 | cli->cl_max_mds_cookiesize = cookiesize; |
| 2429 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2430 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage) |
| 2434 | { |
| 2435 | int rc = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2436 | |
| 2437 | switch (stage) { |
| 2438 | case OBD_CLEANUP_EARLY: |
| 2439 | break; |
| 2440 | case OBD_CLEANUP_EXPORTS: |
| 2441 | /* Failsafe, ok if racy */ |
| 2442 | if (obd->obd_type->typ_refcnt <= 1) |
| 2443 | libcfs_kkuc_group_rem(0, KUC_GRP_HSM); |
| 2444 | |
| 2445 | obd_cleanup_client_import(obd); |
| 2446 | ptlrpc_lprocfs_unregister_obd(obd); |
| 2447 | lprocfs_obd_cleanup(obd); |
| 2448 | |
| 2449 | rc = obd_llog_finish(obd, 0); |
| 2450 | if (rc != 0) |
| 2451 | CERROR("failed to cleanup llogging subsystems\n"); |
| 2452 | break; |
| 2453 | } |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2454 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | static int mdc_cleanup(struct obd_device *obd) |
| 2458 | { |
| 2459 | struct client_obd *cli = &obd->u.cli; |
| 2460 | |
| 2461 | OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock)); |
| 2462 | OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock)); |
| 2463 | |
| 2464 | ptlrpcd_decref(); |
| 2465 | |
| 2466 | return client_obd_cleanup(obd); |
| 2467 | } |
| 2468 | |
| 2469 | |
| 2470 | static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg, |
| 2471 | struct obd_device *tgt, int *index) |
| 2472 | { |
| 2473 | struct llog_ctxt *ctxt; |
| 2474 | int rc; |
| 2475 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2476 | LASSERT(olg == &obd->obd_olg); |
| 2477 | |
| 2478 | rc = llog_setup(NULL, obd, olg, LLOG_CHANGELOG_REPL_CTXT, tgt, |
| 2479 | &llog_client_ops); |
| 2480 | if (rc) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2481 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2482 | |
| 2483 | ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT); |
| 2484 | llog_initiator_connect(ctxt); |
| 2485 | llog_ctxt_put(ctxt); |
| 2486 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2487 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | static int mdc_llog_finish(struct obd_device *obd, int count) |
| 2491 | { |
| 2492 | struct llog_ctxt *ctxt; |
| 2493 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2494 | ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT); |
| 2495 | if (ctxt) |
| 2496 | llog_cleanup(NULL, ctxt); |
| 2497 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2498 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf) |
| 2502 | { |
| 2503 | struct lustre_cfg *lcfg = buf; |
| 2504 | struct lprocfs_static_vars lvars = { 0 }; |
| 2505 | int rc = 0; |
| 2506 | |
| 2507 | lprocfs_mdc_init_vars(&lvars); |
| 2508 | switch (lcfg->lcfg_command) { |
| 2509 | default: |
| 2510 | rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars, |
| 2511 | lcfg, obd); |
| 2512 | if (rc > 0) |
| 2513 | rc = 0; |
| 2514 | break; |
| 2515 | } |
| 2516 | return(rc); |
| 2517 | } |
| 2518 | |
| 2519 | |
| 2520 | /* get remote permission for current user on fid */ |
| 2521 | int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid, |
| 2522 | struct obd_capa *oc, __u32 suppgid, |
| 2523 | struct ptlrpc_request **request) |
| 2524 | { |
| 2525 | struct ptlrpc_request *req; |
| 2526 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2527 | |
| 2528 | LASSERT(client_is_remote(exp)); |
| 2529 | |
| 2530 | *request = NULL; |
| 2531 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR); |
| 2532 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2533 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2534 | |
| 2535 | mdc_set_capa_size(req, &RMF_CAPA1, oc); |
| 2536 | |
| 2537 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR); |
| 2538 | if (rc) { |
| 2539 | ptlrpc_request_free(req); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2540 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0); |
| 2544 | |
| 2545 | req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER, |
| 2546 | sizeof(struct mdt_remote_perm)); |
| 2547 | |
| 2548 | ptlrpc_request_set_replen(req); |
| 2549 | |
| 2550 | rc = ptlrpc_queue_wait(req); |
| 2551 | if (rc) |
| 2552 | ptlrpc_req_finished(req); |
| 2553 | else |
| 2554 | *request = req; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2555 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | static int mdc_interpret_renew_capa(const struct lu_env *env, |
| 2559 | struct ptlrpc_request *req, void *args, |
| 2560 | int status) |
| 2561 | { |
| 2562 | struct mdc_renew_capa_args *ra = args; |
| 2563 | struct mdt_body *body = NULL; |
| 2564 | struct lustre_capa *capa; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2565 | |
| 2566 | if (status) |
| 2567 | GOTO(out, capa = ERR_PTR(status)); |
| 2568 | |
| 2569 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); |
| 2570 | if (body == NULL) |
| 2571 | GOTO(out, capa = ERR_PTR(-EFAULT)); |
| 2572 | |
| 2573 | if ((body->valid & OBD_MD_FLOSSCAPA) == 0) |
| 2574 | GOTO(out, capa = ERR_PTR(-ENOENT)); |
| 2575 | |
| 2576 | capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2); |
| 2577 | if (!capa) |
| 2578 | GOTO(out, capa = ERR_PTR(-EFAULT)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2579 | out: |
| 2580 | ra->ra_cb(ra->ra_oc, capa); |
| 2581 | return 0; |
| 2582 | } |
| 2583 | |
| 2584 | static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc, |
| 2585 | renew_capa_cb_t cb) |
| 2586 | { |
| 2587 | struct ptlrpc_request *req; |
| 2588 | struct mdc_renew_capa_args *ra; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2589 | |
| 2590 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR, |
| 2591 | LUSTRE_MDS_VERSION, MDS_GETATTR); |
| 2592 | if (req == NULL) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2593 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2594 | |
| 2595 | /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the |
| 2596 | * capa to renew is oss capa. |
| 2597 | */ |
| 2598 | mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0); |
| 2599 | ptlrpc_request_set_replen(req); |
| 2600 | |
| 2601 | CLASSERT(sizeof(*ra) <= sizeof(req->rq_async_args)); |
| 2602 | ra = ptlrpc_req_async_args(req); |
| 2603 | ra->ra_oc = oc; |
| 2604 | ra->ra_cb = cb; |
| 2605 | req->rq_interpret_reply = mdc_interpret_renew_capa; |
| 2606 | ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2607 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2608 | } |
| 2609 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2610 | struct obd_ops mdc_obd_ops = { |
| 2611 | .o_owner = THIS_MODULE, |
| 2612 | .o_setup = mdc_setup, |
| 2613 | .o_precleanup = mdc_precleanup, |
| 2614 | .o_cleanup = mdc_cleanup, |
| 2615 | .o_add_conn = client_import_add_conn, |
| 2616 | .o_del_conn = client_import_del_conn, |
Mikhail Pershin | a7c6d5a | 2013-12-09 22:56:56 +0800 | [diff] [blame] | 2617 | .o_connect = client_connect_import, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2618 | .o_disconnect = client_disconnect_export, |
| 2619 | .o_iocontrol = mdc_iocontrol, |
| 2620 | .o_set_info_async = mdc_set_info_async, |
| 2621 | .o_statfs = mdc_statfs, |
| 2622 | .o_pin = mdc_pin, |
| 2623 | .o_unpin = mdc_unpin, |
| 2624 | .o_fid_init = client_fid_init, |
| 2625 | .o_fid_fini = client_fid_fini, |
| 2626 | .o_fid_alloc = mdc_fid_alloc, |
| 2627 | .o_import_event = mdc_import_event, |
| 2628 | .o_llog_init = mdc_llog_init, |
| 2629 | .o_llog_finish = mdc_llog_finish, |
| 2630 | .o_get_info = mdc_get_info, |
| 2631 | .o_process_config = mdc_process_config, |
| 2632 | .o_get_uuid = mdc_get_uuid, |
| 2633 | .o_quotactl = mdc_quotactl, |
| 2634 | .o_quotacheck = mdc_quotacheck |
| 2635 | }; |
| 2636 | |
| 2637 | struct md_ops mdc_md_ops = { |
| 2638 | .m_getstatus = mdc_getstatus, |
| 2639 | .m_null_inode = mdc_null_inode, |
| 2640 | .m_find_cbdata = mdc_find_cbdata, |
| 2641 | .m_close = mdc_close, |
| 2642 | .m_create = mdc_create, |
| 2643 | .m_done_writing = mdc_done_writing, |
| 2644 | .m_enqueue = mdc_enqueue, |
| 2645 | .m_getattr = mdc_getattr, |
| 2646 | .m_getattr_name = mdc_getattr_name, |
| 2647 | .m_intent_lock = mdc_intent_lock, |
| 2648 | .m_link = mdc_link, |
| 2649 | .m_is_subdir = mdc_is_subdir, |
| 2650 | .m_rename = mdc_rename, |
| 2651 | .m_setattr = mdc_setattr, |
| 2652 | .m_setxattr = mdc_setxattr, |
| 2653 | .m_getxattr = mdc_getxattr, |
| 2654 | .m_sync = mdc_sync, |
| 2655 | .m_readpage = mdc_readpage, |
| 2656 | .m_unlink = mdc_unlink, |
| 2657 | .m_cancel_unused = mdc_cancel_unused, |
| 2658 | .m_init_ea_size = mdc_init_ea_size, |
| 2659 | .m_set_lock_data = mdc_set_lock_data, |
| 2660 | .m_lock_match = mdc_lock_match, |
| 2661 | .m_get_lustre_md = mdc_get_lustre_md, |
| 2662 | .m_free_lustre_md = mdc_free_lustre_md, |
| 2663 | .m_set_open_replay_data = mdc_set_open_replay_data, |
| 2664 | .m_clear_open_replay_data = mdc_clear_open_replay_data, |
| 2665 | .m_renew_capa = mdc_renew_capa, |
| 2666 | .m_unpack_capa = mdc_unpack_capa, |
| 2667 | .m_get_remote_perm = mdc_get_remote_perm, |
| 2668 | .m_intent_getattr_async = mdc_intent_getattr_async, |
| 2669 | .m_revalidate_lock = mdc_revalidate_lock |
| 2670 | }; |
| 2671 | |
| 2672 | int __init mdc_init(void) |
| 2673 | { |
| 2674 | int rc; |
| 2675 | struct lprocfs_static_vars lvars = { 0 }; |
| 2676 | lprocfs_mdc_init_vars(&lvars); |
| 2677 | |
| 2678 | rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars, |
| 2679 | LUSTRE_MDC_NAME, NULL); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 2680 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | static void /*__exit*/ mdc_exit(void) |
| 2684 | { |
| 2685 | class_unregister_type(LUSTRE_MDC_NAME); |
| 2686 | } |
| 2687 | |
| 2688 | MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); |
| 2689 | MODULE_DESCRIPTION("Lustre Metadata Client"); |
| 2690 | MODULE_LICENSE("GPL"); |
| 2691 | |
| 2692 | module_init(mdc_init); |
| 2693 | module_exit(mdc_exit); |