4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2017, Intel Corporation.
26 * lustre/mdt/mdt_som.c
30 * Author: Jinshan Xiong <jinshan.xiong@intel.com>
33 #define DEBUG_SUBSYSTEM S_MDS
35 #include "mdt_internal.h"
37 int mdt_get_som(struct mdt_thread_info *info, struct mdt_object *obj,
40 struct lu_buf *buf = &info->mti_buf;
41 struct lustre_som_attrs *som;
44 som = buf->lb_buf = info->mti_xattr_buf;
45 buf->lb_len = sizeof(info->mti_xattr_buf);
46 rc = mo_xattr_get(info->mti_env, mdt_object_child(obj), buf,
48 if (rc >= (int)sizeof(*som) && (som->lsa_valid & LSOM_FL_VALID)) {
49 attr->la_valid |= LA_SIZE | LA_BLOCKS;
50 attr->la_size = som->lsa_size;
51 attr->la_blocks = som->lsa_blocks;
53 /* Size on MDS is valid and could be returned to client */
54 info->mti_som_valid = 1;
56 CDEBUG(D_INODE, DFID": Reading som attrs: "
57 "valid: %x, size: %lld, blocks: %lld, rc: %d.\n",
58 PFID(mdt_object_fid(obj)), som->lsa_valid,
59 som->lsa_size, som->lsa_blocks, rc);
62 return (rc > 0 || rc == -ENODATA) ? 0 : rc;
65 int mdt_set_som(struct mdt_thread_info *info, struct mdt_object *obj,
68 struct md_object *next = mdt_object_child(obj);
69 struct lu_buf *buf = &info->mti_buf;
70 struct lustre_som_attrs *som;
74 buf->lb_buf = info->mti_xattr_buf;
75 buf->lb_len = sizeof(info->mti_xattr_buf);
76 rc = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_SOM);
77 if (rc < 0 && rc != -ENODATA)
83 DFID": Set som attrs: S/B: %lld/%lld to %lld/%lld, rc: %d\n",
84 PFID(mdt_object_fid(obj)), som->lsa_size, som->lsa_blocks,
85 attr->la_size, attr->la_blocks, rc);
88 memset(som, 0, sizeof(*som));
89 if (attr->la_valid & (LA_SIZE | LA_BLOCKS)) {
90 som->lsa_valid |= LSOM_FL_VALID;
91 som->lsa_size = attr->la_size;
92 som->lsa_blocks = attr->la_blocks;
94 buf->lb_len = sizeof(*som);
95 rc = mo_xattr_set(info->mti_env, next, buf, XATTR_NAME_SOM, 0);