Motr  M0
lustre.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include "lib/errno.h"
24 #include "lib/memory.h"
25 #include "lib/misc.h" /* M0_SET0 */
26 #include "lib/bitstring.h"
27 
28 #include "fop/fop.h"
29 #include "cob/cob.h"
30 #include "mdstore/mdstore.h"
31 #include "mdservice/md_fops.h"
32 #include "mdservice/md_fops_xc.h"
33 #include "mdservice/ut/lustre.h"
34 
35 typedef int (*fop_translate_t)(struct m0_fop *fop, void *data);
36 
37 static void lustre_copy_fid(struct m0_fid *bf,
38  const struct m0_md_lustre_fid *cf)
39 {
40  m0_fid_set(bf, cf->f_seq, cf->f_oid);
41 }
42 
43 static int lustre_copy_name(struct m0_fop_str *n,
44  const struct m0_md_lustre_logrec *rec)
45 {
46  n->s_buf = m0_alloc(rec->cr_namelen);
47  if (n->s_buf == NULL)
48  return -ENOMEM;
49  n->s_len = rec->cr_namelen;
50  memcpy(n->s_buf, rec->cr_name, rec->cr_namelen);
51  return 0;
52 }
53 
55  M0_LA_ATIME = 1 << 0,
56  M0_LA_MTIME = 1 << 1,
57  M0_LA_CTIME = 1 << 2,
58  M0_LA_SIZE = 1 << 3,
59  M0_LA_MODE = 1 << 4,
60  M0_LA_UID = 1 << 5,
61  M0_LA_GID = 1 << 6,
62  M0_LA_BLOCKS = 1 << 7,
63  M0_LA_TYPE = 1 << 8,
64  M0_LA_FLAGS = 1 << 9,
65  M0_LA_NLINK = 1 << 10,
66  M0_LA_RDEV = 1 << 11,
67  M0_LA_BLKSIZE = 1 << 12
68 };
69 
70 static uint16_t lustre_get_valid(uint16_t valid)
71 {
72  uint16_t result = 0;
73 
74  if (valid & M0_LA_ATIME)
75  result |= M0_COB_ATIME;
76  if (valid & M0_LA_MTIME)
77  result |= M0_COB_MTIME;
78  if (valid & M0_LA_CTIME)
79  result |= M0_COB_CTIME;
80  if (valid & M0_LA_SIZE)
81  result |= M0_COB_SIZE;
82  if (valid & M0_LA_MODE)
83  result |= M0_COB_MODE;
84  if (valid & M0_LA_UID)
85  result |= M0_COB_UID;
86  if (valid & M0_LA_GID)
87  result |= M0_COB_GID;
88  if (valid & M0_LA_BLOCKS)
89  result |= M0_COB_BLOCKS;
90  if (valid & M0_LA_TYPE)
91  result |= M0_COB_TYPE;
92  if (valid & M0_LA_FLAGS)
93  result |= M0_COB_FLAGS;
94  if (valid & M0_LA_NLINK)
95  result |= M0_COB_NLINK;
96  if (valid & M0_LA_RDEV)
97  result |= M0_COB_RDEV;
98  if (valid & M0_LA_BLKSIZE)
99  result |= M0_COB_BLKSIZE;
100  return result;
101 }
102 
103 static void lustre_copy_body(struct m0_fop_cob *body,
104  const struct m0_md_lustre_logrec *rec)
105 {
106  struct m0_md_lustre_fid fid;
107 
108  body->b_index = rec->cr_index;
109  if (rec->cr_valid & M0_LA_SIZE)
110  body->b_size = rec->cr_size;
111  if (rec->cr_valid & M0_LA_BLKSIZE)
112  body->b_blksize = rec->cr_blksize;
113  if (rec->cr_valid & M0_LA_BLOCKS)
114  body->b_blocks = rec->cr_blocks;
115  if (rec->cr_valid & M0_LA_UID)
116  body->b_uid = rec->cr_uid;
117  if (rec->cr_valid & M0_LA_GID)
118  body->b_gid = rec->cr_gid;
119  if (rec->cr_valid & M0_LA_ATIME)
120  body->b_atime = rec->cr_atime;
121  if (rec->cr_valid & M0_LA_MTIME)
122  body->b_mtime = rec->cr_mtime;
123  if (rec->cr_valid & M0_LA_CTIME)
124  body->b_ctime = rec->cr_ctime;
125  if (rec->cr_valid & M0_LA_NLINK)
126  body->b_nlink = rec->cr_nlink;
127  if (rec->cr_valid & M0_LA_MODE)
128  body->b_mode = rec->cr_mode;
129  body->b_sid = rec->cr_sid;
130  body->b_nid = rec->cr_clnid;
131  body->b_version = rec->cr_version;
132  body->b_flags = rec->cr_flags;
134  fid = rec->cr_tfid;
136  fid = rec->cr_pfid;
138 }
139 
140 static int lustre_create_fop(struct m0_fop *fop, void *data)
141 {
142  struct m0_fop_create *d = m0_fop_data(fop);
143  struct m0_md_lustre_logrec *rec = data;
144 
145  lustre_copy_body(&d->c_body, rec);
146  return lustre_copy_name(&d->c_name, rec);
147 }
148 
149 static int lustre_link_fop(struct m0_fop *fop, void *data)
150 {
151  struct m0_fop_link *d = m0_fop_data(fop);
152  struct m0_md_lustre_logrec *rec = data;
153 
154  lustre_copy_body(&d->l_body, rec);
155  return lustre_copy_name(&d->l_name, rec);
156 }
157 
158 static int lustre_unlink_fop(struct m0_fop *fop, void *data)
159 {
160  struct m0_fop_unlink *d = m0_fop_data(fop);
161  struct m0_md_lustre_logrec *rec = data;
162 
163  lustre_copy_body(&d->u_body, rec);
164  return lustre_copy_name(&d->u_name, rec);
165 }
166 
167 static int lustre_open_fop(struct m0_fop *fop, void *data)
168 {
169  struct m0_fop_open *d = m0_fop_data(fop);
170  struct m0_md_lustre_logrec *rec = data;
171  lustre_copy_body(&d->o_body, rec);
172  return 0;
173 }
174 
175 static int lustre_close_fop(struct m0_fop *fop, void *data)
176 {
177  struct m0_fop_close *d = m0_fop_data(fop);
178  struct m0_md_lustre_logrec *rec = data;
179  lustre_copy_body(&d->c_body, rec);
180  return 0;
181 }
182 
183 static int lustre_setattr_fop(struct m0_fop *fop, void *data)
184 {
185  struct m0_fop_setattr *d = m0_fop_data(fop);
186  struct m0_md_lustre_logrec *rec = data;
187  lustre_copy_body(&d->s_body, rec);
188  return 0;
189 }
190 
191 static int lustre_rename_fop(struct m0_fop *fop, void *data)
192 {
193  struct m0_fop_rename *d = m0_fop_data(fop);
194  struct m0_md_lustre_logrec *rec = data;
195 
196  if (rec->cr_type == RT_RENAME) {
197  lustre_copy_body(&d->r_sbody, rec);
198  return lustre_copy_name(&d->r_sname, rec);
199  } else {
200  lustre_copy_body(&d->r_tbody, rec);
201  return lustre_copy_name(&d->r_tname, rec);
202  }
203 }
204 
205 int m0_md_lustre_fop_alloc(struct m0_fop **fop, void *data,
206  struct m0_rpc_machine *mach)
207 {
208  struct m0_md_lustre_logrec *rec = data;
209  fop_translate_t translate = NULL;
210  struct m0_fop_type *fopt = NULL;
211  int rc1, rc = 0;
212 
213  switch (rec->cr_type) {
214  case RT_MARK:
215  case RT_IOCTL:
216  case RT_TRUNC:
217  case RT_HSM:
218  case RT_XATTR:
219  return -EOPNOTSUPP;
220  case RT_CREATE:
221  case RT_MKDIR:
222  case RT_MKNOD:
223  case RT_SOFTLINK:
224  fopt = &m0_fop_create_fopt;
225  translate = lustre_create_fop;
226  break;
227  case RT_HARDLINK:
228  fopt = &m0_fop_link_fopt;
229  translate = lustre_link_fop;
230  break;
231  case RT_UNLINK:
232  case RT_RMDIR:
233  fopt = &m0_fop_unlink_fopt;
234  translate = lustre_unlink_fop;
235  break;
236  case RT_RENAME:
237  fopt = &m0_fop_rename_fopt;
238  translate = lustre_rename_fop;
239  rc = -EAGAIN;
240  break;
241  case RT_EXT:
242  M0_ASSERT(*fop != NULL);
243  translate = lustre_rename_fop;
244  break;
245  case RT_OPEN:
246  fopt = &m0_fop_open_fopt;
247  translate = lustre_open_fop;
248  break;
249  case RT_CLOSE:
250  fopt = &m0_fop_close_fopt;
251  translate = lustre_close_fop;
252  break;
253  case RT_SETATTR:
254  case RT_MTIME:
255  case RT_CTIME:
256  case RT_ATIME:
257  fopt = &m0_fop_setattr_fopt;
258  translate = lustre_setattr_fop;
259  break;
260  default:
261  return -EINVAL;
262  }
263 
264  if (*fop == NULL) {
265  *fop = m0_fop_alloc(fopt, NULL, mach);
266  if (*fop == NULL)
267  return -ENOMEM;
268  }
269 
270  M0_ASSERT(translate != NULL);
271  rc1 = translate(*fop, rec);
272  if (rc1 != 0) {
273  m0_fop_fini(*fop);
274  m0_free(*fop);
275  *fop = NULL;
276  rc = rc1;
277  }
278 
279  return rc;
280 }
281 
282 /*
283  * Local variables:
284  * c-indentation-style: "K&R"
285  * c-basic-offset: 8
286  * tab-width: 8
287  * fill-column: 80
288  * scroll-step: 1
289  * End:
290  */
uint32_t b_nlink
Definition: md_fops.h:81
uint32_t b_flags
Definition: md_fops.h:75
uint32_t b_uid
Definition: md_fops.h:82
struct m0_md_lustre_fid cr_tfid
Definition: lustre.h:60
uint32_t b_valid
Definition: md_fops.h:76
#define NULL
Definition: misc.h:38
static void lustre_copy_body(struct m0_fop_cob *body, const struct m0_md_lustre_logrec *rec)
Definition: lustre.c:103
struct m0_fid b_tfid
Definition: md_fops.h:92
uint32_t f_oid
Definition: lustre.h:35
Definition: lustre.h:75
uint64_t b_index
Definition: md_fops.h:73
uint64_t cr_ctime
Definition: lustre.h:48
static int lustre_link_fop(struct m0_fop *fop, void *data)
Definition: lustre.c:149
uint64_t f_seq
Definition: lustre.h:34
struct m0_bufvec data
Definition: di.c:40
struct m0_fop_str r_sname
Definition: md_fops.h:155
static void lustre_copy_fid(struct m0_fid *bf, const struct m0_md_lustre_fid *cf)
Definition: lustre.c:37
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
struct m0_fop_type m0_fop_create_fopt
Definition: md_fops.c:52
static struct m0_addb2_mach * mach
Definition: storage.c:42
uint32_t cr_sid
Definition: lustre.h:58
uint64_t b_size
Definition: md_fops.h:78
uint64_t cr_version
Definition: lustre.h:52
uint64_t b_nid
Definition: md_fops.h:85
struct m0_fop_cob c_body
Definition: md_fops.h:177
struct m0_fop_cob * body
Definition: dir.c:1436
struct m0_fid fid
Definition: di.c:46
static int lustre_setattr_fop(struct m0_fop *fop, void *data)
Definition: lustre.c:183
uint64_t cr_clnid
Definition: lustre.h:59
uint32_t cr_nlink
Definition: lustre.h:50
static int lustre_open_fop(struct m0_fop *fop, void *data)
Definition: lustre.c:167
uint32_t b_ctime
Definition: md_fops.h:89
M0_INTERNAL void m0_fid_set(struct m0_fid *fid, uint64_t container, uint64_t key)
Definition: fid.c:116
uint64_t cr_mtime
Definition: lustre.h:49
static int lustre_copy_name(struct m0_fop_str *n, const struct m0_md_lustre_logrec *rec)
Definition: lustre.c:43
struct m0_fop_str r_tname
Definition: md_fops.h:156
#define M0_ASSERT(cond)
static uint16_t lustre_get_valid(uint16_t valid)
Definition: lustre.c:70
struct m0_fop_type m0_fop_unlink_fopt
Definition: md_fops.c:55
uint32_t b_mode
Definition: md_fops.h:77
uint64_t cr_atime
Definition: lustre.h:47
uint32_t b_mtime
Definition: md_fops.h:88
static int lustre_rename_fop(struct m0_fop *fop, void *data)
Definition: lustre.c:191
uint16_t cr_valid
Definition: lustre.h:42
uint32_t cr_mode
Definition: lustre.h:43
void * m0_alloc(size_t size)
Definition: memory.c:126
static int lustre_unlink_fop(struct m0_fop *fop, void *data)
Definition: lustre.c:158
struct m0_fop_cob o_body
Definition: md_fops.h:167
uint8_t cr_type
Definition: lustre.h:44
uint32_t b_atime
Definition: md_fops.h:87
Definition: lustre.h:66
uint16_t cr_namelen
Definition: lustre.h:40
M0_INTERNAL void m0_fop_fini(struct m0_fop *fop)
Definition: fop.c:136
struct m0_fop_cob r_tbody
Definition: md_fops.h:152
uint32_t cr_uid
Definition: lustre.h:56
struct m0_fop_type m0_fop_rename_fopt
Definition: md_fops.c:65
static int lustre_close_fop(struct m0_fop *fop, void *data)
Definition: lustre.c:175
uint64_t cr_index
Definition: lustre.h:45
uint64_t cr_blocks
Definition: lustre.h:54
struct m0_fop_cob c_body
Definition: md_fops.h:102
uint64_t b_blocks
Definition: md_fops.h:80
uint64_t n
Definition: fops.h:107
static int lustre_create_fop(struct m0_fop *fop, void *data)
Definition: lustre.c:140
int(* fop_translate_t)(struct m0_fop *fop, void *data)
Definition: lustre.c:35
Definition: fid.h:38
uint64_t b_blksize
Definition: md_fops.h:79
struct m0_fop_type m0_fop_setattr_fopt
Definition: md_fops.c:58
struct m0_md_lustre_fid cr_pfid
Definition: lustre.h:61
uint64_t b_version
Definition: md_fops.h:74
uint64_t cr_blksize
Definition: lustre.h:55
struct m0_fop_cob r_sbody
Definition: md_fops.h:151
struct m0_fop_type m0_fop_open_fopt
Definition: md_fops.c:56
static struct m0_fop * fop
Definition: item.c:57
lustre_la_valid
Definition: lustre.c:54
uint16_t cr_flags
Definition: lustre.h:41
Definition: lustre.h:82
struct m0_fid b_pfid
Definition: md_fops.h:91
char cr_name[0]
Definition: lustre.h:62
int m0_md_lustre_fop_alloc(struct m0_fop **fop, void *data, struct m0_rpc_machine *mach)
Definition: lustre.c:205
uint32_t cr_gid
Definition: lustre.h:57
uint64_t cr_size
Definition: lustre.h:53
void m0_free(void *data)
Definition: memory.c:146
struct m0_fop_cob s_body
Definition: md_fops.h:187
int32_t rc
Definition: trigger_fop.h:47
uint32_t b_gid
Definition: md_fops.h:83
Definition: fop.h:79
struct m0_fop_str c_name
Definition: md_fops.h:105
Definition: lustre.h:76
uint32_t b_sid
Definition: md_fops.h:84
struct m0_fop_type m0_fop_close_fopt
Definition: md_fops.c:57
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96
struct m0_fop_type m0_fop_link_fopt
Definition: md_fops.c:54