1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LLITE
30 #include <sys/types.h>
32 #include <sys/fcntl.h>
33 #include <sys/queue.h>
34 #include <sys/capability.h>
36 # include <sys/statvfs.h>
38 # include <sys/statfs.h>
49 #include "llite_lib.h"
51 static void llu_fsop_gone(struct filesys *fs)
53 struct llu_sb_info *sbi = (struct llu_sb_info *) fs->fs_private;
54 struct obd_device *obd = class_exp2obd(sbi->ll_mdc_exp);
55 struct ll_fid rootfid;
58 list_del(&sbi->ll_conn_chain);
59 obd_disconnect(sbi->ll_osc_exp, 0);
61 /* NULL request to force sync on the MDS, and get the last_committed
62 * value to flush remaining RPCs from the sending queue on client.
64 * XXX This should be an mdc_sync() call to sync the whole MDS fs,
65 * which we can call for other reasons as well.
67 if (!obd->obd_no_recov)
68 mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
70 obd_disconnect(sbi->ll_mdc_exp, 0);
72 OBD_FREE(sbi, sizeof(*sbi));
77 static struct inode_ops llu_inode_ops;
79 void llu_update_inode(struct inode *inode, struct mds_body *body,
80 struct lov_stripe_md *lsm)
82 struct llu_inode_info *lli = llu_i2info(inode);
84 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
86 if (lli->lli_smd == NULL) {
88 lli->lli_maxbytes = lsm->lsm_maxbytes;
89 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
90 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
92 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
93 CERROR("lsm mismatch for inode %ld\n",
100 if (body->valid & OBD_MD_FLID)
101 lli->lli_st_ino = body->ino;
102 if (body->valid & OBD_MD_FLATIME)
103 LTIME_S(lli->lli_st_atime) = body->atime;
104 if (body->valid & OBD_MD_FLMTIME)
105 LTIME_S(lli->lli_st_mtime) = body->mtime;
106 if (body->valid & OBD_MD_FLCTIME)
107 LTIME_S(lli->lli_st_ctime) = body->ctime;
108 if (body->valid & OBD_MD_FLMODE)
109 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT)|(body->mode & ~S_IFMT);
110 if (body->valid & OBD_MD_FLTYPE)
111 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT)|(body->mode & S_IFMT);
112 if (body->valid & OBD_MD_FLUID)
113 lli->lli_st_uid = body->uid;
114 if (body->valid & OBD_MD_FLGID)
115 lli->lli_st_gid = body->gid;
116 if (body->valid & OBD_MD_FLFLAGS)
117 lli->lli_st_flags = body->flags;
118 if (body->valid & OBD_MD_FLNLINK)
119 lli->lli_st_nlink = body->nlink;
120 if (body->valid & OBD_MD_FLGENER)
121 lli->lli_st_generation = body->generation;
122 if (body->valid & OBD_MD_FLRDEV)
123 lli->lli_st_rdev = body->rdev;
124 if (body->valid & OBD_MD_FLSIZE)
125 lli->lli_st_size = body->size;
126 if (body->valid & OBD_MD_FLBLOCKS)
127 lli->lli_st_blocks = body->blocks;
130 if (body->valid & OBD_MD_FLID)
131 lli->lli_fid.id = body->ino;
132 if (body->valid & OBD_MD_FLGENER)
133 lli->lli_fid.generation = body->generation;
134 if (body->valid & OBD_MD_FLTYPE)
135 lli->lli_fid.f_type = body->mode & S_IFMT;
138 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
140 struct llu_inode_info *lli = llu_i2info(dst);
142 valid &= src->o_valid;
144 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
145 CDEBUG(D_INODE, "valid %x, cur time %lu/%lu, new %lu/%lu\n",
147 LTIME_S(lli->lli_st_mtime), LTIME_S(lli->lli_st_ctime),
148 (long)src->o_mtime, (long)src->o_ctime);
150 if (valid & OBD_MD_FLATIME)
151 LTIME_S(lli->lli_st_atime) = src->o_atime;
152 if (valid & OBD_MD_FLMTIME)
153 LTIME_S(lli->lli_st_mtime) = src->o_mtime;
154 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(lli->lli_st_ctime))
155 LTIME_S(lli->lli_st_ctime) = src->o_ctime;
156 if (valid & OBD_MD_FLSIZE)
157 lli->lli_st_size = src->o_size;
158 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
159 lli->lli_st_blocks = src->o_blocks;
160 if (valid & OBD_MD_FLBLKSZ)
161 lli->lli_st_blksize = src->o_blksize;
162 if (valid & OBD_MD_FLTYPE)
163 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
164 if (valid & OBD_MD_FLMODE)
165 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
166 if (valid & OBD_MD_FLUID)
167 lli->lli_st_uid = src->o_uid;
168 if (valid & OBD_MD_FLGID)
169 lli->lli_st_gid = src->o_gid;
170 if (valid & OBD_MD_FLFLAGS)
171 lli->lli_st_flags = src->o_flags;
172 if (valid & OBD_MD_FLGENER)
173 lli->lli_st_generation = src->o_generation;
176 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
177 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
179 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
181 struct llu_inode_info *lli = llu_i2info(src);
182 obd_flag newvalid = 0;
184 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
185 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
186 valid, LTIME_S(lli->lli_st_mtime),
187 LTIME_S(lli->lli_st_ctime));
189 if (valid & OBD_MD_FLATIME) {
190 dst->o_atime = LTIME_S(lli->lli_st_atime);
191 newvalid |= OBD_MD_FLATIME;
193 if (valid & OBD_MD_FLMTIME) {
194 dst->o_mtime = LTIME_S(lli->lli_st_mtime);
195 newvalid |= OBD_MD_FLMTIME;
197 if (valid & OBD_MD_FLCTIME) {
198 dst->o_ctime = LTIME_S(lli->lli_st_ctime);
199 newvalid |= OBD_MD_FLCTIME;
201 if (valid & OBD_MD_FLSIZE) {
202 dst->o_size = lli->lli_st_size;
203 newvalid |= OBD_MD_FLSIZE;
205 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
206 dst->o_blocks = lli->lli_st_blocks;
207 newvalid |= OBD_MD_FLBLOCKS;
209 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
210 dst->o_blksize = lli->lli_st_blksize;
211 newvalid |= OBD_MD_FLBLKSZ;
213 if (valid & OBD_MD_FLTYPE) {
214 dst->o_mode = (dst->o_mode & S_IALLUGO)|(lli->lli_st_mode & S_IFMT);
215 newvalid |= OBD_MD_FLTYPE;
217 if (valid & OBD_MD_FLMODE) {
218 dst->o_mode = (dst->o_mode & S_IFMT)|(lli->lli_st_mode & S_IALLUGO);
219 newvalid |= OBD_MD_FLMODE;
221 if (valid & OBD_MD_FLUID) {
222 dst->o_uid = lli->lli_st_uid;
223 newvalid |= OBD_MD_FLUID;
225 if (valid & OBD_MD_FLGID) {
226 dst->o_gid = lli->lli_st_gid;
227 newvalid |= OBD_MD_FLGID;
229 if (valid & OBD_MD_FLFLAGS) {
230 dst->o_flags = lli->lli_st_flags;
231 newvalid |= OBD_MD_FLFLAGS;
233 if (valid & OBD_MD_FLGENER) {
234 dst->o_generation = lli->lli_st_generation;
235 newvalid |= OBD_MD_FLGENER;
238 dst->o_valid |= newvalid;
242 * really does the getattr on the inode and updates its fields
244 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
246 struct llu_inode_info *lli = llu_i2info(inode);
247 struct obd_export *exp = llu_i2obdexp(inode);
248 struct ptlrpc_request_set *set;
250 obd_flag refresh_valid;
257 memset(&oa, 0, sizeof oa);
258 oa.o_id = lsm->lsm_object_id;
260 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
261 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
264 set = ptlrpc_prep_set();
266 CERROR ("ENOMEM allocing request set\n");
269 rc = obd_getattr_async(exp, &oa, lsm, set);
271 rc = ptlrpc_set_wait(set);
272 ptlrpc_set_destroy(set);
277 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
278 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
280 /* We set this flag in commit write as we extend the file size. When
281 * the bit is set and the lock is canceled that covers the file size,
282 * we clear the bit. This is enough to protect the window where our
283 * local size extension is needed for writeback. However, it relies on
284 * behaviour that won't be true in the near future. This assumes that
285 * all getattr callers get extent locks, which they currnetly do. It
286 * also assumes that we only send discarding asts for {0,eof} truncates
287 * as is currently the case. This will have to be replaced by the
288 * proper eoc communication between clients and the ost, which is on
290 if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
291 if (oa.o_size < lli->lli_st_size)
292 refresh_valid &= ~OBD_MD_FLSIZE;
294 clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
297 obdo_refresh_inode(inode, &oa, refresh_valid);
302 static struct inode* llu_new_inode(struct filesys *fs,
306 struct llu_inode_info *lli;
308 OBD_ALLOC(lli, sizeof(*lli));
312 /* initialize lli here */
313 lli->lli_sbi = llu_fs2sbi(fs);
315 lli->lli_symlink_name = NULL;
317 lli->lli_maxbytes = (__u64)(~0UL);
318 lli->lli_file_data = NULL;
320 lli->lli_sysio_fid.fid_data = &lli->lli_fid;
321 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_fid);
323 memcpy(&lli->lli_fid, fid, sizeof(*fid));
325 /* file identifier is needed by functions like _sysio_i_find() */
326 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
327 #ifndef AUTOMOUNT_FILE_NAME
328 fid->f_type & S_IFMT,
330 fid->f_type, /* all of the bits! */
333 &llu_inode_ops, lli);
336 OBD_FREE(lli, sizeof(*lli));
341 static int llu_have_md_lock(struct inode *inode, __u64 lockpart)
343 struct llu_sb_info *sbi = llu_i2sbi(inode);
344 struct llu_inode_info *lli = llu_i2info(inode);
345 struct lustre_handle lockh;
346 struct ldlm_res_id res_id = { .name = {0} };
347 struct obd_device *obddev;
348 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
354 obddev = sbi->ll_mdc_exp->exp_obd;
355 res_id.name[0] = lli->lli_st_ino;
356 res_id.name[1] = lli->lli_st_generation;
358 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
360 /* FIXME use LDLM_FL_TEST_LOCK instead */
361 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
362 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
363 &policy, LCK_PR, &lockh)) {
364 ldlm_lock_decref(&lockh, LCK_PR);
368 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
369 &policy, LCK_PW, &lockh)) {
370 ldlm_lock_decref(&lockh, LCK_PW);
376 static int llu_inode_revalidate(struct inode *inode)
378 struct llu_inode_info *lli = llu_i2info(inode);
379 struct lov_stripe_md *lsm = NULL;
383 CERROR("REPORT THIS LINE TO PETER\n");
387 if (!llu_have_md_lock(inode, MDS_INODELOCK_UPDATE)) {
389 struct ptlrpc_request *req = NULL;
390 struct llu_sb_info *sbi = llu_i2sbi(inode);
392 unsigned long valid = 0;
395 /* Why don't we update all valid MDS fields here, if we're
396 * doing an RPC anyways? -phil */
397 if (S_ISREG(lli->lli_st_mode)) {
398 ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
399 valid |= OBD_MD_FLEASIZE;
401 ll_inode2fid(&fid, inode);
402 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
404 CERROR("failure %d inode %lu\n", rc, lli->lli_st_ino);
407 rc = mdc_req2lustre_md(req, 0, sbi->ll_osc_exp, &md);
409 /* XXX Too paranoid? */
410 if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) &&
411 !((md.body->valid & OBD_MD_FLNLINK) &&
412 (md.body->nlink == 0))) {
413 CERROR("Asked for %s eadata but got %s (%d)\n",
414 (valid & OBD_MD_FLEASIZE) ? "some" : "no",
415 (md.body->valid & OBD_MD_FLEASIZE) ? "some":"none",
416 md.body->eadatasize);
419 ptlrpc_req_finished(req);
424 llu_update_inode(inode, md.body, md.lsm);
425 if (md.lsm != NULL && llu_i2info(inode)->lli_smd != md.lsm)
426 obd_free_memmd(sbi->ll_osc_exp, &md.lsm);
428 if (md.body->valid & OBD_MD_FLSIZE)
429 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
430 &llu_i2info(inode)->lli_flags);
431 ptlrpc_req_finished(req);
434 lsm = llu_i2info(inode)->lli_smd;
435 if (!lsm) /* object not yet allocated, don't validate size */
438 /* ll_glimpse_size will prefer locally cached writes if they extend
444 err = llu_glimpse_size(inode, &lvb);
445 lli->lli_st_size = lvb.lvb_size;
450 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
452 struct llu_inode_info *lli = llu_i2info(ino);
454 b->st_dev = lli->lli_st_dev;
455 b->st_ino = lli->lli_st_ino;
456 b->st_mode = lli->lli_st_mode;
457 b->st_nlink = lli->lli_st_nlink;
458 b->st_uid = lli->lli_st_uid;
459 b->st_gid = lli->lli_st_gid;
460 b->st_rdev = lli->lli_st_rdev;
461 b->st_size = lli->lli_st_size;
462 b->st_blksize = lli->lli_st_blksize;
463 b->st_blocks = lli->lli_st_blocks;
464 b->st_atime = lli->lli_st_atime;
465 b->st_mtime = lli->lli_st_mtime;
466 b->st_ctime = lli->lli_st_ctime;
469 static int llu_iop_getattr(struct pnode *pno,
471 struct intnl_stat *b)
478 LASSERT(pno->p_base->pb_ino);
479 ino = pno->p_base->pb_ino;
481 LASSERT(!pno || pno->p_base->pb_ino == ino);
484 /* libsysio might call us directly without intent lock,
485 * we must re-fetch the attrs here
487 rc = llu_inode_revalidate(ino);
489 copy_stat_buf(ino, b);
490 LASSERT(!llu_i2info(ino)->lli_it);
496 static int null_if_equal(struct ldlm_lock *lock, void *data)
498 if (data == lock->l_ast_data)
499 lock->l_ast_data = NULL;
501 if (lock->l_req_mode != lock->l_granted_mode)
502 return LDLM_ITER_STOP;
504 return LDLM_ITER_CONTINUE;
507 void llu_clear_inode(struct inode *inode)
510 struct llu_inode_info *lli = llu_i2info(inode);
511 struct llu_sb_info *sbi = llu_i2sbi(inode);
514 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu(%p)\n", lli->lli_st_ino,
515 lli->lli_st_generation, inode);
517 ll_inode2fid(&fid, inode);
518 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
519 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
522 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
523 null_if_equal, inode);
526 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
530 if (lli->lli_symlink_name) {
531 OBD_FREE(lli->lli_symlink_name,
532 strlen(lli->lli_symlink_name) + 1);
533 lli->lli_symlink_name = NULL;
539 void llu_iop_gone(struct inode *inode)
541 struct llu_inode_info *lli = llu_i2info(inode);
544 llu_clear_inode(inode);
546 OBD_FREE(lli, sizeof(*lli));
550 static int inode_setattr(struct inode * inode, struct iattr * attr)
552 unsigned int ia_valid = attr->ia_valid;
553 struct llu_inode_info *lli = llu_i2info(inode);
556 if (ia_valid & ATTR_SIZE) {
557 error = llu_vmtruncate(inode, attr->ia_size);
562 if (ia_valid & ATTR_UID)
563 lli->lli_st_uid = attr->ia_uid;
564 if (ia_valid & ATTR_GID)
565 lli->lli_st_gid = attr->ia_gid;
566 if (ia_valid & ATTR_ATIME)
567 lli->lli_st_atime = attr->ia_atime;
568 if (ia_valid & ATTR_MTIME)
569 lli->lli_st_mtime = attr->ia_mtime;
570 if (ia_valid & ATTR_CTIME)
571 lli->lli_st_ctime = attr->ia_ctime;
572 if (ia_valid & ATTR_MODE) {
573 lli->lli_st_mode = attr->ia_mode;
574 if (!in_group_p(lli->lli_st_gid) && !capable(CAP_FSETID))
575 lli->lli_st_mode &= ~S_ISGID;
577 /* mark_inode_dirty(inode); */
582 /* If this inode has objects allocated to it (lsm != NULL), then the OST
583 * object(s) determine the file size and mtime. Otherwise, the MDS will
584 * keep these values until such a time that objects are allocated for it.
585 * We do the MDS operations first, as it is checking permissions for us.
586 * We don't to the MDS RPC if there is nothing that we want to store there,
587 * otherwise there is no harm in updating mtime/atime on the MDS if we are
588 * going to do an RPC anyways.
590 * If we are doing a truncate, we will send the mtime and ctime updates
591 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
592 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
595 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
597 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
598 struct llu_sb_info *sbi = llu_i2sbi(inode);
599 struct llu_inode_info *lli = llu_i2info(inode);
600 struct ptlrpc_request *request = NULL;
601 struct mdc_op_data op_data;
602 int ia_valid = attr->ia_valid;
606 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
608 if (ia_valid & ATTR_SIZE) {
609 if (attr->ia_size > ll_file_maxbytes(inode)) {
610 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
611 attr->ia_size, ll_file_maxbytes(inode));
615 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
618 /* We mark all of the fields "set" so MDS/OST does not re-set them */
619 if (attr->ia_valid & ATTR_CTIME) {
620 attr->ia_ctime = CURRENT_TIME;
621 attr->ia_valid |= ATTR_CTIME_SET;
623 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
624 attr->ia_atime = CURRENT_TIME;
625 attr->ia_valid |= ATTR_ATIME_SET;
627 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
628 attr->ia_mtime = CURRENT_TIME;
629 attr->ia_valid |= ATTR_MTIME_SET;
632 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
633 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
634 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
635 LTIME_S(CURRENT_TIME));
637 attr->ia_valid &= ~ATTR_SIZE;
639 /* If only OST attributes being set on objects, don't do MDS RPC.
640 * In that case, we need to check permissions and update the local
641 * inode ourselves so we can call obdo_from_inode() always. */
642 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
644 llu_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
646 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
647 attr, NULL, 0, NULL, 0, &request);
650 ptlrpc_req_finished(request);
651 if (rc != -EPERM && rc != -EACCES)
652 CERROR("mdc_setattr fails: rc = %d\n", rc);
656 rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
658 ptlrpc_req_finished(request);
661 llu_update_inode(inode, md.body, md.lsm);
662 ptlrpc_req_finished(request);
664 if (!md.lsm || !S_ISREG(lli->lli_st_mode)) {
665 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
669 /* The OST doesn't check permissions, but the alternative is
670 * a gratuitous RPC to the MDS. We already rely on the client
671 * to do read/write/truncate permission checks, so is mtime OK?
673 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
674 /* from sys_utime() */
675 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
676 if (current->fsuid != lli->lli_st_uid &&
677 (rc = ll_permission(inode, 0/*MAY_WRITE*/, NULL)) != 0)
680 /* from inode_change_ok() */
681 if (current->fsuid != lli->lli_st_uid &&
682 !capable(CAP_FOWNER))
687 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
688 inode_setattr(inode, attr);
691 if (ia_valid & ATTR_SIZE) {
692 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
694 struct lustre_handle lockh = { 0 };
695 int err, ast_flags = 0;
696 /* XXX when we fix the AST intents to pass the discard-range
697 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
699 if (attr->ia_size == 0)
700 ast_flags = LDLM_AST_DISCARD_DATA;
702 rc = llu_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
704 if (rc != ELDLM_OK) {
710 rc = llu_vmtruncate(inode, attr->ia_size);
712 set_bit(LLI_F_HAVE_OST_SIZE_LOCK,
713 &llu_i2info(inode)->lli_flags);
715 /* unlock now as we don't mind others file lockers racing with
716 * the mds updates below? */
717 err = llu_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
719 CERROR("llu_extent_unlock failed: %d\n", err);
723 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
726 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
727 lli->lli_st_ino, LTIME_S(attr->ia_mtime));
728 oa.o_id = lsm->lsm_object_id;
729 oa.o_valid = OBD_MD_FLID;
730 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
731 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
732 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
734 CERROR("obd_setattr fails: rc=%d\n", rc);
739 /* here we simply act as a thin layer to glue it with
740 * llu_setattr_raw(), which is copy from kernel
742 static int llu_iop_setattr(struct pnode *pno,
745 struct intnl_stat *stbuf)
750 memset(&iattr, 0, sizeof(iattr));
752 if (mask & SETATTR_MODE) {
753 iattr.ia_mode = stbuf->st_mode;
754 iattr.ia_valid |= ATTR_MODE;
756 if (mask & SETATTR_MTIME) {
757 iattr.ia_mtime = stbuf->st_mtime;
758 iattr.ia_valid |= ATTR_MTIME;
760 if (mask & SETATTR_ATIME) {
761 iattr.ia_atime = stbuf->st_atime;
762 iattr.ia_valid |= ATTR_ATIME;
764 if (mask & SETATTR_UID) {
765 iattr.ia_uid = stbuf->st_uid;
766 iattr.ia_valid |= ATTR_UID;
768 if (mask & SETATTR_GID) {
769 iattr.ia_gid = stbuf->st_gid;
770 iattr.ia_valid |= ATTR_GID;
772 if (mask & SETATTR_LEN) {
773 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
774 iattr.ia_valid |= ATTR_SIZE;
777 iattr.ia_valid |= ATTR_RAW;
779 RETURN(llu_setattr_raw(ino, &iattr));
782 #define EXT2_LINK_MAX 32000
784 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
786 struct inode *dir = pno->p_base->pb_parent->pb_ino;
787 struct qstr *qstr = &pno->p_base->pb_name;
788 const char *name = qstr->name;
790 struct ptlrpc_request *request = NULL;
791 struct llu_sb_info *sbi = llu_i2sbi(dir);
792 struct mdc_op_data op_data;
796 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
799 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
800 err = mdc_create(sbi->ll_mdc_exp, &op_data,
801 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
802 current->fsuid, current->fsgid, 0, &request);
803 ptlrpc_req_finished(request);
807 static int llu_readlink_internal(struct inode *inode,
808 struct ptlrpc_request **request,
811 struct llu_inode_info *lli = llu_i2info(inode);
812 struct llu_sb_info *sbi = llu_i2sbi(inode);
814 struct mds_body *body;
815 int rc, symlen = lli->lli_st_size + 1;
820 if (lli->lli_symlink_name) {
821 *symname = lli->lli_symlink_name;
822 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
826 ll_inode2fid(&fid, inode);
827 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
828 OBD_MD_LINKNAME, symlen, request);
830 CERROR("inode %lu: rc = %d\n", lli->lli_st_ino, rc);
834 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
835 LASSERT (body != NULL);
836 LASSERT_REPSWABBED (*request, 0);
838 if ((body->valid & OBD_MD_LINKNAME) == 0) {
839 CERROR ("OBD_MD_LINKNAME not set on reply\n");
840 GOTO (failed, rc = -EPROTO);
843 LASSERT (symlen != 0);
844 if (body->eadatasize != symlen) {
845 CERROR ("inode %lu: symlink length %d not expected %d\n",
846 lli->lli_st_ino, body->eadatasize - 1, symlen - 1);
847 GOTO (failed, rc = -EPROTO);
850 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
851 if (*symname == NULL ||
852 strnlen (*symname, symlen) != symlen - 1) {
853 /* not full/NULL terminated */
854 CERROR ("inode %lu: symlink not NULL terminated string"
855 "of length %d\n", lli->lli_st_ino, symlen - 1);
856 GOTO (failed, rc = -EPROTO);
859 OBD_ALLOC(lli->lli_symlink_name, symlen);
860 /* do not return an error if we cannot cache the symlink locally */
861 if (lli->lli_symlink_name)
862 memcpy(lli->lli_symlink_name, *symname, symlen);
867 ptlrpc_req_finished (*request);
871 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
873 struct inode *inode = pno->p_base->pb_ino;
874 struct ptlrpc_request *request;
879 rc = llu_readlink_internal(inode, &request, &symname);
884 strncpy(data, symname, bufsize);
886 ptlrpc_req_finished(request);
891 static int llu_iop_mknod_raw(struct pnode *pno,
895 struct ptlrpc_request *request = NULL;
896 struct inode *dir = pno->p_parent->p_base->pb_ino;
897 struct llu_sb_info *sbi = llu_i2sbi(dir);
898 struct mdc_op_data op_data;
902 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu\n",
903 pno->p_base->pb_name.name, llu_i2info(dir)->lli_st_ino);
905 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
908 mode &= ~current->fs->umask;
910 switch (mode & S_IFMT) {
913 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
918 llu_prepare_mdc_op_data(&op_data, dir, NULL,
919 pno->p_base->pb_name.name,
920 pno->p_base->pb_name.len,
922 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
923 current->fsuid, current->fsgid, dev, &request);
924 ptlrpc_req_finished(request);
935 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
937 struct inode *src = old->p_base->pb_ino;
938 struct inode *dir = new->p_parent->p_base->pb_ino;
939 const char *name = new->p_base->pb_name.name;
940 int namelen = new->p_base->pb_name.len;
941 struct ptlrpc_request *request = NULL;
942 struct mdc_op_data op_data;
949 llu_prepare_mdc_op_data(&op_data, src, dir, name, namelen, 0);
950 rc = mdc_link(llu_i2sbi(src)->ll_mdc_exp, &op_data, &request);
951 ptlrpc_req_finished(request);
956 static int llu_iop_unlink_raw(struct pnode *pno)
958 struct inode *dir = pno->p_base->pb_parent->pb_ino;
959 struct qstr *qstr = &pno->p_base->pb_name;
960 const char *name = qstr->name;
962 struct inode *target = pno->p_base->pb_ino;
963 struct ptlrpc_request *request = NULL;
964 struct mdc_op_data op_data;
970 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
971 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
973 rc = llu_objects_destroy(request, dir);
975 llu_i2info(target)->lli_stale_flag = 1;
976 unhook_stale_inode(pno);
979 ptlrpc_req_finished(request);
984 * following cases need to be considered later:
985 * - rename an opened file/dir
986 * - an opened file be removed in rename
987 * - rename to remove and hardlink (?opened)
989 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
991 struct inode *src = old->p_parent->p_base->pb_ino;
992 struct inode *tgt = new->p_parent->p_base->pb_ino;
993 struct inode *tgtinode = new->p_base->pb_ino;
994 const char *oldname = old->p_base->pb_name.name;
995 int oldnamelen = old->p_base->pb_name.len;
996 const char *newname = new->p_base->pb_name.name;
997 int newnamelen = new->p_base->pb_name.len;
998 struct ptlrpc_request *request = NULL;
999 struct mdc_op_data op_data;
1006 llu_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0);
1007 rc = mdc_rename(llu_i2sbi(src)->ll_mdc_exp, &op_data,
1008 oldname, oldnamelen, newname, newnamelen,
1011 rc = llu_objects_destroy(request, src);
1014 llu_i2info(tgtinode)->lli_stale_flag = 1;
1015 unhook_stale_inode(new);
1019 ptlrpc_req_finished(request);
1024 #ifdef _HAVE_STATVFS
1025 static int llu_statfs_internal(struct llu_sb_info *sbi,
1026 struct obd_statfs *osfs,
1027 unsigned long max_age)
1029 struct obd_statfs obd_osfs;
1033 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1035 CERROR("mdc_statfs fails: rc = %d\n", rc);
1039 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1040 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1042 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1044 CERROR("obd_statfs fails: rc = %d\n", rc);
1048 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1049 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1052 osfs->os_blocks = obd_osfs.os_blocks;
1053 osfs->os_bfree = obd_osfs.os_bfree;
1054 osfs->os_bavail = obd_osfs.os_bavail;
1056 /* If we don't have as many objects free on the OST as inodes
1057 * on the MDS, we reduce the total number of inodes to
1058 * compensate, so that the "inodes in use" number is correct.
1060 if (obd_osfs.os_ffree < osfs->os_ffree) {
1061 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1063 osfs->os_ffree = obd_osfs.os_ffree;
1069 static int llu_statfs(struct llu_sb_info *sbi, struct statfs *sfs)
1071 struct obd_statfs osfs;
1074 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1076 /* For now we will always get up-to-date statfs values, but in the
1077 * future we may allow some amount of caching on the client (e.g.
1078 * from QOS or lprocfs updates). */
1079 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1083 statfs_unpack(sfs, &osfs);
1085 if (sizeof(sfs->f_blocks) == 4) {
1086 while (osfs.os_blocks > ~0UL) {
1089 osfs.os_blocks >>= 1;
1090 osfs.os_bfree >>= 1;
1091 osfs.os_bavail >>= 1;
1095 sfs->f_blocks = osfs.os_blocks;
1096 sfs->f_bfree = osfs.os_bfree;
1097 sfs->f_bavail = osfs.os_bavail;
1102 static int llu_iop_statvfs(struct pnode *pno,
1104 struct intnl_statvfs *buf)
1111 LASSERT(pno->p_base->pb_ino);
1112 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1116 /* from native driver */
1117 buf->f_bsize = fs.f_bsize; /* file system block size */
1118 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1119 buf->f_blocks = fs.f_blocks;
1120 buf->f_bfree = fs.f_bfree;
1121 buf->f_bavail = fs.f_bavail;
1122 buf->f_files = fs.f_files; /* Total number serial numbers */
1123 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1124 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1125 buf->f_fsid = fs.f_fsid.__val[1];
1126 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1127 buf->f_namemax = fs.f_namelen;
1132 #endif /* _HAVE_STATVFS */
1134 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1136 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1137 struct qstr *qstr = &pno->p_base->pb_name;
1138 const char *name = qstr->name;
1139 int len = qstr->len;
1140 struct ptlrpc_request *request = NULL;
1141 struct llu_inode_info *lli = llu_i2info(dir);
1142 struct mdc_op_data op_data;
1145 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1146 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1148 if (lli->lli_st_nlink >= EXT2_LINK_MAX)
1151 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
1152 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1153 err = mdc_create(llu_i2sbi(dir)->ll_mdc_exp, &op_data, NULL, 0, mode,
1154 current->fsuid, current->fsgid, 0, &request);
1155 ptlrpc_req_finished(request);
1159 static int llu_iop_rmdir_raw(struct pnode *pno)
1161 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1162 struct qstr *qstr = &pno->p_base->pb_name;
1163 const char *name = qstr->name;
1164 int len = qstr->len;
1165 struct ptlrpc_request *request = NULL;
1166 struct mdc_op_data op_data;
1167 struct llu_inode_info *lli = llu_i2info(dir);
1170 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1171 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1173 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, S_IFDIR);
1174 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1175 ptlrpc_req_finished(request);
1177 /* libsysio: remove the pnode right away */
1179 llu_i2info(pno->p_base->pb_ino)->lli_stale_flag = 1;
1180 unhook_stale_inode(pno);
1186 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap)
1188 CERROR("liblustre did not support fcntl\n");
1192 static int llu_get_grouplock(struct inode *inode, unsigned long arg)
1194 struct llu_inode_info *lli = llu_i2info(inode);
1195 struct ll_file_data *fd = lli->lli_file_data;
1196 ldlm_policy_data_t policy = { .l_extent = { .start = 0,
1197 .end = OBD_OBJECT_EOF}};
1198 struct lustre_handle lockh = { 0 };
1199 struct lov_stripe_md *lsm = lli->lli_smd;
1204 if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
1208 policy.l_extent.gid = arg;
1209 if (lli->lli_open_flags & O_NONBLOCK)
1210 flags = LDLM_FL_BLOCK_NOWAIT;
1212 err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
1217 fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
1219 memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
1224 static int llu_put_grouplock(struct inode *inode, unsigned long arg)
1226 struct llu_inode_info *lli = llu_i2info(inode);
1227 struct ll_file_data *fd = lli->lli_file_data;
1228 struct lov_stripe_md *lsm = lli->lli_smd;
1232 if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
1235 if (fd->fd_gid != arg)
1238 fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
1240 err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
1245 memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
1250 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1256 case LL_IOC_GROUP_LOCK:
1257 arg = va_arg(ap, unsigned long);
1258 return llu_get_grouplock(ino, arg);
1259 case LL_IOC_GROUP_UNLOCK:
1260 arg = va_arg(ap, unsigned long);
1261 return llu_put_grouplock(ino, arg);
1264 CERROR("did not support ioctl cmd %lx\n", request);
1269 * we already do syncronous read/write
1271 static int llu_iop_sync(struct inode *inode)
1276 static int llu_iop_datasync(struct inode *inode)
1281 struct filesys_ops llu_filesys_ops =
1283 fsop_gone: llu_fsop_gone,
1286 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1288 struct inode *inode;
1290 struct file_identifier fileid = {&fid, sizeof(fid)};
1292 if ((md->body->valid &
1293 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1294 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) {
1295 /* FIXME this is workaround for for open(O_CREAT),
1296 * see lookup_it_finish(). */
1297 return ERR_PTR(-EPERM);
1300 /* try to find existing inode */
1301 fid.id = md->body->ino;
1302 fid.generation = md->body->generation;
1303 fid.f_type = md->body->mode & S_IFMT;
1305 inode = _sysio_i_find(fs, &fileid);
1307 struct llu_inode_info *lli = llu_i2info(inode);
1309 if (lli->lli_stale_flag ||
1310 lli->lli_st_generation != md->body->generation)
1313 llu_update_inode(inode, md->body, md->lsm);
1318 inode = llu_new_inode(fs, &fid);
1320 llu_update_inode(inode, md->body, md->lsm);
1325 extern struct list_head lustre_profile_list;
1328 llu_fsswop_mount(const char *source,
1330 const void *data __IS_UNUSED,
1331 struct pnode *tocover,
1332 struct mount **mntp)
1336 struct pnode_base *rootpb;
1337 struct obd_device *obd;
1338 struct ll_fid rootfid;
1339 struct llu_sb_info *sbi;
1340 struct obd_statfs osfs;
1341 static struct qstr noname = { NULL, 0, 0 };
1342 struct ptlrpc_request *request = NULL;
1343 struct lustre_handle mdc_conn = {0, };
1344 struct lustre_handle osc_conn = {0, };
1345 struct lustre_md md;
1347 struct lustre_profile *lprof;
1348 char *osc = NULL, *mdc = NULL;
1353 /* allocate & initialize sbi */
1354 OBD_ALLOC(sbi, sizeof(*sbi));
1358 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1359 generate_random_uuid(uuid);
1360 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1364 struct config_llog_instance cfg;
1367 if (!g_zconf_mdsname) {
1368 CERROR("no mds name\n");
1369 GOTO(out_free, err = -EINVAL);
1372 /* generate a string unique to this super, let's try
1373 the address of the super itself.*/
1374 len = (sizeof(sbi) * 2) + 1;
1375 OBD_ALLOC(sbi->ll_instance, len);
1376 if (sbi->ll_instance == NULL)
1377 GOTO(out_free, err = -ENOMEM);
1378 sprintf(sbi->ll_instance, "%p", sbi);
1380 cfg.cfg_instance = sbi->ll_instance;
1381 cfg.cfg_uuid = sbi->ll_sb_uuid;
1382 err = liblustre_process_log(&cfg, 1);
1384 CERROR("Unable to process log: %s\n", g_zconf_profile);
1386 GOTO(out_free, err);
1389 lprof = class_get_profile(g_zconf_profile);
1390 if (lprof == NULL) {
1391 CERROR("No profile found: %s\n", g_zconf_profile);
1392 GOTO(out_free, err = -EINVAL);
1395 OBD_FREE(osc, strlen(osc) + 1);
1396 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
1397 strlen(sbi->ll_instance) + 2);
1398 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
1401 OBD_FREE(mdc, strlen(mdc) + 1);
1402 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
1403 strlen(sbi->ll_instance) + 2);
1404 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
1406 /* setup from dump_file */
1407 if (list_empty(&lustre_profile_list)) {
1408 CERROR("no profile\n");
1409 GOTO(out_free, err = -EINVAL);
1412 lprof = list_entry(lustre_profile_list.next,
1413 struct lustre_profile, lp_list);
1414 osc = lprof->lp_osc;
1415 mdc = lprof->lp_mdc;
1420 GOTO(out_free, err = -EINVAL);
1424 GOTO(out_free, err = -EINVAL);
1427 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1433 obd = class_name2obd(mdc);
1435 CERROR("MDC %s: not setup or attached\n", mdc);
1436 GOTO(out_free, err = -EINVAL);
1439 if (mdc_init_ea_size(obd, osc))
1440 GOTO(out_free, err = -EINVAL);
1443 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
1445 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
1446 GOTO(out_free, err);
1448 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
1450 err = obd_statfs(obd, &osfs, 100000000);
1455 * FIXME fill fs stat data into sbi here!!! FIXME
1459 obd = class_name2obd(osc);
1461 CERROR("OSC %s: not setup or attached\n", osc);
1462 GOTO(out_mdc, err = -EINVAL);
1465 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
1467 CERROR("cannot connect to %s: rc = %d\n", osc, err);
1470 sbi->ll_osc_exp = class_conn2export(&osc_conn);
1472 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
1474 CERROR("cannot mds_connect: rc = %d\n", err);
1477 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
1478 sbi->ll_rootino = rootfid.id;
1480 /* fetch attr of root inode */
1481 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
1482 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
1484 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1488 err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
1490 CERROR("failed to understand root inode md: rc = %d\n",err);
1491 GOTO(out_request, err);
1494 LASSERT(sbi->ll_rootino != 0);
1496 root = llu_iget(fs, &md);
1497 if (!root || IS_ERR(root)) {
1498 CERROR("fail to generate root inode\n");
1499 GOTO(out_request, err = -EBADF);
1503 * Generate base path-node for root.
1505 rootpb = _sysio_pb_new(&noname, NULL, root);
1511 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1513 _sysio_pb_gone(rootpb);
1517 ptlrpc_req_finished(request);
1519 printf("LibLustre: namespace mounted successfully!\n");
1524 _sysio_i_gone(root);
1526 ptlrpc_req_finished(request);
1528 obd_disconnect(sbi->ll_osc_exp, 0);
1530 obd_disconnect(sbi->ll_mdc_exp, 0);
1532 OBD_FREE(sbi, sizeof(*sbi));
1536 struct fssw_ops llu_fssw_ops = {
1540 static struct inode_ops llu_inode_ops = {
1541 inop_lookup: llu_iop_lookup,
1542 inop_getattr: llu_iop_getattr,
1543 inop_setattr: llu_iop_setattr,
1544 inop_getdirentries: llu_iop_getdirentries,
1545 inop_mkdir: llu_iop_mkdir_raw,
1546 inop_rmdir: llu_iop_rmdir_raw,
1547 inop_symlink: llu_iop_symlink_raw,
1548 inop_readlink: llu_iop_readlink,
1549 inop_open: llu_iop_open,
1550 inop_close: llu_iop_close,
1551 inop_link: llu_iop_link_raw,
1552 inop_unlink: llu_iop_unlink_raw,
1553 inop_rename: llu_iop_rename_raw,
1554 inop_ipreadv: llu_iop_ipreadv,
1555 inop_ipwritev: llu_iop_ipwritev,
1556 inop_iodone: llu_iop_iodone,
1557 inop_fcntl: llu_iop_fcntl,
1558 inop_sync: llu_iop_sync,
1559 inop_datasync: llu_iop_datasync,
1560 inop_ioctl: llu_iop_ioctl,
1561 inop_mknod: llu_iop_mknod_raw,
1562 #ifdef _HAVE_STATVFS
1563 inop_statvfs: llu_iop_statvfs,
1565 inop_gone: llu_iop_gone,