Motr  M0
md_foms.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_COB
23 #include <sys/stat.h> /* S_ISDIR */
24 
25 #include "lib/misc.h" /* M0_SET0 */
26 #include "lib/arith.h" /* M0_3WAY */
27 #include "lib/errno.h"
28 #include "lib/assert.h"
29 #include "lib/memory.h"
30 #include "lib/bitstring.h"
31 #include "lib/rwlock.h"
32 #include "lib/trace.h"
33 
34 #include "net/net.h"
35 #include "fid/fid.h"
36 #include "fop/fop.h"
37 #include "cob/cob.h"
38 #include "reqh/reqh.h"
39 #include "rpc/rpc_opcodes.h"
40 #include "fop/fom_generic.h"
41 #include "layout/layout.h"
42 #include "layout/pdclust.h"
43 #include "mdservice/md_fops.h"
44 #include "mdservice/md_fops_xc.h"
45 #include "mdservice/md_foms.h"
46 #include "mdservice/md_service.h"
47 #include "mdstore/mdstore.h"
48 
49 static int md_locate(struct m0_mdstore *md, struct m0_fid *tfid,
50  struct m0_cob **cob);
51 static size_t m0_md_req_fom_locality_get(const struct m0_fom *fom);
52 
53 M0_INTERNAL void m0_md_cob_wire2mem(struct m0_cob_attr *attr,
54  const struct m0_fop_cob *body)
55 {
56  M0_SET0(attr);
57  attr->ca_pfid = body->b_pfid;
58  attr->ca_tfid = body->b_tfid;
59  attr->ca_valid = body->b_valid;
60  if (body->b_valid & M0_COB_MODE)
61  attr->ca_mode = body->b_mode;
62  if (body->b_valid & M0_COB_UID)
63  attr->ca_uid = body->b_uid;
64  if (body->b_valid & M0_COB_GID)
65  attr->ca_gid = body->b_gid;
66  if (body->b_valid & M0_COB_ATIME)
67  attr->ca_atime = body->b_atime;
68  if (body->b_valid & M0_COB_MTIME)
69  attr->ca_mtime = body->b_mtime;
70  if (body->b_valid & M0_COB_CTIME)
71  attr->ca_ctime = body->b_ctime;
72  if (body->b_valid & M0_COB_NLINK)
73  attr->ca_nlink = body->b_nlink;
74  if (body->b_valid & M0_COB_RDEV)
75  attr->ca_rdev = body->b_rdev;
76  if (body->b_valid & M0_COB_SIZE)
77  attr->ca_size = body->b_size;
79  attr->ca_blksize = body->b_blksize;
80  if (body->b_valid & M0_COB_BLOCKS)
81  attr->ca_blocks = body->b_blocks;
82  if (body->b_valid & M0_COB_LID)
83  attr->ca_lid = body->b_lid;
84  if (body->b_valid & M0_COB_PVER)
85  attr->ca_pver = body->b_pver;
86  attr->ca_version = body->b_version;
87 }
88 
89 M0_INTERNAL void m0_md_cob_mem2wire(struct m0_fop_cob *body,
90  const struct m0_cob_attr *attr)
91 {
92  body->b_pfid = attr->ca_pfid;
93  body->b_tfid = attr->ca_tfid;
94  body->b_valid = attr->ca_valid;
95  if (body->b_valid & M0_COB_MODE)
96  body->b_mode = attr->ca_mode;
97  if (body->b_valid & M0_COB_UID)
98  body->b_uid = attr->ca_uid;
99  if (body->b_valid & M0_COB_GID)
100  body->b_gid = attr->ca_gid;
101  if (body->b_valid & M0_COB_ATIME)
102  body->b_atime = attr->ca_atime;
103  if (body->b_valid & M0_COB_MTIME)
104  body->b_mtime = attr->ca_mtime;
105  if (body->b_valid & M0_COB_CTIME)
106  body->b_ctime = attr->ca_ctime;
107  if (body->b_valid & M0_COB_NLINK)
108  body->b_nlink = attr->ca_nlink;
109  if (body->b_valid & M0_COB_RDEV)
110  body->b_rdev = attr->ca_rdev;
111  if (body->b_valid & M0_COB_SIZE)
112  body->b_size = attr->ca_size;
113  if (body->b_valid & M0_COB_BLKSIZE)
114  body->b_blksize = attr->ca_blksize;
115  if (body->b_valid & M0_COB_BLOCKS)
116  body->b_blocks = attr->ca_blocks;
117  if (body->b_valid & M0_COB_LID)
118  body->b_lid = attr->ca_lid;
119  if (body->b_valid & M0_COB_PVER)
120  body->b_pver = attr->ca_pver;
121  body->b_version = attr->ca_version;
122 }
123 
124 static void m0_md_create_credit(struct m0_mdstore *md,
125  struct m0_be_tx_credit *accum)
126 {
128  m0_mdstore_link_credit(md, accum);
130 }
131 
137 static int m0_md_create(struct m0_mdstore *md,
138  struct m0_fid *pfid,
139  struct m0_fid *tfid,
140  struct m0_cob_attr *attr,
141  struct m0_be_tx *tx)
142 {
143  struct m0_cob *scob = NULL;
144  int rc;
145 
146  rc = m0_mdstore_locate(md, tfid, &scob, M0_MD_LOCATE_STORED);
147  if (rc == -ENOENT) {
148  /*
149  * Statdata cob is not found, let's create it. This
150  * must be normal create case.
151  */
152  rc = m0_mdstore_fcreate(md, pfid, attr, &scob, tx);
153  } else if (rc == 0) {
154  /*
155  * There is statdata name, this must be hardlink
156  * case.
157  */
158  rc = m0_mdstore_link(md, pfid, scob, &attr->ca_name, tx);
159  /*
160  * Each operation changes target attributes (times).
161  * We want to keep them up-to-date.
162  */
163  if (rc == 0)
164  rc = m0_mdstore_setattr(md, scob, attr, tx);
165  }
166  if (scob)
167  m0_cob_put(scob);
168  M0_LOG(M0_DEBUG, "create \"%.*s\" finished with %d and lid=%d",
169  (int)attr->ca_name.b_nob, (char *)attr->ca_name.b_addr, rc,
170  (int)attr->ca_lid);
171  return M0_RC(rc);
172 }
173 
174 static inline int m0_md_tick_generic(struct m0_fom *fom)
175 {
177 
178  if (m0_fom_phase(fom) < M0_FOPH_NR) {
180  /* XXX: should be fixed after layout converted to BE */
181  struct m0_be_tx_credit cred = M0_BE_TX_CREDIT(512, 65536);
182  m0_be_tx_credit_add(&fom->fo_tx.tx_betx_cred, &cred);
183  }
184  return m0_fom_tick_generic(fom);
185  }
186 
187  return 0;
188 }
189 
190 static int md_tail(struct m0_fom *fom, struct m0_fop_cob *body,
191  struct m0_fop_mod_rep *mod, int rc)
192 {
193  const struct m0_fop *fop = fom->fo_fop;
194 
195  M0_LOG(M0_DEBUG, "%s "FID_F" finished with %d.",
196  fop->f_type->ft_name, FID_P(&body->b_pfid), rc);
197  body->b_rc = rc;
198  m0_fom_mod_rep_fill(mod, fom);
200  return M0_FSO_AGAIN;
201 }
202 
203 static int m0_md_tick_create(struct m0_fom *fom)
204 {
205  struct m0_mdstore *md;
206  struct m0_cob_attr attr;
207  struct m0_fop_cob *body;
208  struct m0_fop_create *req;
209  struct m0_fop_create_rep *rep;
210  struct m0_fop *fop;
211  struct m0_fop *fop_rep;
212  int rc;
213  struct m0_rpc_item *item;
214 
219  if (rc != 0)
220  return M0_RC(rc);
221 
222  fop = fom->fo_fop;
223  M0_ASSERT(fop != NULL);
225  req = m0_fop_data(fop);
226 
227  body = &req->c_body;
229 
230  fop_rep = fom->fo_rep_fop;
231  M0_ASSERT(fop_rep != NULL);
232  rep = m0_fop_data(fop_rep);
233 
234  m0_buf_init(&attr.ca_name, req->c_name.s_buf, req->c_name.s_len);
235 
236  M0_LOG(M0_DEBUG, "%p[%u] Create "FID_F"/"FID_F" %.*s",
238  FID_P(&body->b_pfid), FID_P(&body->b_tfid),
239  (int)attr.ca_name.b_nob, (char *)attr.ca_name.b_addr);
240 
245  rc = m0_md_fop_init(fop, fom);
246  if (rc != 0)
247  goto out;
248 
249  if (S_ISLNK(attr.ca_mode)) {
251  m0_buf_init(&attr.ca_link, (char *)req->c_target.s_buf, attr.ca_size);
252  }
253 
255  &body->b_tfid, &attr, m0_fom_tx(fom));
256 out:
257  return md_tail(fom, &rep->c_body, &rep->c_mod_rep, rc);
258 }
259 
260 static int m0_md_tick_link(struct m0_fom *fom)
261 {
262  struct m0_mdstore *md;
263  struct m0_fop_cob *body;
264  struct m0_fop_link *req;
265  struct m0_fop_link_rep *rep;
266  struct m0_fop *fop;
267  struct m0_fop *fop_rep;
268  struct m0_cob_attr attr;
269  int rc;
270 
275  if (rc != 0)
276  return M0_RC(rc);
277 
278  fop = fom->fo_fop;
279  M0_ASSERT(fop != NULL);
280  req = m0_fop_data(fop);
281 
282  fop_rep = fom->fo_rep_fop;
283  M0_ASSERT(fop_rep != NULL);
284  rep = m0_fop_data(fop_rep);
285 
286  body = &req->l_body;
288  m0_buf_init(&attr.ca_name, req->l_name.s_buf, req->l_name.s_len);
289 
290  M0_LOG(M0_DEBUG, "Link "FID_F"/%.*s -> "FID_F" started",
291  FID_P(&body->b_pfid), (int)req->l_name.s_len,
292  (char *)req->l_name.s_buf, FID_P(&body->b_tfid));
293 
298  rc = m0_md_fop_init(fop, fom);
299  if (rc != 0)
300  goto out;
301 
302  rc = m0_md_create(md,
303  &body->b_pfid, &body->b_tfid, &attr,
304  m0_fom_tx(fom));
305 out:
306  return md_tail(fom, &rep->l_body, &rep->l_mod_rep, rc);
307 }
308 
309 static int m0_md_tick_unlink(struct m0_fom *fom)
310 {
311  struct m0_mdstore *md;
312  struct m0_cob_attr attr;
313  struct m0_fop_cob *body;
314  struct m0_cob *scob = NULL;
315  struct m0_fop_unlink *req;
316  struct m0_fop_unlink_rep *rep;
317  struct m0_fop *fop;
318  struct m0_fop *fop_rep;
319  struct m0_be_tx *tx;
320  int rc;
321 
326  if (rc != 0)
327  return M0_RC(rc);
328 
329  fop = fom->fo_fop;
330  M0_ASSERT(fop != NULL);
331  req = m0_fop_data(fop);
332  body = &req->u_body;
333 
334  fop_rep = fom->fo_rep_fop;
335  M0_ASSERT(fop_rep != NULL);
336  rep = m0_fop_data(fop_rep);
337 
339  tx = m0_fom_tx(fom);
340 
342  m0_buf_init(&attr.ca_name, req->u_name.s_buf, req->u_name.s_len);
343 
344  M0_LOG(M0_DEBUG, "Unlink "FID_F"/%.*s started",
345  FID_P(&body->b_pfid),
346  (int)req->u_name.s_len, (char *)req->u_name.s_buf);
347 
352  rc = m0_md_fop_init(fop, fom);
353  if (rc != 0)
354  goto out;
355 
356  rc = md_locate(md, &body->b_tfid, &scob);
357  if (rc != 0)
358  goto out;
359 
360  rc = m0_mdstore_unlink(md, &body->b_pfid, scob, &attr.ca_name, tx);
361  m0_cob_put(scob);
362  if (rc != 0) {
363  M0_LOG(M0_DEBUG, "Unlink "FID_F"/%.*s failed with %d",
364  FID_P(&body->b_pfid),
365  (int)req->u_name.s_len, (char *)req->u_name.s_buf,
366  rc);
367  goto out;
368  }
369 out:
370  return md_tail(fom, &rep->u_body, &rep->u_mod_rep, rc);
371 }
372 
373 static void m0_md_rename_credit(struct m0_mdstore *md,
374  struct m0_be_tx_credit *accum)
375 {
378 }
379 
380 static int m0_md_rename(struct m0_mdstore *md,
381  struct m0_fid *pfid_tgt,
382  struct m0_fid *pfid_src,
383  struct m0_fid *tfid_tgt,
384  struct m0_fid *tfid_src,
385  struct m0_cob_attr *tattr,
386  struct m0_cob_attr *sattr,
387  struct m0_cob *tcob,
388  struct m0_cob *scob,
389  struct m0_be_tx *tx)
390 {
391  int rc;
392 
393  M0_ASSERT(scob != NULL);
394  M0_ASSERT(tcob != NULL);
395 
396  /*
397  * Do normal rename as all objects are fine.
398  */
399  rc = m0_mdstore_rename(md, pfid_tgt, pfid_src, tcob, scob,
400  &tattr->ca_name, &sattr->ca_name, tx);
401  if (rc != 0)
402  return M0_RC(rc);
403  /*
404  * Update attributes of source and target.
405  */
406  if (m0_fid_eq(m0_cob_fid(scob), m0_cob_fid(tcob))) {
407  if (tcob->co_nsrec.cnr_nlink > 0)
408  rc = m0_mdstore_setattr(md, tcob, tattr, tx);
409  } else {
410  rc = m0_mdstore_setattr(md, scob, sattr, tx);
411  if (rc == 0 && tcob->co_nsrec.cnr_nlink > 0)
412  rc = m0_mdstore_setattr(md, tcob, tattr, tx);
413  }
414  return M0_RC(rc);
415 }
416 
417 static int m0_md_tick_rename(struct m0_fom *fom)
418 {
419  struct m0_mdstore *md;
420  struct m0_fop_cob *sbody;
421  struct m0_fop_cob *tbody;
422  struct m0_fop_rename *req;
423  struct m0_fop_rename_rep *rep;
424  struct m0_fop *fop;
425  struct m0_fop *fop_rep;
426  struct m0_cob *tcob = NULL;
427  struct m0_cob *scob = NULL;
428  struct m0_cob_attr sattr;
429  struct m0_cob_attr tattr;
430  struct m0_be_tx *tx;
431  int rc;
432 
437  if (rc != 0)
438  return M0_RC(rc);
439 
440  fop = fom->fo_fop;
441  M0_ASSERT(fop != NULL);
442  req = m0_fop_data(fop);
443 
444  fop_rep = fom->fo_rep_fop;
445  M0_ASSERT(fop_rep != NULL);
446  rep = m0_fop_data(fop_rep);
447 
448  tx = m0_fom_tx(fom);
449 
454  rc = m0_md_fop_init(fop, fom);
455  if (rc != 0)
456  goto out;
457 
458  sbody = &req->r_sbody;
459  tbody = &req->r_tbody;
460 
461  m0_md_cob_wire2mem(&tattr, tbody);
462  m0_buf_init(&tattr.ca_name, req->r_tname.s_buf, req->r_tname.s_len);
463 
464  m0_md_cob_wire2mem(&sattr, sbody);
465  m0_buf_init(&sattr.ca_name, req->r_sname.s_buf, req->r_sname.s_len);
466 
467  rc = md_locate(md, &sbody->b_tfid, &scob);
468  if (rc != 0) {
469  goto out;
470  }
471  if (m0_fid_eq(&tbody->b_tfid, &sbody->b_tfid)) {
472  rc = m0_md_rename(md, &tbody->b_pfid, &sbody->b_pfid,
473  &tbody->b_tfid, &sbody->b_tfid, &tattr,
474  &sattr, scob, scob, tx);
475  } else {
476  rc = md_locate(md, &tbody->b_tfid, &tcob);
477  if (rc != 0) {
478  goto out;
479  }
480  rc = m0_md_rename(md, &tbody->b_pfid, &sbody->b_pfid,
481  &tbody->b_tfid, &sbody->b_tfid, &tattr,
482  &sattr, tcob, scob, tx);
483  m0_cob_put(tcob);
484  }
485  m0_cob_put(scob);
486 out:
487  return md_tail(fom, &rep->r_body, &rep->r_mod_rep, rc);
488 }
489 
490 static int m0_md_tick_open(struct m0_fom *fom)
491 {
492  struct m0_mdstore *md;
493  struct m0_fop_cob *body;
494  struct m0_cob *cob;
495  struct m0_fop_open *req;
496  struct m0_fop_open_rep *rep;
497  struct m0_fop *fop;
498  struct m0_fop *fop_rep;
499  struct m0_cob_attr attr;
500  int rc;
501 
506  if (rc != 0)
507  return M0_RC(rc);
508 
509  fop = fom->fo_fop;
510  M0_ASSERT(fop != NULL);
511  req = m0_fop_data(fop);
512 
513  fop_rep = fom->fo_rep_fop;
514  M0_ASSERT(fop_rep != NULL);
515  rep = m0_fop_data(fop_rep);
516 
521  rc = m0_md_fop_init(fop, fom);
522  if (rc != 0)
523  goto out;
524 
525  body = &req->o_body;
527 
529  if (rc == 0) {
532  if (rc == 0 &&
533  (!(attr.ca_valid & M0_COB_NLINK) || attr.ca_nlink > 0)) {
534  /*
535  * Mode contains open flags that we don't need
536  * to store to db.
537  */
538  attr.ca_valid &= ~M0_COB_MODE;
540  cob, &attr, m0_fom_tx(fom));
541  }
542  m0_cob_put(cob);
543  } else if (rc == -ENOENT) {
544  /*
545  * Lustre has create before open in case of OPEN_CREATE.
546  * We don't have to create anything here as file already
547  * should exist, let's just check this.
548  */
549  /* M0_ASSERT(!(body->b_flags & M0_MD_OPEN_CREAT)); */
550  } else if (rc != 0) {
551  goto out;
552  }
553 
554 out:
555  return md_tail(fom, &rep->o_body, &rep->o_mod_rep, rc);
556 }
557 
558 static int m0_md_tick_close(struct m0_fom *fom)
559 {
560  struct m0_mdstore *md;
561  struct m0_fop_cob *body;
562  struct m0_cob *cob;
563  struct m0_fop_close *req;
564  struct m0_fop_close_rep *rep;
565  struct m0_fop *fop;
566  struct m0_fop *fop_rep;
567  struct m0_cob_attr attr;
568  int rc;
569 
574  if (rc != 0)
575  return M0_RC(rc);
576 
577  fop = fom->fo_fop;
578  M0_ASSERT(fop != NULL);
579  req = m0_fop_data(fop);
580 
581  fop_rep = fom->fo_rep_fop;
582  M0_ASSERT(fop_rep != NULL);
583  rep = m0_fop_data(fop_rep);
584 
589  rc = m0_md_fop_init(fop, fom);
590  if (rc != 0)
591  goto out;
592 
593  body = &req->c_body;
595 
596  /*
597  * @TODO: This should lookup for cobs in special opened
598  * cobs table. But so far orphans and open/close are not
599  * quite implemented and we lookup on main store to make
600  * ut happy.
601  */
602  rc = md_locate(md, &body->b_tfid, &cob);
603  if (rc != 0) {
604  goto out;
605  }
606 
608  if (rc == 0 &&
609  (!(attr.ca_valid & M0_COB_NLINK) || attr.ca_nlink > 0)) {
610  /*
611  * Mode contains open flags that we don't need
612  * to store to db.
613  */
614  attr.ca_valid &= ~M0_COB_MODE;
616  }
617  m0_cob_put(cob);
618 out:
619  rep->c_body.b_rc = rc;
621  return M0_FSO_AGAIN;
622 }
623 
624 static int m0_md_tick_setattr(struct m0_fom *fom)
625 {
626  struct m0_mdstore *md;
627  struct m0_cob_attr attr;
628  struct m0_fop_cob *body;
629  struct m0_cob *cob;
630  struct m0_fop_setattr *req;
631  struct m0_fop_setattr_rep *rep;
632  struct m0_fop *fop;
633  struct m0_fop *fop_rep;
634  int rc;
635 
640  if (rc != 0)
641  return M0_RC(rc);
642 
643  fop = fom->fo_fop;
644  M0_ASSERT(fop != NULL);
645  req = m0_fop_data(fop);
646 
647  fop_rep = fom->fo_rep_fop;
648  M0_ASSERT(fop_rep != NULL);
649  rep = m0_fop_data(fop_rep);
650 
651  body = &req->s_body;
653 
654  M0_LOG(M0_DEBUG, "Setattr for "FID_F" started", FID_P(&body->b_tfid));
655 
660  rc = m0_md_fop_init(fop, fom);
661  if (rc != 0)
662  goto out;
663 
664  /*
665  * Setattr fop does not carry enough information to create
666  * an object in case there is no target yet. This is why
667  * we return quickly if no object is found.
668  */
669  rc = md_locate(md, &body->b_tfid, &cob);
670  if (rc != 0) {
671  goto out;
672  }
673 
675  m0_cob_put(cob);
676 out:
677  return md_tail(fom, &rep->s_body, &rep->s_mod_rep, rc);
678 }
679 
680 static int m0_md_tick_lookup(struct m0_fom *fom)
681 {
682  struct m0_mdstore *md;
683  struct m0_cob_attr attr;
684  struct m0_fop_cob *body;
685  struct m0_cob *cob;
686  struct m0_fop_lookup *req;
687  struct m0_fop_lookup_rep *rep;
688  struct m0_fop *fop;
689  struct m0_fop *fop_rep;
690  struct m0_fid tfid;
691  int rc;
692  struct m0_buf name;
693 
696  if (rc != 0)
697  return M0_RC(rc);
698 
699  fop = fom->fo_fop;
700  M0_ASSERT(fop != NULL);
701  req = m0_fop_data(fop);
702  body = &req->l_body;
703 
704  fop_rep = fom->fo_rep_fop;
705  M0_ASSERT(fop_rep != NULL);
706  rep = m0_fop_data(fop_rep);
707 
708  m0_buf_init(&name, req->l_name.s_buf, req->l_name.s_len);
709 
710  M0_LOG(M0_DEBUG, "Lookup for \"%.*s\" in object "FID_F,
711  (int)name.b_nob, (char *)name.b_addr, FID_P(&body->b_pfid));
712 
717  rc = m0_md_fop_init(fop, fom);
718  if (rc != 0)
719  goto out;
720 
722  if (rc != 0) {
723  M0_LOG(M0_DEBUG, "m0_mdstore_lookup() failed with %d", rc);
724  goto out;
725  }
726  tfid = *m0_cob_fid(cob);
727  m0_cob_put(cob);
728 
729  M0_LOG(M0_DEBUG, "Found object "FID_F" go for getattr", FID_P(&tfid));
730 
731  rc = md_locate(md, &tfid, &cob);
732  if (rc != 0) {
733  goto out;
734  }
735 
737  m0_cob_put(cob);
738 
739  if (rc == 0) {
740  attr.ca_valid = M0_COB_ALL;
741  m0_md_cob_mem2wire(&rep->l_body, &attr);
742  } else {
743  M0_LOG(M0_DEBUG, "Getattr on object "FID_F" failed with %d",
744  FID_P(m0_cob_fid(cob)), rc);
745  }
746 out:
747  M0_LOG(M0_DEBUG, "Lookup for \"%.*s\" finished with %d",
748  (int)name.b_nob, (char *)name.b_addr, rc);
749 
750  rep->l_body.b_rc = rc;
752  return M0_FSO_AGAIN;
753 }
754 
755 static int m0_md_tick_getattr(struct m0_fom *fom)
756 {
757  struct m0_mdstore *md;
758  struct m0_cob_attr attr;
759  struct m0_fop_cob *body;
760  struct m0_cob *cob;
761  struct m0_fop_getattr *req;
762  struct m0_fop_getattr_rep *rep;
763  struct m0_fop *fop;
764  struct m0_fop *fop_rep;
765  int rc;
766 
769  if (rc != 0)
770  return M0_RC(rc);
771 
772  fop = fom->fo_fop;
773  M0_ASSERT(fop != NULL);
774  req = m0_fop_data(fop);
775  body = &req->g_body;
776 
777  fop_rep = fom->fo_rep_fop;
778  M0_ASSERT(fop_rep != NULL);
779  rep = m0_fop_data(fop_rep);
780 
781  M0_LOG(M0_DEBUG, "Getattr for "FID_F" started", FID_P(&body->b_tfid));
782 
787  rc = m0_md_fop_init(fop, fom);
788  if (rc != 0)
789  goto out;
790 
791  rc = md_locate(md, &body->b_tfid, &cob);
792  if (rc != 0)
793  goto out;
794 
796  m0_cob_put(cob);
797  if (rc == 0) {
798  attr.ca_valid = M0_COB_ALL;
800  }
801 out:
802  M0_LOG(M0_DEBUG, "Getattr for "FID_F" finished with %d",
803  FID_P(&body->b_tfid), rc);
804  rep->g_body.b_rc = rc;
806  return M0_FSO_AGAIN;
807 }
808 
810  struct m0_statfs *statfs)
811 {
812  rep->f_type = statfs->sf_type;
813  rep->f_bsize = statfs->sf_bsize;
814  rep->f_blocks = statfs->sf_blocks;
815  rep->f_bfree = statfs->sf_bfree;
816  rep->f_bavail = statfs->sf_bavail;
817  rep->f_files = statfs->sf_files;
818  rep->f_ffree = statfs->sf_ffree;
819  rep->f_namelen = statfs->sf_namelen;
820  rep->f_root = statfs->sf_root;
821 }
822 
823 static int m0_md_tick_getxattr(struct m0_fom *fom)
824 {
825  struct m0_mdstore *md;
826  struct m0_cob_eakey *eakey;
827  struct m0_cob_earec *earec;
828  struct m0_fop_cob *body;
829  struct m0_cob *cob;
830  struct m0_fop_getxattr *req;
831  struct m0_fop_getxattr_rep *rep;
832  struct m0_fop *fop;
833  struct m0_fop *fop_rep;
834  int rc;
835 
838  if (rc != 0)
839  return M0_RC(rc);
840 
841  fop = fom->fo_fop;
842  M0_ASSERT(fop != NULL);
843  req = m0_fop_data(fop);
844  body = &req->g_body;
845 
846  fop_rep = fom->fo_rep_fop;
847  M0_ASSERT(fop_rep != NULL);
848  rep = m0_fop_data(fop_rep);
849 
850  M0_LOG(M0_DEBUG, "Getxattr %.*s for "FID_F" started",
851  req->g_key.s_len, (char *)req->g_key.s_buf, FID_P(&body->b_pfid));
852 
857  rc = m0_md_fop_init(fop, fom);
858  if (rc != 0)
859  goto out;
860 
861  rc = md_locate(md, &body->b_tfid, &cob);
862  if (rc != 0)
863  goto out;
864 
865  rc = m0_cob_eakey_make(&eakey, m0_cob_fid(cob),
866  (char *)req->g_key.s_buf,
867  req->g_key.s_len);
868  if (rc != 0) {
869  goto out;
870  }
871 
872  earec = m0_alloc(m0_cob_max_earec_size());
873  if (earec == NULL) {
874  m0_free(eakey);
875  goto out;
876  }
877 
878  rc = m0_cob_ea_get(cob, eakey, earec, m0_fom_tx(fom));
879  m0_cob_put(cob);
880  if (rc == 0) {
881  rep->g_value.s_len = earec->cer_size;
882  rep->g_value.s_buf = m0_alloc(earec->cer_size);
883  if (rep->g_value.s_buf == NULL) {
884  m0_free(eakey);
885  m0_free(earec);
886  rc = -ENOMEM;
887  goto out;
888  }
889  memcpy(rep->g_value.s_buf, earec->cer_body, earec->cer_size);
890  }
891  m0_free(eakey);
892  m0_free(earec);
893 out:
894  M0_LOG(M0_DEBUG, "Getxattr for "FID_F" finished with %d",
895  FID_P(&body->b_pfid), rc);
896  rep->g_body.b_rc = rc;
898  return M0_FSO_AGAIN;
899 }
900 
901 static int m0_md_tick_setxattr(struct m0_fom *fom)
902 {
903  struct m0_mdstore *md;
904  struct m0_cob_eakey *eakey;
905  struct m0_cob_earec *earec;
906  struct m0_fop_cob *body;
907  struct m0_cob *cob;
908  struct m0_fop_setxattr *req;
909  struct m0_fop_setxattr_rep *rep;
910  struct m0_fop *fop;
911  struct m0_fop *fop_rep;
912  int rc;
913 
919  if (rc != 0)
920  return M0_RC(rc);
921 
922  fop = fom->fo_fop;
923  M0_ASSERT(fop != NULL);
924  req = m0_fop_data(fop);
925  body = &req->s_body;
926 
927  fop_rep = fom->fo_rep_fop;
928  M0_ASSERT(fop_rep != NULL);
929  rep = m0_fop_data(fop_rep);
930 
931  M0_LOG(M0_DEBUG, "Setxattr %.*s=%.*s for "FID_F" started",
932  req->s_key.s_len, (char *)req->s_key.s_buf,
933  req->s_value.s_len, (char *)req->s_value.s_buf,
934  FID_P(&body->b_pfid));
935 
936  /*
937  * Init some fop fields (full path) that require mdstore and other
938  * initialized structures.
939  */
940  rc = m0_md_fop_init(fop, fom);
941  if (rc != 0)
942  goto out;
943 
944  rc = md_locate(md, &body->b_tfid, &cob);
945  if (rc != 0)
946  goto out;
947 
948  rc = m0_cob_eakey_make(&eakey, m0_cob_fid(cob),
949  (char *)req->s_key.s_buf,
950  req->s_key.s_len);
951  if (rc != 0) {
952  goto out;
953  }
954 
955  earec = m0_alloc(m0_cob_max_earec_size());
956  if (earec == NULL) {
957  m0_free(eakey);
958  goto out;
959  }
960 
961  earec->cer_size = req->s_value.s_len;
962  memcpy(earec->cer_body, req->s_value.s_buf, earec->cer_size);
963 
964  rc = m0_cob_ea_set(cob, eakey, earec, m0_fom_tx(fom));
965  m0_cob_put(cob);
966  m0_free(eakey);
967  m0_free(earec);
968 out:
969  return md_tail(fom, &rep->s_body, &rep->s_mod_rep, rc);
970 }
971 
972 static int m0_md_tick_delxattr(struct m0_fom *fom)
973 {
974  struct m0_mdstore *md;
975  struct m0_cob_eakey *eakey;
976  struct m0_fop_cob *body;
977  struct m0_cob *cob;
978  struct m0_fop_delxattr *req;
979  struct m0_fop_delxattr_rep *rep;
980  struct m0_fop *fop;
981  struct m0_fop *fop_rep;
982  int rc;
983 
989  if (rc != 0)
990  return M0_RC(rc);
991 
992  fop = fom->fo_fop;
993  M0_ASSERT(fop != NULL);
994  req = m0_fop_data(fop);
995  body = &req->d_body;
996 
997  fop_rep = fom->fo_rep_fop;
998  M0_ASSERT(fop_rep != NULL);
999  rep = m0_fop_data(fop_rep);
1000 
1001  M0_LOG(M0_DEBUG, "Delxattr for "FID_F" started", FID_P(&body->b_tfid));
1002 
1007  rc = m0_md_fop_init(fop, fom);
1008  if (rc != 0)
1009  goto out;
1010 
1011  rc = md_locate(md, &body->b_tfid, &cob);
1012  if (rc != 0)
1013  goto out;
1014 
1015  rc = m0_cob_eakey_make(&eakey, m0_cob_fid(cob),
1016  (char *)req->d_key.s_buf,
1017  req->d_key.s_len);
1018  if (rc != 0) {
1019  goto out;
1020  }
1021 
1022  rc = m0_cob_ea_del(cob, eakey, m0_fom_tx(fom));
1023  m0_cob_put(cob);
1024  m0_free(eakey);
1025 out:
1026  return md_tail(fom, &rep->d_body, &rep->d_mod_rep, rc);
1027 }
1028 
1029 static int m0_md_tick_listxattr(struct m0_fom *fom)
1030 {
1031  int rc = -EOPNOTSUPP;
1033  return M0_FSO_AGAIN;
1034 }
1035 
1036 static int m0_md_tick_statfs(struct m0_fom *fom)
1037 {
1038  struct m0_fop_statfs_rep *rep;
1039  struct m0_fop *fop;
1040  struct m0_fop *fop_rep;
1041  struct m0_statfs statfs;
1042  int rc;
1043 
1045  if (rc != 0)
1046  return M0_RC(rc);
1047 
1048  fop = fom->fo_fop;
1049  M0_ASSERT(fop != NULL);
1050 
1051  fop_rep = fom->fo_rep_fop;
1052  M0_ASSERT(fop_rep != NULL);
1053  rep = m0_fop_data(fop_rep);
1054 
1055  rc = m0_md_fop_init(fop, fom);
1056  if (rc != 0)
1057  goto out;
1058 
1059  rc = m0_mdstore_statfs(m0_fom_reqh(fom)->rh_mdstore, &statfs);
1060  if (rc == 0)
1061  md_statfs_mem2wire(rep, &statfs);
1062 out:
1063  rep->f_rc = rc;
1065  return M0_FSO_AGAIN;
1066 }
1067 
1069 #define M0_MD_READDIR_BUFF_SIZE 4096
1070 
1071 static int m0_md_tick_readdir(struct m0_fom *fom)
1072 {
1073  struct m0_mdstore *md;
1074  struct m0_fop_cob *body;
1075  struct m0_cob *cob;
1076  struct m0_fop_readdir *req;
1077  struct m0_fop_readdir_rep *rep;
1078  struct m0_fop *fop;
1079  struct m0_fop *fop_rep;
1080  struct m0_rdpg rdpg;
1081  void *addr;
1082  int rc;
1083 
1086  if (rc != 0)
1087  return M0_RC(rc);
1088 
1089  fop = fom->fo_fop;
1090  M0_ASSERT(fop != NULL);
1091  req = m0_fop_data(fop);
1092 
1093  fop_rep = fom->fo_rep_fop;
1094  M0_ASSERT(fop_rep != NULL);
1095  rep = m0_fop_data(fop_rep);
1096 
1101  rc = m0_md_fop_init(fop, fom);
1102  if (rc != 0)
1103  goto out;
1104 
1105  body = &req->r_body;
1106  rc = md_locate(md, &body->b_tfid, &cob);
1107  if (rc != 0)
1108  goto out;
1109 
1110  if (!S_ISDIR(cob->co_omgrec.cor_mode)) {
1111  rc = -ENOTDIR;
1112  m0_cob_put(cob);
1113  goto out;
1114  }
1115 
1116  M0_SET0(&rdpg);
1118  if (rdpg.r_pos == NULL) {
1119  m0_cob_put(cob);
1120  rc = -ENOMEM;
1121  goto out;
1122  }
1123  m0_bitstring_copy(rdpg.r_pos,
1124  (char *)req->r_pos.s_buf, req->r_pos.s_len);
1125 
1127  if (addr == NULL) {
1128  m0_bitstring_free(rdpg.r_pos);
1129  m0_cob_put(cob);
1130  rc = -ENOMEM;
1131  goto out;
1132  }
1133 
1135 
1136  rc = m0_mdstore_readdir(md, cob, &rdpg);
1137  m0_free(rdpg.r_pos);
1138  m0_cob_put(cob);
1139  if (rc < 0) {
1140  m0_free(addr);
1141  goto out;
1142  }
1143 
1144  /*
1145  * Prepare end position.
1146  */
1147  rep->r_end.s_len = m0_bitstring_len_get(rdpg.r_end);
1148  rep->r_end.s_buf = m0_alloc(rep->r_end.s_len);
1149  if (rep->r_end.s_buf == NULL) {
1150  m0_free(addr);
1151  rc = -ENOMEM;
1152  goto out;
1153  }
1154  memcpy(rep->r_end.s_buf, m0_bitstring_buf_get(rdpg.r_end),
1155  rep->r_end.s_len);
1156  m0_bitstring_free(rdpg.r_end);
1157 
1158  /*
1159  * Prepare buf with data.
1160  */
1161  rep->r_buf.b_count = rdpg.r_buf.b_nob;
1162  rep->r_buf.b_addr = rdpg.r_buf.b_addr;
1163 out:
1164  rep->r_body.b_rc = rc;
1165 
1166  /*
1167  * Readddir return convention:
1168  * <0 - some error occured;
1169  * 0 - no errors, more data available for next readdir;
1170  * >0 - EOF detyected, more data available but this is the last page.
1171  *
1172  * Return code according to this convention should go to client but
1173  * local state machine requires "normal" errors. Let's adopt @rc.
1174  */
1175  rc = (rc < 0 ? rc : 0);
1177  return M0_FSO_AGAIN;
1178 }
1179 
1180 static int m0_md_req_path_get(struct m0_mdstore *mdstore,
1181  struct m0_fid *fid,
1182  struct m0_fop_str *str)
1183 {
1184  /*
1185  * This was solely used for replicator, which is not needed right now.
1186  * The reason to disable this is that, m0_mdstore_path() tries to init
1187  * fid's cob, which is not existing for .motr/fid directories. Later
1188  * when we need this path, we will rework it different way.
1189  */
1190 #if 0
1191  int rc;
1192 
1193  rc = m0_mdstore_path(mdstore, fid, (char **)&str->s_buf);
1194  if (rc != 0)
1195  return M0_RC(rc);
1196  str->s_len = strlen((char *)str->s_buf);
1197 #endif
1198  return 0;
1199 }
1200 
1201 M0_INTERNAL int m0_md_fop_init(struct m0_fop *fop, struct m0_fom *fom)
1202 {
1203  struct m0_fop_create *create;
1204  struct m0_fop_unlink *unlink;
1205  struct m0_fop_rename *rename;
1206  struct m0_fop_link *link;
1207  struct m0_fop_setattr *setattr;
1208  struct m0_fop_getattr *getattr;
1209  struct m0_fop_lookup *lookup;
1210  struct m0_fop_open *open;
1211  struct m0_fop_close *close;
1212  struct m0_fop_readdir *readdir;
1213  struct m0_mdstore *md;
1214  int rc;
1215 
1216  M0_PRE(fop != NULL);
1218 
1219  switch (m0_fop_opcode(fop)) {
1221  create = m0_fop_data(fop);
1223  &create->c_body.b_pfid,
1224  &create->c_path);
1225  break;
1227  link = m0_fop_data(fop);
1229  &link->l_body.b_pfid,
1230  &link->l_tpath);
1231  if (rc != 0)
1232  return M0_RC(rc);
1234  &link->l_body.b_tfid,
1235  &link->l_spath);
1236  if (rc != 0) {
1237  m0_free0(&link->l_tpath.s_buf);
1238  link->l_tpath.s_len = 0;
1239  return M0_RC(rc);
1240  }
1241  break;
1243  unlink = m0_fop_data(fop);
1245  &unlink->u_body.b_pfid,
1246  &unlink->u_path);
1247  break;
1249  rename = m0_fop_data(fop);
1251  &rename->r_sbody.b_pfid,
1252  &rename->r_spath);
1253  if (rc != 0)
1254  return M0_RC(rc);
1256  &rename->r_tbody.b_pfid,
1257  &rename->r_tpath);
1258  if (rc != 0) {
1259  m0_free0(&rename->r_spath.s_buf);
1260  rename->r_spath.s_len = 0;
1261  return M0_RC(rc);
1262  }
1263  break;
1265  open = m0_fop_data(fop);
1267  &open->o_body.b_tfid,
1268  &open->o_path);
1269  break;
1271  close = m0_fop_data(fop);
1273  &close->c_body.b_tfid,
1274  &close->c_path);
1275  break;
1277  setattr = m0_fop_data(fop);
1279  &setattr->s_body.b_tfid,
1280  &setattr->s_path);
1281  break;
1283  getattr = m0_fop_data(fop);
1285  &getattr->g_body.b_tfid,
1286  &getattr->g_path);
1287  break;
1289  lookup = m0_fop_data(fop);
1291  &lookup->l_body.b_pfid,
1292  &lookup->l_path);
1293  break;
1295  readdir = m0_fop_data(fop);
1297  &readdir->r_body.b_tfid,
1298  &readdir->r_path);
1299  break;
1300  default:
1301  rc = 0;
1302  break;
1303  }
1304 
1305  return M0_RC(rc);
1306 }
1307 
1308 static void m0_md_fom_fini(struct m0_fom *fom)
1309 {
1310  struct m0_fom_md *fom_obj;
1311 
1312  M0_ENTRY("fom=%p", fom);
1313 
1314  fom_obj = container_of(fom, struct m0_fom_md, fm_fom);
1315  /* Fini fom itself. */
1316  m0_fom_fini(fom);
1317  m0_free(fom_obj);
1318 
1319  M0_LEAVE();
1320 }
1321 
1327 
1328 static void m0_md_req_fom_fini(struct m0_fom *fom)
1329 {
1330  (*m0_md_req_fom_fini_func)(fom);
1331 }
1332 
1333 static size_t m0_md_req_fom_locality_get(const struct m0_fom *fom)
1334 {
1335  M0_PRE(fom != NULL);
1336  M0_PRE(fom->fo_fop != NULL);
1337 
1338  return m0_fop_opcode(fom->fo_fop);
1339 }
1340 
1341 static const struct m0_fom_ops m0_md_fom_create_ops = {
1343  .fo_tick = m0_md_tick_create,
1344  .fo_fini = m0_md_req_fom_fini
1345 };
1346 
1347 static const struct m0_fom_ops m0_md_fom_link_ops = {
1349  .fo_tick = m0_md_tick_link,
1350  .fo_fini = m0_md_req_fom_fini
1351 };
1352 
1353 static const struct m0_fom_ops m0_md_fom_unlink_ops = {
1355  .fo_tick = m0_md_tick_unlink,
1356  .fo_fini = m0_md_req_fom_fini
1357 };
1358 
1359 static const struct m0_fom_ops m0_md_fom_rename_ops = {
1361  .fo_tick = m0_md_tick_rename,
1362  .fo_fini = m0_md_req_fom_fini
1363 };
1364 
1365 static const struct m0_fom_ops m0_md_fom_open_ops = {
1367  .fo_tick = m0_md_tick_open,
1368  .fo_fini = m0_md_req_fom_fini
1369 };
1370 
1371 static const struct m0_fom_ops m0_md_fom_close_ops = {
1373  .fo_tick = m0_md_tick_close,
1374  .fo_fini = m0_md_req_fom_fini
1375 };
1376 
1377 static const struct m0_fom_ops m0_md_fom_setattr_ops = {
1379  .fo_tick = m0_md_tick_setattr,
1380  .fo_fini = m0_md_req_fom_fini
1381 };
1382 
1383 static const struct m0_fom_ops m0_md_fom_getattr_ops = {
1385  .fo_tick = m0_md_tick_getattr,
1386  .fo_fini = m0_md_req_fom_fini
1387 };
1388 
1389 static const struct m0_fom_ops m0_md_fom_setxattr_ops = {
1391  .fo_tick = m0_md_tick_setxattr,
1392  .fo_fini = m0_md_req_fom_fini
1393 };
1394 
1395 static const struct m0_fom_ops m0_md_fom_getxattr_ops = {
1397  .fo_tick = m0_md_tick_getxattr,
1398  .fo_fini = m0_md_req_fom_fini
1399 };
1400 
1401 static const struct m0_fom_ops m0_md_fom_delxattr_ops = {
1403  .fo_tick = m0_md_tick_delxattr,
1404  .fo_fini = m0_md_req_fom_fini
1405 };
1406 
1407 static const struct m0_fom_ops m0_md_fom_listxattr_ops = {
1409  .fo_tick = m0_md_tick_listxattr,
1410  .fo_fini = m0_md_req_fom_fini
1411 };
1412 
1413 static const struct m0_fom_ops m0_md_fom_lookup_ops = {
1415  .fo_tick = m0_md_tick_lookup,
1416  .fo_fini = m0_md_req_fom_fini
1417 };
1418 
1419 static const struct m0_fom_ops m0_md_fom_statfs_ops = {
1421  .fo_tick = m0_md_tick_statfs,
1422  .fo_fini = m0_md_req_fom_fini
1423 };
1424 
1425 static const struct m0_fom_ops m0_md_fom_readdir_ops = {
1427  .fo_tick = m0_md_tick_readdir,
1428  .fo_fini = m0_md_req_fom_fini
1429 };
1430 
1431 M0_INTERNAL int m0_md_rep_fom_create(struct m0_fop *fop, struct m0_fom **m,
1432  struct m0_reqh *reqh)
1433 {
1434  return 0;
1435 }
1436 
1437 M0_INTERNAL int m0_md_req_fom_create(struct m0_fop *fop, struct m0_fom **m,
1438  struct m0_reqh *reqh)
1439 {
1440  struct m0_fop *rep_fop;
1441  struct m0_fom *fom;
1442  struct m0_fom_md *fom_obj;
1443  struct m0_fop_type *rep_fopt;
1444  const struct m0_fom_ops *ops;
1445 
1446  M0_PRE(fop != NULL);
1447  M0_PRE(m != NULL);
1448 
1449  fom_obj = m0_alloc(sizeof(struct m0_fom_md));
1450  if (fom_obj == NULL)
1451  return M0_ERR(-ENOMEM);
1452 
1453  switch (m0_fop_opcode(fop)) {
1456  rep_fopt = &m0_fop_create_rep_fopt;
1457  break;
1460  rep_fopt = &m0_fop_lookup_rep_fopt;
1461  break;
1464  rep_fopt = &m0_fop_link_rep_fopt;
1465  break;
1468  rep_fopt = &m0_fop_unlink_rep_fopt;
1469  break;
1472  rep_fopt = &m0_fop_rename_rep_fopt;
1473  break;
1476  rep_fopt = &m0_fop_open_rep_fopt;
1477  break;
1480  rep_fopt = &m0_fop_close_rep_fopt;
1481  break;
1484  rep_fopt = &m0_fop_setattr_rep_fopt;
1485  break;
1488  rep_fopt = &m0_fop_getattr_rep_fopt;
1489  break;
1492  rep_fopt = &m0_fop_setxattr_rep_fopt;
1493  break;
1496  rep_fopt = &m0_fop_getxattr_rep_fopt;
1497  break;
1500  rep_fopt = &m0_fop_delxattr_rep_fopt;
1501  break;
1504  rep_fopt = &m0_fop_listxattr_rep_fopt;
1505  break;
1508  rep_fopt = &m0_fop_statfs_rep_fopt;
1509  break;
1512  rep_fopt = &m0_fop_readdir_rep_fopt;
1513  break;
1514  default:
1515  m0_free(fom_obj);
1516  return M0_ERR(-EOPNOTSUPP);
1517  }
1518 
1519  rep_fop = m0_fop_reply_alloc(fop, rep_fopt);
1520  if (rep_fop == NULL) {
1521  m0_free(fom_obj);
1522  return M0_ERR(-ENOMEM);
1523  }
1524  fom = &fom_obj->fm_fom;
1526  *m = fom;
1527  return 0;
1528 }
1529 
1530 static int md_locate(struct m0_mdstore *md, struct m0_fid *tfid,
1531  struct m0_cob **cob)
1532 {
1533  int rc;
1534 
1536  if (rc != 0)
1537  M0_LOG(M0_DEBUG, "m0_mdstore_locate() failed for "FID_F" (%d)",
1538  FID_P(tfid), rc);
1539  return M0_RC(rc);
1540 }
1541 
1542 #undef M0_TRACE_SUBSYSTEM
1543 
1544 /*
1545  * Local variables:
1546  * c-indentation-style: "K&R"
1547  * c-basic-offset: 8
1548  * tab-width: 8
1549  * fill-column: 80
1550  * scroll-step: 1
1551  * End:
1552  */
static int m0_md_tick_setattr(struct m0_fom *fom)
Definition: md_foms.c:624
struct m0_cob_nsrec co_nsrec
Definition: cob.h:590
struct m0_fop_cob g_body
Definition: md_fops.h:214
uint32_t b_nlink
Definition: md_fops.h:81
uint32_t b_flags
Definition: md_fops.h:75
struct m0_fop_str r_spath
Definition: md_fops.h:153
void m0_fom_phase_moveif(struct m0_fom *fom, int32_t rc, int phase0, int phase1)
Definition: fom.c:1710
static const struct m0_fom_ops m0_md_fom_rename_ops
Definition: md_foms.c:1359
uint32_t b_uid
Definition: md_fops.h:82
uint32_t rit_opcode
Definition: item.h:474
uint32_t m0_fop_opcode(const struct m0_fop *fop)
Definition: fop.c:226
#define M0_PRE(cond)
static int m0_md_tick_readdir(struct m0_fom *fom)
Definition: md_foms.c:1071
uint32_t cnr_nlink
Definition: cob.h:426
static int m0_md_tick_lookup(struct m0_fom *fom)
Definition: md_foms.c:680
static int m0_md_tick_open(struct m0_fom *fom)
Definition: md_foms.c:490
Definition: cob.h:581
void(* m0_md_req_fom_fini_func)(struct m0_fom *fom)
Definition: md_foms.c:1326
static const struct m0_fom_ops m0_md_fom_statfs_ops
Definition: md_foms.c:1419
M0_INTERNAL int m0_cob_ea_del(struct m0_cob *cob, struct m0_cob_eakey *eakey, struct m0_be_tx *tx)
Definition: cob.c:2193
struct m0_cob_domain * md_dom
Definition: mdstore.h:58
uint32_t b_valid
Definition: md_fops.h:76
#define NULL
Definition: misc.h:38
static struct m0_addb2_mach * m
Definition: consumer.c:38
M0_INTERNAL size_t m0_cob_max_earec_size(void)
Definition: cob.c:241
struct m0_fop_str o_path
Definition: md_fops.h:166
struct m0_fid b_tfid
Definition: md_fops.h:92
struct m0_mdstore * rh_mdstore
Definition: reqh.h:115
#define M0_MD_MAX_NAME_LEN
Definition: mdstore.h:43
M0_INTERNAL int m0_cob_ea_get(struct m0_cob *cob, struct m0_cob_eakey *eakey, struct m0_cob_earec *out, struct m0_be_tx *tx)
Definition: cob.c:2155
void * b_addr
Definition: buf.h:39
static struct io_request req
Definition: file.c:100
struct m0_fop_cob l_body
Definition: md_fops.h:115
static void md_statfs_mem2wire(struct m0_fop_statfs_rep *rep, struct m0_statfs *statfs)
Definition: md_foms.c:809
static int md_tail(struct m0_fom *fom, struct m0_fop_cob *body, struct m0_fop_mod_rep *mod, int rc)
Definition: md_foms.c:190
#define M0_LOG(level,...)
Definition: trace.h:167
M0_LEAVE()
static struct m0_be_tx_credit * m0_fom_tx_credit(struct m0_fom *fom)
Definition: fom.h:542
M0_INTERNAL int m0_mdstore_locate(struct m0_mdstore *md, const struct m0_fid *fid, struct m0_cob **cob, int flags)
Definition: mdstore.c:819
static void m0_md_create_credit(struct m0_mdstore *md, struct m0_be_tx_credit *accum)
Definition: md_foms.c:124
uint64_t sf_files
Definition: mdstore.h:51
struct m0_fop_str c_path
Definition: md_fops.h:178
static struct m0_mdstore md
Definition: sd_common.c:42
static void create(void)
Definition: service_ut.c:546
struct m0_fop_str s_path
Definition: md_fops.h:188
M0_INTERNAL uint32_t m0_bitstring_len_get(const struct m0_bitstring *c)
Definition: bitstring.c:38
M0_INTERNAL void m0_buf_init(struct m0_buf *buf, void *data, uint32_t nob)
Definition: buf.c:37
M0_INTERNAL int m0_mdstore_statfs(struct m0_mdstore *md, struct m0_statfs *statfs)
Definition: mdstore.c:55
M0_INTERNAL void m0_cob_put(struct m0_cob *cob)
Definition: cob.c:1095
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
uint32_t sf_bsize
Definition: mdstore.h:47
struct m0_fop_str g_path
Definition: md_fops.h:199
M0_INTERNAL void m0_md_cob_wire2mem(struct m0_cob_attr *attr, const struct m0_fop_cob *body)
Definition: md_foms.c:53
struct m0_fop_type m0_fop_create_rep_fopt
Definition: md_fops.c:68
uint64_t b_size
Definition: md_fops.h:78
uint32_t b_rdev
Definition: md_fops.h:86
#define container_of(ptr, type, member)
Definition: misc.h:33
#define M0_SET0(obj)
Definition: misc.h:64
struct m0_fop_cob r_body
Definition: md_fops.h:253
static const struct m0_fom_ops m0_md_fom_link_ops
Definition: md_foms.c:1347
static int m0_md_tick_rename(struct m0_fom *fom)
Definition: md_foms.c:417
static struct m0_rpc_item * item
Definition: item.c:56
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
struct m0_buf ca_name
Definition: cob.h:381
static int m0_md_tick_listxattr(struct m0_fom *fom)
Definition: md_foms.c:1029
uint32_t b_rc
Definition: md_fops.h:72
m0_fom_phase
Definition: fom.h:372
static int m0_md_tick_create(struct m0_fom *fom)
Definition: md_foms.c:203
static struct m0_be_tx * m0_fom_tx(struct m0_fom *fom)
Definition: fom.h:537
struct m0_fop_cob c_body
Definition: md_fops.h:177
struct m0_fom_type ft_fom_type
Definition: fop.h:232
struct m0_fop_cob * body
Definition: dir.c:1436
static int m0_md_tick_link(struct m0_fom *fom)
Definition: md_foms.c:260
M0_INTERNAL int m0_mdstore_close(struct m0_mdstore *md, struct m0_cob *cob, struct m0_be_tx *tx)
Definition: mdstore.c:536
struct m0_fid fid
Definition: di.c:46
M0_INTERNAL int m0_md_req_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
Definition: md_foms.c:1437
M0_INTERNAL int m0_mdstore_fcreate(struct m0_mdstore *md, struct m0_fid *pfid, struct m0_cob_attr *attr, struct m0_cob **out, struct m0_be_tx *tx)
Definition: mdstore.c:209
return M0_RC(rc)
M0_INTERNAL void m0_cob_tx_credit(struct m0_cob_domain *dom, enum m0_cob_op optype, struct m0_be_tx_credit *accum)
Definition: cob.c:2281
char cer_body[0]
Definition: cob.h:511
#define M0_BE_TX_CREDIT(nr, size)
Definition: tx_credit.h:94
M0_INTERNAL void m0_mdstore_unlink_credit(struct m0_mdstore *md, struct m0_be_tx_credit *accum)
Definition: mdstore.c:380
#define M0_ENTRY(...)
Definition: trace.h:170
static const struct m0_fom_ops m0_md_fom_setxattr_ops
Definition: md_foms.c:1389
M0_INTERNAL int m0_cob_ea_set(struct m0_cob *cob, struct m0_cob_eakey *eakey, struct m0_cob_earec *earec, struct m0_be_tx *tx)
Definition: cob.c:2171
struct m0_fop_cob g_body
Definition: md_fops.h:198
Definition: buf.h:37
static const struct m0_fom_ops m0_md_fom_getxattr_ops
Definition: md_foms.c:1395
void m0_fom_init(struct m0_fom *fom, const struct m0_fom_type *fom_type, const struct m0_fom_ops *ops, struct m0_fop *fop, struct m0_fop *reply, struct m0_reqh *reqh)
Definition: fom.c:1372
static char * addr
Definition: node_k.c:37
M0_INTERNAL int m0_mdstore_link(struct m0_mdstore *md, struct m0_fid *pfid, struct m0_cob *cob, struct m0_buf *name, struct m0_be_tx *tx)
Definition: mdstore.c:295
struct m0_fop_type * f_type
Definition: fop.h:81
uint32_t b_ctime
Definition: md_fops.h:89
M0_INTERNAL void m0_mdstore_create_credit(struct m0_mdstore *md, struct m0_be_tx_credit *accum)
Definition: mdstore.c:202
return M0_ERR(-EOPNOTSUPP)
static int m0_md_tick_getattr(struct m0_fom *fom)
Definition: md_foms.c:755
struct m0_fop_type m0_fop_getxattr_rep_fopt
Definition: md_fops.c:77
struct m0_fop_type m0_fop_getattr_rep_fopt
Definition: md_fops.c:75
const char * name
Definition: trace.c:110
static void m0_md_fom_fini(struct m0_fom *fom)
Definition: md_foms.c:1308
static void attr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
Definition: dump.c:949
M0_INTERNAL void m0_bitstring_copy(struct m0_bitstring *dst, const char *src, size_t count)
Definition: bitstring.c:63
const char * ft_name
Definition: fop.h:225
struct m0_bitstring * r_pos
Definition: cob.h:608
int m0_fom_tick_generic(struct m0_fom *fom)
Definition: fom_generic.c:848
uint64_t sf_bfree
Definition: mdstore.h:49
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
uint8_t * s_buf
Definition: string.h:72
#define m0_free0(pptr)
Definition: memory.h:77
struct m0_fop_type m0_fop_unlink_rep_fopt
Definition: md_fops.c:71
m0_bcount_t b_nob
Definition: buf.h:38
static struct m0_cob * cob
Definition: bytecount.c:40
#define M0_ASSERT(cond)
static void m0_md_rename_credit(struct m0_mdstore *md, struct m0_be_tx_credit *accum)
Definition: md_foms.c:373
static const struct m0_fom_ops m0_md_fom_delxattr_ops
Definition: md_foms.c:1401
struct m0_fop_str l_path
Definition: md_fops.h:116
M0_INTERNAL void m0_md_cob_mem2wire(struct m0_fop_cob *body, const struct m0_cob_attr *attr)
Definition: md_foms.c:89
void m0_fom_phase_move(struct m0_fom *fom, int32_t rc, int phase)
Definition: fom.c:1699
struct m0_fop_type m0_fop_close_rep_fopt
Definition: md_fops.c:73
uint32_t sf_namelen
Definition: mdstore.h:53
uint32_t b_mode
Definition: md_fops.h:77
M0_INTERNAL void m0_be_tx_credit_add(struct m0_be_tx_credit *c0, const struct m0_be_tx_credit *c1)
Definition: tx_credit.c:44
uint32_t b_mtime
Definition: md_fops.h:88
static int m0_md_rename(struct m0_mdstore *md, struct m0_fid *pfid_tgt, struct m0_fid *pfid_src, struct m0_fid *tfid_tgt, struct m0_fid *tfid_src, struct m0_cob_attr *tattr, struct m0_cob_attr *sattr, struct m0_cob *tcob, struct m0_cob *scob, struct m0_be_tx *tx)
Definition: md_foms.c:380
struct m0_fop_type m0_fop_delxattr_rep_fopt
Definition: md_fops.c:78
uint64_t sf_ffree
Definition: mdstore.h:52
M0_INTERNAL void m0_fom_mod_rep_fill(struct m0_fop_mod_rep *rep, struct m0_fom *fom)
Definition: fom_generic.c:68
uint32_t cor_mode
Definition: cob.h:498
uint64_t sf_blocks
Definition: mdstore.h:48
uint64_t b_lid
Definition: md_fops.h:90
const struct m0_rpc_item_type * ri_type
Definition: item.h:200
void * m0_alloc(size_t size)
Definition: memory.c:126
M0_INTERNAL int m0_mdstore_open(struct m0_mdstore *md, struct m0_cob *cob, m0_mdstore_locate_flags_t flags, struct m0_be_tx *tx)
Definition: mdstore.c:525
static const struct m0_fom_ops m0_md_fom_readdir_ops
Definition: md_foms.c:1425
#define M0_MD_READDIR_BUFF_SIZE
Definition: md_foms.c:1069
struct m0_fop_cob o_body
Definition: md_fops.h:167
struct m0_fid b_pver
Definition: md_fops.h:93
Definition: xcode.h:73
static int md_locate(struct m0_mdstore *md, struct m0_fid *tfid, struct m0_cob **cob)
Definition: md_foms.c:1530
static const struct m0_fom_ops m0_md_fom_setattr_ops
Definition: md_foms.c:1377
Definition: reqh.h:94
struct m0_fop_type m0_fop_rename_rep_fopt
Definition: md_fops.c:81
Definition: dump.c:103
uint32_t b_atime
Definition: md_fops.h:87
M0_INTERNAL int m0_mdstore_readdir(struct m0_mdstore *md, struct m0_cob *cob, struct m0_rdpg *rdpg)
Definition: mdstore.c:705
static int m0_md_tick_generic(struct m0_fom *fom)
Definition: md_foms.c:174
static int m0_md_tick_unlink(struct m0_fom *fom)
Definition: md_foms.c:309
static const struct m0_fom_ops m0_md_fom_unlink_ops
Definition: md_foms.c:1353
#define FID_P(f)
Definition: fid.h:77
struct m0_fid sf_root
Definition: mdstore.h:54
M0_INTERNAL int m0_md_fop_init(struct m0_fop *fop, struct m0_fom *fom)
Definition: md_foms.c:1201
struct m0_fop_type m0_fop_setxattr_rep_fopt
Definition: md_fops.c:76
static int m0_md_tick_setxattr(struct m0_fom *fom)
Definition: md_foms.c:901
M0_INTERNAL int m0_mdstore_path(struct m0_mdstore *md, struct m0_fid *fid, char **path)
Definition: mdstore.c:900
static const struct m0_fom_ops m0_md_fom_open_ops
Definition: md_foms.c:1365
static int m0_md_create(struct m0_mdstore *md, struct m0_fid *pfid, struct m0_fid *tfid, struct m0_cob_attr *attr, struct m0_be_tx *tx)
Definition: md_foms.c:137
static const struct m0_fom_ops m0_md_fom_close_ops
Definition: md_foms.c:1371
struct m0_fop_cob r_tbody
Definition: md_fops.h:152
M0_INTERNAL int m0_mdstore_rename(struct m0_mdstore *md, struct m0_fid *pfid_tgt, struct m0_fid *pfid_src, struct m0_cob *cob_tgt, struct m0_cob *cob_src, struct m0_buf *tname, struct m0_buf *sname, struct m0_be_tx *tx)
Definition: mdstore.c:560
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:129
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
struct m0_fop_str g_value
Definition: md_fops.h:215
Definition: fom.h:481
static int m0_md_tick_statfs(struct m0_fom *fom)
Definition: md_foms.c:1036
M0_INTERNAL int m0_md_rep_fom_create(struct m0_fop *fop, struct m0_fom **m, struct m0_reqh *reqh)
Definition: md_foms.c:1431
size_t(* fo_home_locality)(const struct m0_fom *fom)
Definition: fom.h:671
struct m0_fop_type m0_fop_link_rep_fopt
Definition: md_fops.c:70
uint64_t b_blocks
Definition: md_fops.h:80
struct m0_reqh reqh
Definition: rm_foms.c:48
M0_INTERNAL void m0_mdstore_rename_credit(struct m0_mdstore *md, struct m0_be_tx_credit *accum)
Definition: mdstore.c:553
struct m0_fop_type m0_fop_listxattr_rep_fopt
Definition: md_fops.c:79
struct m0_fop_str r_path
Definition: md_fops.h:254
Definition: fid.h:38
uint64_t b_blksize
Definition: md_fops.h:79
#define M0_COB_ALL
Definition: cob.h:352
M0_INTERNAL void m0_mdstore_setattr_credit(struct m0_mdstore *md, struct m0_be_tx_credit *accum)
Definition: mdstore.c:626
M0_INTERNAL int m0_cob_eakey_make(struct m0_cob_eakey **keyh, const struct m0_fid *fid, const char *name, size_t namelen)
Definition: cob.c:181
uint64_t b_version
Definition: md_fops.h:74
M0_INTERNAL void m0_bitstring_free(struct m0_bitstring *c)
Definition: bitstring.c:58
static const struct m0_fom_ops m0_md_fom_listxattr_ops
Definition: md_foms.c:1407
uint32_t cer_size
Definition: cob.h:510
struct m0_fop_cob r_sbody
Definition: md_fops.h:151
struct m0_buf r_buf
Definition: cob.h:609
static void m0_md_req_fom_fini(struct m0_fom *fom)
Definition: md_foms.c:1328
struct m0_fop_str r_tpath
Definition: md_fops.h:154
M0_INTERNAL int m0_mdstore_unlink(struct m0_mdstore *md, struct m0_fid *pfid, struct m0_cob *cob, struct m0_buf *name, struct m0_be_tx *tx)
Definition: mdstore.c:388
struct m0_fom fm_fom
Definition: md_foms.h:40
M0_INTERNAL void * m0_bitstring_buf_get(struct m0_bitstring *c)
Definition: bitstring.c:33
struct m0_rpc_item * m0_fop_to_rpc_item(const struct m0_fop *fop)
Definition: fop.c:338
static int m0_md_tick_getxattr(struct m0_fom *fom)
Definition: md_foms.c:823
static int m0_md_tick_close(struct m0_fom *fom)
Definition: md_foms.c:558
static struct m0_fop * fop
Definition: item.c:57
struct m0_cob_omgrec co_omgrec
Definition: cob.h:592
static const struct m0_fom_ops m0_md_fom_lookup_ops
Definition: md_foms.c:1413
Definition: cob.h:607
uint64_t sf_bavail
Definition: mdstore.h:50
M0_INTERNAL void m0_mdstore_link_credit(struct m0_mdstore *md, struct m0_be_tx_credit *accum)
Definition: mdstore.c:288
static size_t m0_md_req_fom_locality_get(const struct m0_fom *fom)
Definition: md_foms.c:1333
static int m0_md_tick_delxattr(struct m0_fom *fom)
Definition: md_foms.c:972
M0_INTERNAL int m0_mdstore_setattr(struct m0_mdstore *md, struct m0_cob *cob, struct m0_cob_attr *attr, struct m0_be_tx *tx)
Definition: mdstore.c:632
static const struct m0_fom_ops m0_md_fom_create_ops
Definition: md_foms.c:1341
struct m0_fid b_pfid
Definition: md_fops.h:91
static int m0_md_req_path_get(struct m0_mdstore *mdstore, struct m0_fid *fid, struct m0_fop_str *str)
Definition: md_foms.c:1180
#define out(...)
Definition: gen.c:41
uint32_t s_len
Definition: string.h:71
M0_INTERNAL const struct m0_fid * m0_cob_fid(const struct m0_cob *cob)
Definition: cob.c:122
struct m0_fop_type m0_fop_setattr_rep_fopt
Definition: md_fops.c:74
struct m0_fom_ops ops
Definition: io_foms.c:623
M0_INTERNAL int m0_mdstore_lookup(struct m0_mdstore *md, struct m0_fid *pfid, struct m0_buf *name, struct m0_cob **cob)
Definition: mdstore.c:863
struct m0_bitstring * r_end
Definition: cob.h:610
struct m0_fop_type m0_fop_open_rep_fopt
Definition: md_fops.c:72
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL int m0_mdstore_getattr(struct m0_mdstore *md, struct m0_cob *cob, struct m0_cob_attr *attr)
Definition: mdstore.c:642
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
uint64_t sf_type
Definition: mdstore.h:46
Definition: fop.h:79
#define FID_F
Definition: fid.h:75
M0_INTERNAL struct m0_reqh * m0_fom_reqh(const struct m0_fom *fom)
Definition: fom.c:283
struct m0_fop_type m0_fop_lookup_rep_fopt
Definition: md_fops.c:69
struct m0_fop_type m0_fop_statfs_rep_fopt
Definition: md_fops.c:80
struct m0_fop * rep_fop
Definition: dir.c:334
M0_INTERNAL bool m0_fom_invariant(const struct m0_fom *fom)
Definition: fom.c:311
Definition: tx.h:280
static const struct m0_fom_ops m0_md_fom_getattr_ops
Definition: md_foms.c:1383
struct m0_fop_type m0_fop_readdir_rep_fopt
Definition: md_fops.c:82