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>
35 # include <sys/statvfs.h>
37 # include <sys/statfs.h>
48 #include "llite_lib.h"
50 static void llu_fsop_gone(struct filesys *fs)
52 struct llu_sb_info *sbi = (struct llu_sb_info *) fs->fs_private;
53 struct obd_device *obd = class_exp2obd(sbi->ll_mdc_exp);
54 struct ll_fid rootfid;
57 list_del(&sbi->ll_conn_chain);
58 obd_disconnect(sbi->ll_osc_exp, 0);
60 /* NULL request to force sync on the MDS, and get the last_committed
61 * value to flush remaining RPCs from the sending queue on client.
63 * XXX This should be an mdc_sync() call to sync the whole MDS fs,
64 * which we can call for other reasons as well.
66 if (!obd->obd_no_recov)
67 mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
69 obd_disconnect(sbi->ll_mdc_exp, 0);
71 OBD_FREE(sbi, sizeof(*sbi));
76 static struct inode_ops llu_inode_ops;
78 void llu_update_inode(struct inode *inode, struct mds_body *body,
79 struct lov_stripe_md *lsm)
81 struct llu_inode_info *lli = llu_i2info(inode);
83 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
85 if (lli->lli_smd == NULL) {
87 lli->lli_maxbytes = lsm->lsm_maxbytes;
88 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
89 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
91 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
92 CERROR("lsm mismatch for inode %ld\n",
99 if (body->valid & OBD_MD_FLID)
100 lli->lli_st_ino = body->ino;
101 if (body->valid & OBD_MD_FLATIME)
102 LTIME_S(lli->lli_st_atime) = body->atime;
103 if (body->valid & OBD_MD_FLMTIME)
104 LTIME_S(lli->lli_st_mtime) = body->mtime;
105 if (body->valid & OBD_MD_FLCTIME)
106 LTIME_S(lli->lli_st_ctime) = body->ctime;
107 if (body->valid & OBD_MD_FLMODE)
108 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT)|(body->mode & ~S_IFMT);
109 if (body->valid & OBD_MD_FLTYPE)
110 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT)|(body->mode & S_IFMT);
111 if (body->valid & OBD_MD_FLUID)
112 lli->lli_st_uid = body->uid;
113 if (body->valid & OBD_MD_FLGID)
114 lli->lli_st_gid = body->gid;
115 if (body->valid & OBD_MD_FLFLAGS)
116 lli->lli_st_flags = body->flags;
117 if (body->valid & OBD_MD_FLNLINK)
118 lli->lli_st_nlink = body->nlink;
119 if (body->valid & OBD_MD_FLGENER)
120 lli->lli_st_generation = body->generation;
121 if (body->valid & OBD_MD_FLRDEV)
122 lli->lli_st_rdev = body->rdev;
123 if (body->valid & OBD_MD_FLSIZE)
124 lli->lli_st_size = body->size;
125 if (body->valid & OBD_MD_FLBLOCKS)
126 lli->lli_st_blocks = body->blocks;
129 if (body->valid & OBD_MD_FLID)
130 lli->lli_fid.id = body->ino;
131 if (body->valid & OBD_MD_FLGENER)
132 lli->lli_fid.generation = body->generation;
133 if (body->valid & OBD_MD_FLTYPE)
134 lli->lli_fid.f_type = body->mode & S_IFMT;
137 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
139 struct llu_inode_info *lli = llu_i2info(dst);
141 valid &= src->o_valid;
143 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
144 CDEBUG(D_INODE, "valid %x, cur time %lu/%lu, new %lu/%lu\n",
146 LTIME_S(lli->lli_st_mtime), LTIME_S(lli->lli_st_ctime),
147 (long)src->o_mtime, (long)src->o_ctime);
149 if (valid & OBD_MD_FLATIME)
150 LTIME_S(lli->lli_st_atime) = src->o_atime;
151 if (valid & OBD_MD_FLMTIME)
152 LTIME_S(lli->lli_st_mtime) = src->o_mtime;
153 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(lli->lli_st_ctime))
154 LTIME_S(lli->lli_st_ctime) = src->o_ctime;
155 if (valid & OBD_MD_FLSIZE)
156 lli->lli_st_size = src->o_size;
157 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
158 lli->lli_st_blocks = src->o_blocks;
159 if (valid & OBD_MD_FLBLKSZ)
160 lli->lli_st_blksize = src->o_blksize;
161 if (valid & OBD_MD_FLTYPE)
162 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
163 if (valid & OBD_MD_FLMODE)
164 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
165 if (valid & OBD_MD_FLUID)
166 lli->lli_st_uid = src->o_uid;
167 if (valid & OBD_MD_FLGID)
168 lli->lli_st_gid = src->o_gid;
169 if (valid & OBD_MD_FLFLAGS)
170 lli->lli_st_flags = src->o_flags;
171 if (valid & OBD_MD_FLGENER)
172 lli->lli_st_generation = src->o_generation;
175 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
176 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
178 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
180 struct llu_inode_info *lli = llu_i2info(src);
181 obd_flag newvalid = 0;
183 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
184 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
185 valid, LTIME_S(lli->lli_st_mtime),
186 LTIME_S(lli->lli_st_ctime));
188 if (valid & OBD_MD_FLATIME) {
189 dst->o_atime = LTIME_S(lli->lli_st_atime);
190 newvalid |= OBD_MD_FLATIME;
192 if (valid & OBD_MD_FLMTIME) {
193 dst->o_mtime = LTIME_S(lli->lli_st_mtime);
194 newvalid |= OBD_MD_FLMTIME;
196 if (valid & OBD_MD_FLCTIME) {
197 dst->o_ctime = LTIME_S(lli->lli_st_ctime);
198 newvalid |= OBD_MD_FLCTIME;
200 if (valid & OBD_MD_FLSIZE) {
201 dst->o_size = lli->lli_st_size;
202 newvalid |= OBD_MD_FLSIZE;
204 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
205 dst->o_blocks = lli->lli_st_blocks;
206 newvalid |= OBD_MD_FLBLOCKS;
208 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
209 dst->o_blksize = lli->lli_st_blksize;
210 newvalid |= OBD_MD_FLBLKSZ;
212 if (valid & OBD_MD_FLTYPE) {
213 dst->o_mode = (dst->o_mode & S_IALLUGO)|(lli->lli_st_mode & S_IFMT);
214 newvalid |= OBD_MD_FLTYPE;
216 if (valid & OBD_MD_FLMODE) {
217 dst->o_mode = (dst->o_mode & S_IFMT)|(lli->lli_st_mode & S_IALLUGO);
218 newvalid |= OBD_MD_FLMODE;
220 if (valid & OBD_MD_FLUID) {
221 dst->o_uid = lli->lli_st_uid;
222 newvalid |= OBD_MD_FLUID;
224 if (valid & OBD_MD_FLGID) {
225 dst->o_gid = lli->lli_st_gid;
226 newvalid |= OBD_MD_FLGID;
228 if (valid & OBD_MD_FLFLAGS) {
229 dst->o_flags = lli->lli_st_flags;
230 newvalid |= OBD_MD_FLFLAGS;
232 if (valid & OBD_MD_FLGENER) {
233 dst->o_generation = lli->lli_st_generation;
234 newvalid |= OBD_MD_FLGENER;
237 dst->o_valid |= newvalid;
241 * really does the getattr on the inode and updates its fields
243 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
245 struct llu_inode_info *lli = llu_i2info(inode);
246 struct obd_export *exp = llu_i2obdexp(inode);
247 struct ptlrpc_request_set *set;
249 obd_flag refresh_valid;
256 memset(&oa, 0, sizeof oa);
257 oa.o_id = lsm->lsm_object_id;
259 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
260 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
263 set = ptlrpc_prep_set();
265 CERROR ("ENOMEM allocing request set\n");
268 rc = obd_getattr_async(exp, &oa, lsm, set);
270 rc = ptlrpc_set_wait(set);
271 ptlrpc_set_destroy(set);
276 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
277 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
279 /* We set this flag in commit write as we extend the file size. When
280 * the bit is set and the lock is canceled that covers the file size,
281 * we clear the bit. This is enough to protect the window where our
282 * local size extension is needed for writeback. However, it relies on
283 * behaviour that won't be true in the near future. This assumes that
284 * all getattr callers get extent locks, which they currnetly do. It
285 * also assumes that we only send discarding asts for {0,eof} truncates
286 * as is currently the case. This will have to be replaced by the
287 * proper eoc communication between clients and the ost, which is on
289 if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
290 if (oa.o_size < lli->lli_st_size)
291 refresh_valid &= ~OBD_MD_FLSIZE;
293 clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
296 obdo_refresh_inode(inode, &oa, refresh_valid);
301 static struct inode* llu_new_inode(struct filesys *fs,
305 struct llu_inode_info *lli;
307 OBD_ALLOC(lli, sizeof(*lli));
311 /* initialize lli here */
312 lli->lli_sbi = llu_fs2sbi(fs);
314 lli->lli_symlink_name = NULL;
316 lli->lli_maxbytes = (__u64)(~0UL);
317 lli->lli_file_data = NULL;
319 lli->lli_sysio_fid.fid_data = &lli->lli_fid;
320 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_fid);
322 memcpy(&lli->lli_fid, fid, sizeof(*fid));
324 /* file identifier is needed by functions like _sysio_i_find() */
325 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
326 #ifndef AUTOMOUNT_FILE_NAME
327 fid->f_type & S_IFMT,
329 fid->f_type, /* all of the bits! */
332 &llu_inode_ops, lli);
335 OBD_FREE(lli, sizeof(*lli));
340 static int llu_have_md_lock(struct inode *inode, __u64 lockpart)
342 struct llu_sb_info *sbi = llu_i2sbi(inode);
343 struct llu_inode_info *lli = llu_i2info(inode);
344 struct lustre_handle lockh;
345 struct ldlm_res_id res_id = { .name = {0} };
346 struct obd_device *obddev;
347 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
353 obddev = sbi->ll_mdc_exp->exp_obd;
354 res_id.name[0] = lli->lli_st_ino;
355 res_id.name[1] = lli->lli_st_generation;
357 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
359 /* FIXME use LDLM_FL_TEST_LOCK instead */
360 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
361 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
362 &policy, LCK_PR, &lockh)) {
363 ldlm_lock_decref(&lockh, LCK_PR);
367 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
368 &policy, LCK_PW, &lockh)) {
369 ldlm_lock_decref(&lockh, LCK_PW);
375 static int llu_inode_revalidate(struct inode *inode)
377 struct llu_inode_info *lli = llu_i2info(inode);
378 struct lov_stripe_md *lsm = NULL;
382 CERROR("REPORT THIS LINE TO PETER\n");
386 if (!llu_have_md_lock(inode, MDS_INODELOCK_UPDATE)) {
388 struct ptlrpc_request *req = NULL;
389 struct llu_sb_info *sbi = llu_i2sbi(inode);
391 unsigned long valid = 0;
394 /* Why don't we update all valid MDS fields here, if we're
395 * doing an RPC anyways? -phil */
396 if (S_ISREG(lli->lli_st_mode)) {
397 ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
398 valid |= OBD_MD_FLEASIZE;
400 ll_inode2fid(&fid, inode);
401 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
403 CERROR("failure %d inode %lu\n", rc, lli->lli_st_ino);
406 rc = mdc_req2lustre_md(sbi->ll_mdc_exp, req, 0,
407 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 LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
505 return LDLM_ITER_CONTINUE;
508 void llu_clear_inode(struct inode *inode)
511 struct llu_inode_info *lli = llu_i2info(inode);
512 struct llu_sb_info *sbi = llu_i2sbi(inode);
515 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu(%p)\n", lli->lli_st_ino,
516 lli->lli_st_generation, inode);
518 ll_inode2fid(&fid, inode);
519 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
520 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
523 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
524 null_if_equal, inode);
527 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
531 if (lli->lli_symlink_name) {
532 OBD_FREE(lli->lli_symlink_name,
533 strlen(lli->lli_symlink_name) + 1);
534 lli->lli_symlink_name = NULL;
540 void llu_iop_gone(struct inode *inode)
542 struct llu_inode_info *lli = llu_i2info(inode);
545 llu_clear_inode(inode);
547 OBD_FREE(lli, sizeof(*lli));
551 static int inode_setattr(struct inode * inode, struct iattr * attr)
553 unsigned int ia_valid = attr->ia_valid;
554 struct llu_inode_info *lli = llu_i2info(inode);
557 if (ia_valid & ATTR_SIZE) {
558 error = llu_vmtruncate(inode, attr->ia_size);
563 if (ia_valid & ATTR_UID)
564 lli->lli_st_uid = attr->ia_uid;
565 if (ia_valid & ATTR_GID)
566 lli->lli_st_gid = attr->ia_gid;
567 if (ia_valid & ATTR_ATIME)
568 lli->lli_st_atime = attr->ia_atime;
569 if (ia_valid & ATTR_MTIME)
570 lli->lli_st_mtime = attr->ia_mtime;
571 if (ia_valid & ATTR_CTIME)
572 lli->lli_st_ctime = attr->ia_ctime;
573 if (ia_valid & ATTR_MODE) {
574 lli->lli_st_mode = attr->ia_mode;
575 if (!in_group_p(lli->lli_st_gid) && !capable(CAP_FSETID))
576 lli->lli_st_mode &= ~S_ISGID;
578 /* mark_inode_dirty(inode); */
583 /* If this inode has objects allocated to it (lsm != NULL), then the OST
584 * object(s) determine the file size and mtime. Otherwise, the MDS will
585 * keep these values until such a time that objects are allocated for it.
586 * We do the MDS operations first, as it is checking permissions for us.
587 * We don't to the MDS RPC if there is nothing that we want to store there,
588 * otherwise there is no harm in updating mtime/atime on the MDS if we are
589 * going to do an RPC anyways.
591 * If we are doing a truncate, we will send the mtime and ctime updates
592 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
593 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
596 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
598 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
599 struct llu_sb_info *sbi = llu_i2sbi(inode);
600 struct llu_inode_info *lli = llu_i2info(inode);
601 struct ptlrpc_request *request = NULL;
602 struct mdc_op_data op_data;
603 int ia_valid = attr->ia_valid;
607 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
609 if (ia_valid & ATTR_SIZE) {
610 if (attr->ia_size > ll_file_maxbytes(inode)) {
611 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
612 attr->ia_size, ll_file_maxbytes(inode));
616 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
619 /* We mark all of the fields "set" so MDS/OST does not re-set them */
620 if (attr->ia_valid & ATTR_CTIME) {
621 attr->ia_ctime = CURRENT_TIME;
622 attr->ia_valid |= ATTR_CTIME_SET;
624 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
625 attr->ia_atime = CURRENT_TIME;
626 attr->ia_valid |= ATTR_ATIME_SET;
628 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
629 attr->ia_mtime = CURRENT_TIME;
630 attr->ia_valid |= ATTR_MTIME_SET;
633 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
634 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
635 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
636 LTIME_S(CURRENT_TIME));
638 attr->ia_valid &= ~ATTR_SIZE;
640 /* If only OST attributes being set on objects, don't do MDS RPC.
641 * In that case, we need to check permissions and update the local
642 * inode ourselves so we can call obdo_from_inode() always. */
643 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
645 llu_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
647 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
648 attr, NULL, 0, NULL, 0, &request);
651 ptlrpc_req_finished(request);
652 if (rc != -EPERM && rc != -EACCES)
653 CERROR("mdc_setattr fails: rc = %d\n", rc);
657 rc = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
658 sbi->ll_osc_exp, &md);
660 ptlrpc_req_finished(request);
663 llu_update_inode(inode, md.body, md.lsm);
664 ptlrpc_req_finished(request);
666 if (!md.lsm || !S_ISREG(lli->lli_st_mode)) {
667 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
671 /* The OST doesn't check permissions, but the alternative is
672 * a gratuitous RPC to the MDS. We already rely on the client
673 * to do read/write/truncate permission checks, so is mtime OK?
675 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
676 /* from sys_utime() */
677 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
678 if (current->fsuid != lli->lli_st_uid &&
679 (rc = ll_permission(inode, 0/*MAY_WRITE*/, NULL)) != 0)
682 /* from inode_change_ok() */
683 if (current->fsuid != lli->lli_st_uid &&
684 !capable(CAP_FOWNER))
689 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
690 inode_setattr(inode, attr);
693 if (ia_valid & ATTR_SIZE) {
694 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
696 struct lustre_handle lockh = { 0 };
697 int err, ast_flags = 0;
698 /* XXX when we fix the AST intents to pass the discard-range
699 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
701 if (attr->ia_size == 0)
702 ast_flags = LDLM_AST_DISCARD_DATA;
704 rc = llu_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
706 if (rc != ELDLM_OK) {
712 rc = llu_vmtruncate(inode, attr->ia_size);
714 set_bit(LLI_F_HAVE_OST_SIZE_LOCK,
715 &llu_i2info(inode)->lli_flags);
717 /* unlock now as we don't mind others file lockers racing with
718 * the mds updates below? */
719 err = llu_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
721 CERROR("llu_extent_unlock failed: %d\n", err);
725 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
728 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
729 lli->lli_st_ino, LTIME_S(attr->ia_mtime));
730 oa.o_id = lsm->lsm_object_id;
731 oa.o_valid = OBD_MD_FLID;
732 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
733 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
734 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
736 CERROR("obd_setattr fails: rc=%d\n", rc);
741 /* here we simply act as a thin layer to glue it with
742 * llu_setattr_raw(), which is copy from kernel
744 static int llu_iop_setattr(struct pnode *pno,
747 struct intnl_stat *stbuf)
752 memset(&iattr, 0, sizeof(iattr));
754 if (mask & SETATTR_MODE) {
755 iattr.ia_mode = stbuf->st_mode;
756 iattr.ia_valid |= ATTR_MODE;
758 if (mask & SETATTR_MTIME) {
759 iattr.ia_mtime = stbuf->st_mtime;
760 iattr.ia_valid |= ATTR_MTIME;
762 if (mask & SETATTR_ATIME) {
763 iattr.ia_atime = stbuf->st_atime;
764 iattr.ia_valid |= ATTR_ATIME;
766 if (mask & SETATTR_UID) {
767 iattr.ia_uid = stbuf->st_uid;
768 iattr.ia_valid |= ATTR_UID;
770 if (mask & SETATTR_GID) {
771 iattr.ia_gid = stbuf->st_gid;
772 iattr.ia_valid |= ATTR_GID;
774 if (mask & SETATTR_LEN) {
775 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
776 iattr.ia_valid |= ATTR_SIZE;
779 iattr.ia_valid |= ATTR_RAW;
781 RETURN(llu_setattr_raw(ino, &iattr));
784 #define EXT2_LINK_MAX 32000
786 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
788 struct inode *dir = pno->p_base->pb_parent->pb_ino;
789 struct qstr *qstr = &pno->p_base->pb_name;
790 const char *name = qstr->name;
792 struct ptlrpc_request *request = NULL;
793 struct llu_sb_info *sbi = llu_i2sbi(dir);
794 struct mdc_op_data op_data;
798 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
801 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
802 err = mdc_create(sbi->ll_mdc_exp, &op_data,
803 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
804 current->fsuid, current->fsgid, 0, &request);
805 ptlrpc_req_finished(request);
809 static int llu_readlink_internal(struct inode *inode,
810 struct ptlrpc_request **request,
813 struct llu_inode_info *lli = llu_i2info(inode);
814 struct llu_sb_info *sbi = llu_i2sbi(inode);
816 struct mds_body *body;
817 int rc, symlen = lli->lli_st_size + 1;
822 if (lli->lli_symlink_name) {
823 *symname = lli->lli_symlink_name;
824 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
828 ll_inode2fid(&fid, inode);
829 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
830 OBD_MD_LINKNAME, symlen, request);
832 CERROR("inode %lu: rc = %d\n", lli->lli_st_ino, rc);
836 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
837 LASSERT (body != NULL);
838 LASSERT_REPSWABBED (*request, 0);
840 if ((body->valid & OBD_MD_LINKNAME) == 0) {
841 CERROR ("OBD_MD_LINKNAME not set on reply\n");
842 GOTO (failed, rc = -EPROTO);
845 LASSERT (symlen != 0);
846 if (body->eadatasize != symlen) {
847 CERROR ("inode %lu: symlink length %d not expected %d\n",
848 lli->lli_st_ino, body->eadatasize - 1, symlen - 1);
849 GOTO (failed, rc = -EPROTO);
852 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
853 if (*symname == NULL ||
854 strnlen (*symname, symlen) != symlen - 1) {
855 /* not full/NULL terminated */
856 CERROR ("inode %lu: symlink not NULL terminated string"
857 "of length %d\n", lli->lli_st_ino, symlen - 1);
858 GOTO (failed, rc = -EPROTO);
861 OBD_ALLOC(lli->lli_symlink_name, symlen);
862 /* do not return an error if we cannot cache the symlink locally */
863 if (lli->lli_symlink_name)
864 memcpy(lli->lli_symlink_name, *symname, symlen);
869 ptlrpc_req_finished (*request);
873 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
875 struct inode *inode = pno->p_base->pb_ino;
876 struct ptlrpc_request *request;
881 rc = llu_readlink_internal(inode, &request, &symname);
886 strncpy(data, symname, bufsize);
888 ptlrpc_req_finished(request);
893 static int llu_iop_mknod_raw(struct pnode *pno,
897 struct ptlrpc_request *request = NULL;
898 struct inode *dir = pno->p_parent->p_base->pb_ino;
899 struct llu_sb_info *sbi = llu_i2sbi(dir);
900 struct mdc_op_data op_data;
904 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu\n",
905 pno->p_base->pb_name.name, llu_i2info(dir)->lli_st_ino);
907 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
910 mode &= ~current->fs->umask;
912 switch (mode & S_IFMT) {
915 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
920 llu_prepare_mdc_op_data(&op_data, dir, NULL,
921 pno->p_base->pb_name.name,
922 pno->p_base->pb_name.len,
924 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
925 current->fsuid, current->fsgid, dev, &request);
926 ptlrpc_req_finished(request);
937 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
939 struct inode *src = old->p_base->pb_ino;
940 struct inode *dir = new->p_parent->p_base->pb_ino;
941 const char *name = new->p_base->pb_name.name;
942 int namelen = new->p_base->pb_name.len;
943 struct ptlrpc_request *request = NULL;
944 struct mdc_op_data op_data;
951 llu_prepare_mdc_op_data(&op_data, src, dir, name, namelen, 0);
952 rc = mdc_link(llu_i2sbi(src)->ll_mdc_exp, &op_data, &request);
953 ptlrpc_req_finished(request);
958 static int llu_iop_unlink_raw(struct pnode *pno)
960 struct inode *dir = pno->p_base->pb_parent->pb_ino;
961 struct qstr *qstr = &pno->p_base->pb_name;
962 const char *name = qstr->name;
964 struct inode *target = pno->p_base->pb_ino;
965 struct ptlrpc_request *request = NULL;
966 struct mdc_op_data op_data;
972 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
973 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
975 rc = llu_objects_destroy(request, dir);
977 llu_i2info(target)->lli_stale_flag = 1;
978 unhook_stale_inode(pno);
981 ptlrpc_req_finished(request);
986 * following cases need to be considered later:
987 * - rename an opened file/dir
988 * - an opened file be removed in rename
989 * - rename to remove and hardlink (?opened)
991 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
993 struct inode *src = old->p_parent->p_base->pb_ino;
994 struct inode *tgt = new->p_parent->p_base->pb_ino;
995 struct inode *tgtinode = new->p_base->pb_ino;
996 const char *oldname = old->p_base->pb_name.name;
997 int oldnamelen = old->p_base->pb_name.len;
998 const char *newname = new->p_base->pb_name.name;
999 int newnamelen = new->p_base->pb_name.len;
1000 struct ptlrpc_request *request = NULL;
1001 struct mdc_op_data op_data;
1008 llu_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0);
1009 rc = mdc_rename(llu_i2sbi(src)->ll_mdc_exp, &op_data,
1010 oldname, oldnamelen, newname, newnamelen,
1013 rc = llu_objects_destroy(request, src);
1016 llu_i2info(tgtinode)->lli_stale_flag = 1;
1017 unhook_stale_inode(new);
1021 ptlrpc_req_finished(request);
1026 #ifdef _HAVE_STATVFS
1027 static int llu_statfs_internal(struct llu_sb_info *sbi,
1028 struct obd_statfs *osfs,
1029 unsigned long max_age)
1031 struct obd_statfs obd_osfs;
1035 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1037 CERROR("mdc_statfs fails: rc = %d\n", rc);
1041 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1042 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1044 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1046 CERROR("obd_statfs fails: rc = %d\n", rc);
1050 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1051 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1054 osfs->os_blocks = obd_osfs.os_blocks;
1055 osfs->os_bfree = obd_osfs.os_bfree;
1056 osfs->os_bavail = obd_osfs.os_bavail;
1058 /* If we don't have as many objects free on the OST as inodes
1059 * on the MDS, we reduce the total number of inodes to
1060 * compensate, so that the "inodes in use" number is correct.
1062 if (obd_osfs.os_ffree < osfs->os_ffree) {
1063 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1065 osfs->os_ffree = obd_osfs.os_ffree;
1071 static int llu_statfs(struct llu_sb_info *sbi, struct statfs *sfs)
1073 struct obd_statfs osfs;
1076 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1078 /* For now we will always get up-to-date statfs values, but in the
1079 * future we may allow some amount of caching on the client (e.g.
1080 * from QOS or lprocfs updates). */
1081 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1085 statfs_unpack(sfs, &osfs);
1087 if (sizeof(sfs->f_blocks) == 4) {
1088 while (osfs.os_blocks > ~0UL) {
1091 osfs.os_blocks >>= 1;
1092 osfs.os_bfree >>= 1;
1093 osfs.os_bavail >>= 1;
1097 sfs->f_blocks = osfs.os_blocks;
1098 sfs->f_bfree = osfs.os_bfree;
1099 sfs->f_bavail = osfs.os_bavail;
1104 static int llu_iop_statvfs(struct pnode *pno,
1106 struct intnl_statvfs *buf)
1113 LASSERT(pno->p_base->pb_ino);
1114 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1118 /* from native driver */
1119 buf->f_bsize = fs.f_bsize; /* file system block size */
1120 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1121 buf->f_blocks = fs.f_blocks;
1122 buf->f_bfree = fs.f_bfree;
1123 buf->f_bavail = fs.f_bavail;
1124 buf->f_files = fs.f_files; /* Total number serial numbers */
1125 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1126 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1127 buf->f_fsid = fs.f_fsid.__val[1];
1128 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1129 buf->f_namemax = fs.f_namelen;
1134 #endif /* _HAVE_STATVFS */
1136 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1138 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1139 struct qstr *qstr = &pno->p_base->pb_name;
1140 const char *name = qstr->name;
1141 int len = qstr->len;
1142 struct ptlrpc_request *request = NULL;
1143 struct llu_inode_info *lli = llu_i2info(dir);
1144 struct mdc_op_data op_data;
1147 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1148 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1150 if (lli->lli_st_nlink >= EXT2_LINK_MAX)
1153 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
1154 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1155 err = mdc_create(llu_i2sbi(dir)->ll_mdc_exp, &op_data, NULL, 0, mode,
1156 current->fsuid, current->fsgid, 0, &request);
1157 ptlrpc_req_finished(request);
1161 static int llu_iop_rmdir_raw(struct pnode *pno)
1163 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1164 struct qstr *qstr = &pno->p_base->pb_name;
1165 const char *name = qstr->name;
1166 int len = qstr->len;
1167 struct ptlrpc_request *request = NULL;
1168 struct mdc_op_data op_data;
1169 struct llu_inode_info *lli = llu_i2info(dir);
1172 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1173 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1175 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, S_IFDIR);
1176 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1177 ptlrpc_req_finished(request);
1179 /* libsysio: remove the pnode right away */
1181 llu_i2info(pno->p_base->pb_ino)->lli_stale_flag = 1;
1182 unhook_stale_inode(pno);
1188 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap)
1190 CERROR("liblustre did not support fcntl\n");
1194 static int llu_get_grouplock(struct inode *inode, unsigned long arg)
1196 struct llu_inode_info *lli = llu_i2info(inode);
1197 struct ll_file_data *fd = lli->lli_file_data;
1198 ldlm_policy_data_t policy = { .l_extent = { .start = 0,
1199 .end = OBD_OBJECT_EOF}};
1200 struct lustre_handle lockh = { 0 };
1201 struct lov_stripe_md *lsm = lli->lli_smd;
1206 if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
1210 policy.l_extent.gid = arg;
1211 if (lli->lli_open_flags & O_NONBLOCK)
1212 flags = LDLM_FL_BLOCK_NOWAIT;
1214 err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
1219 fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
1221 memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
1226 static int llu_put_grouplock(struct inode *inode, unsigned long arg)
1228 struct llu_inode_info *lli = llu_i2info(inode);
1229 struct ll_file_data *fd = lli->lli_file_data;
1230 struct lov_stripe_md *lsm = lli->lli_smd;
1234 if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
1237 if (fd->fd_gid != arg)
1240 fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
1242 err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
1247 memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
1252 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1258 case LL_IOC_GROUP_LOCK:
1259 arg = va_arg(ap, unsigned long);
1260 return llu_get_grouplock(ino, arg);
1261 case LL_IOC_GROUP_UNLOCK:
1262 arg = va_arg(ap, unsigned long);
1263 return llu_put_grouplock(ino, arg);
1266 CERROR("did not support ioctl cmd %lx\n", request);
1271 * we already do syncronous read/write
1273 static int llu_iop_sync(struct inode *inode)
1278 static int llu_iop_datasync(struct inode *inode)
1283 struct filesys_ops llu_filesys_ops =
1285 fsop_gone: llu_fsop_gone,
1288 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1290 struct inode *inode;
1292 struct file_identifier fileid = {&fid, sizeof(fid)};
1294 if ((md->body->valid &
1295 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1296 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) {
1297 /* FIXME this is workaround for for open(O_CREAT),
1298 * see lookup_it_finish(). */
1299 return ERR_PTR(-EPERM);
1302 /* try to find existing inode */
1303 fid.id = md->body->ino;
1304 fid.generation = md->body->generation;
1305 fid.f_type = md->body->mode & S_IFMT;
1307 inode = _sysio_i_find(fs, &fileid);
1309 struct llu_inode_info *lli = llu_i2info(inode);
1311 if (lli->lli_stale_flag ||
1312 lli->lli_st_generation != md->body->generation) {
1315 llu_update_inode(inode, md->body, md->lsm);
1320 inode = llu_new_inode(fs, &fid);
1322 llu_update_inode(inode, md->body, md->lsm);
1327 extern struct list_head lustre_profile_list;
1330 llu_fsswop_mount(const char *source,
1332 const void *data __IS_UNUSED,
1333 struct pnode *tocover,
1334 struct mount **mntp)
1338 struct pnode_base *rootpb;
1339 struct obd_device *obd;
1340 struct ll_fid rootfid;
1341 struct llu_sb_info *sbi;
1342 struct obd_statfs osfs;
1343 static struct qstr noname = { NULL, 0, 0 };
1344 struct ptlrpc_request *request = NULL;
1345 struct lustre_handle mdc_conn = {0, };
1346 struct lustre_handle osc_conn = {0, };
1347 struct lustre_md md;
1349 struct lustre_profile *lprof;
1350 char *osc = NULL, *mdc = NULL;
1355 /* allocate & initialize sbi */
1356 OBD_ALLOC(sbi, sizeof(*sbi));
1360 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1361 generate_random_uuid(uuid);
1362 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1366 struct config_llog_instance cfg;
1369 if (!g_zconf_mdsname) {
1370 CERROR("no mds name\n");
1371 GOTO(out_free, err = -EINVAL);
1374 /* generate a string unique to this super, let's try
1375 the address of the super itself.*/
1376 len = (sizeof(sbi) * 2) + 1;
1377 OBD_ALLOC(sbi->ll_instance, len);
1378 if (sbi->ll_instance == NULL)
1379 GOTO(out_free, err = -ENOMEM);
1380 sprintf(sbi->ll_instance, "%p", sbi);
1382 cfg.cfg_instance = sbi->ll_instance;
1383 cfg.cfg_uuid = sbi->ll_sb_uuid;
1384 err = liblustre_process_log(&cfg, 1);
1386 CERROR("Unable to process log: %s\n", g_zconf_profile);
1388 GOTO(out_free, err);
1392 lprof = class_get_profile(g_zconf_profile);
1393 if (lprof == NULL) {
1394 CERROR("No profile found: %s\n", g_zconf_profile);
1395 GOTO(out_free, err = -EINVAL);
1398 OBD_FREE(osc, strlen(osc) + 1);
1399 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
1400 strlen(sbi->ll_instance) + 2);
1401 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
1404 OBD_FREE(mdc, strlen(mdc) + 1);
1405 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
1406 strlen(sbi->ll_instance) + 2);
1407 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
1409 /* setup from dump_file */
1410 if (list_empty(&lustre_profile_list)) {
1411 CERROR("no profile\n");
1412 GOTO(out_free, err = -EINVAL);
1415 lprof = list_entry(lustre_profile_list.next,
1416 struct lustre_profile, lp_list);
1417 osc = lprof->lp_osc;
1418 mdc = lprof->lp_mdc;
1423 GOTO(out_free, err = -EINVAL);
1427 GOTO(out_free, err = -EINVAL);
1430 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1436 obd = class_name2obd(mdc);
1438 CERROR("MDC %s: not setup or attached\n", mdc);
1439 GOTO(out_free, err = -EINVAL);
1442 #warning "FIXME ASAP!"
1444 if (mdc_init_ea_size(obd, osc))
1445 GOTO(out_free, err = -EINVAL);
1449 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
1451 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
1452 GOTO(out_free, err);
1454 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
1456 err = obd_statfs(obd, &osfs, 100000000);
1461 * FIXME fill fs stat data into sbi here!!! FIXME
1465 obd = class_name2obd(osc);
1467 CERROR("OSC %s: not setup or attached\n", osc);
1468 GOTO(out_mdc, err = -EINVAL);
1471 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
1473 CERROR("cannot connect to %s: rc = %d\n", osc, err);
1476 sbi->ll_osc_exp = class_conn2export(&osc_conn);
1478 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
1480 CERROR("cannot mds_connect: rc = %d\n", err);
1483 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
1484 sbi->ll_rootino = rootfid.id;
1486 /* fetch attr of root inode */
1487 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
1488 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
1490 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1494 err = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
1495 sbi->ll_osc_exp, &md);
1497 CERROR("failed to understand root inode md: rc = %d\n",err);
1498 GOTO(out_request, err);
1501 LASSERT(sbi->ll_rootino != 0);
1503 root = llu_iget(fs, &md);
1504 if (!root || IS_ERR(root)) {
1505 CERROR("fail to generate root inode\n");
1506 GOTO(out_request, err = -EBADF);
1510 * Generate base path-node for root.
1512 rootpb = _sysio_pb_new(&noname, NULL, root);
1518 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1520 _sysio_pb_gone(rootpb);
1524 ptlrpc_req_finished(request);
1526 printf("LibLustre: namespace mounted successfully!\n");
1531 _sysio_i_gone(root);
1533 ptlrpc_req_finished(request);
1535 obd_disconnect(sbi->ll_osc_exp, 0);
1537 obd_disconnect(sbi->ll_mdc_exp, 0);
1539 OBD_FREE(sbi, sizeof(*sbi));
1543 struct fssw_ops llu_fssw_ops = {
1547 static struct inode_ops llu_inode_ops = {
1548 inop_lookup: llu_iop_lookup,
1549 inop_getattr: llu_iop_getattr,
1550 inop_setattr: llu_iop_setattr,
1551 inop_getdirentries: llu_iop_getdirentries,
1552 inop_mkdir: llu_iop_mkdir_raw,
1553 inop_rmdir: llu_iop_rmdir_raw,
1554 inop_symlink: llu_iop_symlink_raw,
1555 inop_readlink: llu_iop_readlink,
1556 inop_open: llu_iop_open,
1557 inop_close: llu_iop_close,
1558 inop_link: llu_iop_link_raw,
1559 inop_unlink: llu_iop_unlink_raw,
1560 inop_rename: llu_iop_rename_raw,
1561 inop_ipreadv: llu_iop_ipreadv,
1562 inop_ipwritev: llu_iop_ipwritev,
1563 inop_iodone: llu_iop_iodone,
1564 inop_fcntl: llu_iop_fcntl,
1565 inop_sync: llu_iop_sync,
1566 inop_datasync: llu_iop_datasync,
1567 inop_ioctl: llu_iop_ioctl,
1568 inop_mknod: llu_iop_mknod_raw,
1569 #ifdef _HAVE_STATVFS
1570 inop_statvfs: llu_iop_statvfs,
1572 inop_gone: llu_iop_gone,