1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/mdt/mdt_reint.c
5 * Lustre Metadata Target (mdt) reintegration routines
7 * Copyright (C) 2002-2006 Cluster File Systems, Inc.
8 * Author: Peter Braam <braam@clusterfs.com>
9 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * Author: Phil Schwan <phil@clusterfs.com>
11 * Author: Huang Hua <huanghua@clusterfs.com>
13 * This file is part of the Lustre file system, http://www.lustre.org
14 * Lustre is a trademark of Cluster File Systems, Inc.
16 * You may have signed or agreed to another license before downloading
17 * this software. If so, you are bound by the terms and conditions
18 * of that agreement, and the following does not apply to you. See the
19 * LICENSE file included with this distribution for more information.
21 * If you did not agree to a different license, then this copy of Lustre
22 * is open source software; you can redistribute it and/or modify it
23 * under the terms of version 2 of the GNU General Public License as
24 * published by the Free Software Foundation.
26 * In either case, Lustre is distributed in the hope that it will be
27 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
28 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * license text for more details.
33 # define EXPORT_SYMTAB
35 #define DEBUG_SUBSYSTEM S_MDS
37 #include "mdt_internal.h"
40 /* return EADATA length to the caller. negative value means error */
41 static int mdt_getxattr_pack_reply(struct mdt_thread_info * info)
44 int rc = -EOPNOTSUPP, rc2;
45 struct req_capsule *pill;
46 struct ptlrpc_request *req = mdt_info_req(info);
48 pill = &info->mti_pill;
50 /* Imagine how many bytes we need */
51 if (info->mti_body->valid & OBD_MD_FLXATTR) {
52 xattr_name = req_capsule_client_get(pill, &RMF_NAME);
54 CERROR("can't extract xattr name for getxattr\n");
58 if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_XATTR) &&
59 (strncmp(xattr_name, "user.", 5) == 0))
62 rc = mo_xattr_get(info->mti_ctxt,
63 mdt_object_child(info->mti_object),
65 } else if (info->mti_body->valid & OBD_MD_FLXATTRLS) {
66 rc = mo_xattr_list(info->mti_ctxt,
67 mdt_object_child(info->mti_object),
70 CERROR("valid bits: "LPX64"\n", info->mti_body->valid);
75 if (rc != -ENODATA && rc != -EOPNOTSUPP)
76 CWARN("get EA size error: %d\n", rc);
77 /* return empty to client */
78 req_capsule_extend(&info->mti_pill, &RQF_MDS_SETXATTR);
80 rc = min_t(int, info->mti_body->eadatasize, rc);
81 req_capsule_set_size(pill, &RMF_EADATA, RCL_SERVER, rc);
84 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETXATTR_PACK)) {
85 CERROR("failed MDS_GETXATTR_PACK test\n");
86 req->rq_status = -ENOMEM;
90 rc2 = req_capsule_pack(pill);
97 int mdt_getxattr(struct mdt_thread_info *info)
100 struct md_object *next;
103 struct mdt_body *rep_body;
107 LASSERT(info->mti_object != NULL);
108 LASSERT(lu_object_exists(info->mti_ctxt,
109 &info->mti_object->mot_obj.mo_lu));
112 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETXATTR_PACK)) {
113 CERROR(LUSTRE_MDT0_NAME": getxattr lustre_pack_reply failed\n");
114 RETURN(rc = -ENOMEM);
117 next = mdt_object_child(info->mti_object);
119 buflen = mdt_getxattr_pack_reply(info);
122 buf = req_capsule_server_get(&info->mti_pill,
124 rep_body = req_capsule_server_get(&info->mti_pill,
127 if (info->mti_body->valid & OBD_MD_FLXATTR) {
128 char *xattr_name = req_capsule_client_get(&info->mti_pill,
130 CDEBUG(S_MDS, "getxattr %s\n", xattr_name);
132 rc = mo_xattr_get(info->mti_ctxt, next,
133 buf, buflen, xattr_name);
135 if (rc < 0 && rc != -ENODATA && rc != -EOPNOTSUPP &&
137 CDEBUG(S_MDS, "getxattr failed: %d\n", rc);
138 } else if (info->mti_body->valid & OBD_MD_FLXATTRLS) {
139 CDEBUG(S_MDS, "listxattr\n");
141 rc = mo_xattr_list(info->mti_ctxt, next, buf, buflen);
143 CDEBUG(D_OTHER, "listxattr failed: %d\n", rc);
148 rep_body->eadatasize = rc;
157 int mdt_setxattr(struct mdt_thread_info *info)
162 struct ptlrpc_request *req = mdt_info_req(info);
164 struct mdt_lock_handle *lh;
167 lh = &info->mti_lh[MDT_LH_PARENT];
168 lh->mlh_mode = LCK_EX;
170 /* if (req->rq_reqmsg->bufcount < 2)
173 DEBUG_REQ(D_INODE, req, "setxattr "DFID3"\n",
174 PFID3(&info->mti_body->fid1));
176 /* MDS_CHECK_RESENT(req, mds_reconstruct_generic(req)); */
178 lockpart = MDS_INODELOCK_UPDATE;
180 /* various sanity check for xattr name */
181 xattr_name = req_capsule_client_get(&info->mti_pill, &RMF_NAME);
183 CERROR("can't extract xattr name\n");
184 GOTO(out, rc = -EPROTO);
187 CDEBUG(D_INODE, "%sxattr %s\n",
188 info->mti_body->valid & OBD_MD_FLXATTR ? "set" : "remove",
191 if (strncmp(xattr_name, "trusted.", 8) == 0) {
192 if (strcmp(xattr_name + 8, "lov") == 0)
193 GOTO(out, rc = -EACCES);
196 if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_XATTR) &&
197 (strncmp(xattr_name, "user.", 5) == 0)) {
198 GOTO(out, rc = -EOPNOTSUPP);
201 if (!strcmp(xattr_name, XATTR_NAME_ACL_ACCESS))
202 lockpart |= MDS_INODELOCK_LOOKUP;
204 rc = mdt_object_lock(info->mti_mdt->mdt_namespace, info->mti_object,
210 if (info->mti_body->valid & OBD_MD_FLXATTR) {
212 if (!req_capsule_field_present(&info->mti_pill, &RMF_EADATA)) {
213 CERROR("no xattr data supplied\n");
214 GOTO(out_unlock, rc = -EFAULT);
217 xattr_len = req_capsule_get_size(&info->mti_pill,
218 &RMF_EADATA, RCL_CLIENT);
220 xattr = req_capsule_client_get(&info->mti_pill,
223 rc = mo_xattr_set(info->mti_ctxt,
224 mdt_object_child(info->mti_object),
225 xattr, xattr_len, xattr_name);
227 } else if (info->mti_body->valid & OBD_MD_FLXATTRRM) {
228 rc = mo_xattr_del(info->mti_ctxt,
229 mdt_object_child(info->mti_object),
232 CERROR("valid bits: "LPX64"\n", info->mti_body->valid);
237 mdt_object_unlock(info->mti_mdt->mdt_namespace,
238 info->mti_object, lh);