Whamcloud - gitweb
LU-9771 flr: resync support and test tool
[fs/lustre-release.git] / lustre / mdt / mdt_som.c
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,
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.
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2017, Intel Corporation.
24  */
25 /*
26  * lustre/mdt/mdt_som.c
27  *
28  * Size on MDS revival
29  *
30  * Author: Jinshan Xiong <jinshan.xiong@intel.com>
31  */
32
33 #define DEBUG_SUBSYSTEM S_MDS
34
35 #include "mdt_internal.h"
36
37 int mdt_get_som(struct mdt_thread_info *info, struct mdt_object *obj,
38                 struct lu_attr *attr)
39 {
40         struct lu_buf *buf = &info->mti_buf;
41         struct lustre_som_attrs *som;
42         int rc;
43
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,
47                           XATTR_NAME_SOM);
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;
52
53                 /* Size on MDS is valid and could be returned to client */
54                 info->mti_som_valid = 1;
55
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);
60         }
61
62         return (rc > 0 || rc == -ENODATA) ? 0 : rc;
63 }
64
65 int mdt_set_som(struct mdt_thread_info *info, struct mdt_object *obj,
66                 struct lu_attr *attr)
67 {
68         struct md_object *next = mdt_object_child(obj);
69         struct lu_buf *buf = &info->mti_buf;
70         struct lustre_som_attrs *som;
71         int rc;
72         ENTRY;
73
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)
78                 RETURN(rc);
79
80         som = buf->lb_buf;
81
82         CDEBUG(D_INODE,
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);
86
87         if (rc == -ENODATA)
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;
93         }
94         buf->lb_len = sizeof(*som);
95         rc = mo_xattr_set(info->mti_env, next, buf, XATTR_NAME_SOM, 0);
96         RETURN(rc);
97 }