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