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>
46 #include "llite_lib.h"
48 static void llu_fsop_gone(struct filesys *fs)
50 struct llu_sb_info *sbi = (struct llu_sb_info *) fs->fs_private;
51 struct obd_device *obd = class_exp2obd(sbi->ll_mdc_exp);
52 struct ll_fid rootfid;
55 list_del(&sbi->ll_conn_chain);
56 obd_disconnect(sbi->ll_osc_exp, 0);
58 /* NULL request to force sync on the MDS, and get the last_committed
59 * value to flush remaining RPCs from the sending queue on client.
61 * XXX This should be an mdc_sync() call to sync the whole MDS fs,
62 * which we can call for other reasons as well.
64 if (!obd->obd_no_recov)
65 mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
67 obd_disconnect(sbi->ll_mdc_exp, 0);
69 OBD_FREE(sbi, sizeof(*sbi));
74 static struct inode_ops llu_inode_ops;
76 void llu_update_inode(struct inode *inode, struct mds_body *body,
77 struct lov_stripe_md *lsm)
79 struct llu_inode_info *lli = llu_i2info(inode);
81 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
83 if (lli->lli_smd == NULL) {
85 lli->lli_maxbytes = lsm->lsm_maxbytes;
86 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
87 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
89 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
90 CERROR("lsm mismatch for inode %ld\n",
97 if (body->valid & OBD_MD_FLID)
98 lli->lli_st_ino = body->ino;
99 if (body->valid & OBD_MD_FLATIME)
100 LTIME_S(lli->lli_st_atime) = body->atime;
101 if (body->valid & OBD_MD_FLMTIME)
102 LTIME_S(lli->lli_st_mtime) = body->mtime;
103 if (body->valid & OBD_MD_FLCTIME)
104 LTIME_S(lli->lli_st_ctime) = body->ctime;
105 if (body->valid & OBD_MD_FLMODE)
106 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT)|(body->mode & ~S_IFMT);
107 if (body->valid & OBD_MD_FLTYPE)
108 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT)|(body->mode & S_IFMT);
109 if (body->valid & OBD_MD_FLUID)
110 lli->lli_st_uid = body->uid;
111 if (body->valid & OBD_MD_FLGID)
112 lli->lli_st_gid = body->gid;
113 if (body->valid & OBD_MD_FLFLAGS)
114 lli->lli_st_flags = body->flags;
115 if (body->valid & OBD_MD_FLNLINK)
116 lli->lli_st_nlink = body->nlink;
117 if (body->valid & OBD_MD_FLGENER)
118 lli->lli_st_generation = body->generation;
119 if (body->valid & OBD_MD_FLRDEV)
120 lli->lli_st_rdev = body->rdev;
121 if (body->valid & OBD_MD_FLSIZE)
122 lli->lli_st_size = body->size;
123 if (body->valid & OBD_MD_FLBLOCKS)
124 lli->lli_st_blocks = body->blocks;
127 if (body->valid & OBD_MD_FLID)
128 lli->lli_fid.id = body->ino;
129 if (body->valid & OBD_MD_FLGENER)
130 lli->lli_fid.generation = body->generation;
131 if (body->valid & OBD_MD_FLTYPE)
132 lli->lli_fid.f_type = body->mode & S_IFMT;
135 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
137 struct llu_inode_info *lli = llu_i2info(dst);
139 valid &= src->o_valid;
141 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
142 CDEBUG(D_INODE, "valid %x, cur time %lu/%lu, new %lu/%lu\n",
144 LTIME_S(lli->lli_st_mtime), LTIME_S(lli->lli_st_ctime),
145 (long)src->o_mtime, (long)src->o_ctime);
147 if (valid & OBD_MD_FLATIME)
148 LTIME_S(lli->lli_st_atime) = src->o_atime;
149 if (valid & OBD_MD_FLMTIME)
150 LTIME_S(lli->lli_st_mtime) = src->o_mtime;
151 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(lli->lli_st_ctime))
152 LTIME_S(lli->lli_st_ctime) = src->o_ctime;
153 if (valid & OBD_MD_FLSIZE)
154 lli->lli_st_size = src->o_size;
155 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
156 lli->lli_st_blocks = src->o_blocks;
157 if (valid & OBD_MD_FLBLKSZ)
158 lli->lli_st_blksize = src->o_blksize;
159 if (valid & OBD_MD_FLTYPE)
160 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
161 if (valid & OBD_MD_FLMODE)
162 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
163 if (valid & OBD_MD_FLUID)
164 lli->lli_st_uid = src->o_uid;
165 if (valid & OBD_MD_FLGID)
166 lli->lli_st_gid = src->o_gid;
167 if (valid & OBD_MD_FLFLAGS)
168 lli->lli_st_flags = src->o_flags;
169 if (valid & OBD_MD_FLGENER)
170 lli->lli_st_generation = src->o_generation;
173 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
174 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
176 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
178 struct llu_inode_info *lli = llu_i2info(src);
179 obd_flag newvalid = 0;
181 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
182 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
183 valid, LTIME_S(lli->lli_st_mtime),
184 LTIME_S(lli->lli_st_ctime));
186 if (valid & OBD_MD_FLATIME) {
187 dst->o_atime = LTIME_S(lli->lli_st_atime);
188 newvalid |= OBD_MD_FLATIME;
190 if (valid & OBD_MD_FLMTIME) {
191 dst->o_mtime = LTIME_S(lli->lli_st_mtime);
192 newvalid |= OBD_MD_FLMTIME;
194 if (valid & OBD_MD_FLCTIME) {
195 dst->o_ctime = LTIME_S(lli->lli_st_ctime);
196 newvalid |= OBD_MD_FLCTIME;
198 if (valid & OBD_MD_FLSIZE) {
199 dst->o_size = lli->lli_st_size;
200 newvalid |= OBD_MD_FLSIZE;
202 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
203 dst->o_blocks = lli->lli_st_blocks;
204 newvalid |= OBD_MD_FLBLOCKS;
206 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
207 dst->o_blksize = lli->lli_st_blksize;
208 newvalid |= OBD_MD_FLBLKSZ;
210 if (valid & OBD_MD_FLTYPE) {
211 dst->o_mode = (dst->o_mode & S_IALLUGO)|(lli->lli_st_mode & S_IFMT);
212 newvalid |= OBD_MD_FLTYPE;
214 if (valid & OBD_MD_FLMODE) {
215 dst->o_mode = (dst->o_mode & S_IFMT)|(lli->lli_st_mode & S_IALLUGO);
216 newvalid |= OBD_MD_FLMODE;
218 if (valid & OBD_MD_FLUID) {
219 dst->o_uid = lli->lli_st_uid;
220 newvalid |= OBD_MD_FLUID;
222 if (valid & OBD_MD_FLGID) {
223 dst->o_gid = lli->lli_st_gid;
224 newvalid |= OBD_MD_FLGID;
226 if (valid & OBD_MD_FLFLAGS) {
227 dst->o_flags = lli->lli_st_flags;
228 newvalid |= OBD_MD_FLFLAGS;
230 if (valid & OBD_MD_FLGENER) {
231 dst->o_generation = lli->lli_st_generation;
232 newvalid |= OBD_MD_FLGENER;
235 dst->o_valid |= newvalid;
239 * really does the getattr on the inode and updates its fields
241 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
243 struct llu_inode_info *lli = llu_i2info(inode);
244 struct obd_export *exp = llu_i2obdexp(inode);
245 struct ptlrpc_request_set *set;
247 obd_flag refresh_valid;
254 memset(&oa, 0, sizeof oa);
255 oa.o_id = lsm->lsm_object_id;
257 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
258 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
261 set = ptlrpc_prep_set();
263 CERROR ("ENOMEM allocing request set\n");
266 rc = obd_getattr_async(exp, &oa, lsm, set);
268 rc = ptlrpc_set_wait(set);
269 ptlrpc_set_destroy(set);
274 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
275 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
277 /* We set this flag in commit write as we extend the file size. When
278 * the bit is set and the lock is canceled that covers the file size,
279 * we clear the bit. This is enough to protect the window where our
280 * local size extension is needed for writeback. However, it relies on
281 * behaviour that won't be true in the near future. This assumes that
282 * all getattr callers get extent locks, which they currnetly do. It
283 * also assumes that we only send discarding asts for {0,eof} truncates
284 * as is currently the case. This will have to be replaced by the
285 * proper eoc communication between clients and the ost, which is on
287 if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
288 if (oa.o_size < lli->lli_st_size)
289 refresh_valid &= ~OBD_MD_FLSIZE;
291 clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
294 obdo_refresh_inode(inode, &oa, refresh_valid);
297 if (inode->i_blksize < PAGE_CACHE_SIZE)
298 inode->i_blksize = PAGE_CACHE_SIZE;
300 CDEBUG(D_INODE, "objid "LPX64" size %Lu, blocks %lu, blksize %lu\n",
301 lsm->lsm_object_id, inode->i_size, inode->i_blocks,
307 static struct inode* llu_new_inode(struct filesys *fs,
311 struct llu_inode_info *lli;
313 OBD_ALLOC(lli, sizeof(*lli));
317 /* initialize lli here */
318 lli->lli_sbi = llu_fs2sbi(fs);
320 lli->lli_symlink_name = NULL;
322 lli->lli_maxbytes = (__u64)(~0UL);
323 lli->lli_file_data = NULL;
325 lli->lli_sysio_fid.fid_data = &lli->lli_fid;
326 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_fid);
328 memcpy(&lli->lli_fid, fid, sizeof(*fid));
330 /* file identifier is needed by functions like _sysio_i_find() */
331 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
332 #ifndef AUTOMOUNT_FILE_NAME
333 fid->f_type & S_IFMT,
335 fid->f_type, /* all of the bits! */
338 &llu_inode_ops, lli);
341 OBD_FREE(lli, sizeof(*lli));
347 static int ll_intent_to_lock_mode(struct lookup_intent *it)
349 /* CREAT needs to be tested before open (both could be set) */
350 if (it->it_op & IT_CREAT)
352 else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
361 int ll_it_open_error(int phase, struct lookup_intent *it)
363 if (it_disposition(it, DISP_OPEN_OPEN)) {
364 if (phase == DISP_OPEN_OPEN)
365 return it->d.lustre.it_status;
370 if (it_disposition(it, DISP_OPEN_CREATE)) {
371 if (phase == DISP_OPEN_CREATE)
372 return it->d.lustre.it_status;
377 if (it_disposition(it, DISP_LOOKUP_EXECD)) {
378 if (phase == DISP_LOOKUP_EXECD)
379 return it->d.lustre.it_status;
383 CERROR("it disp: %X, status: %d\n", it->d.lustre.it_disposition, it->d.lustre.it_status);
389 static int llu_have_md_lock(struct inode *inode)
391 struct llu_sb_info *sbi = llu_i2sbi(inode);
392 struct llu_inode_info *lli = llu_i2info(inode);
393 struct lustre_handle lockh;
394 struct ldlm_res_id res_id = { .name = {0} };
395 struct obd_device *obddev;
401 obddev = sbi->ll_mdc_exp->exp_obd;
402 res_id.name[0] = lli->lli_st_ino;
403 res_id.name[1] = lli->lli_st_generation;
405 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
407 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
408 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
409 NULL, 0, LCK_PR, &lockh)) {
410 ldlm_lock_decref(&lockh, LCK_PR);
414 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
415 NULL, 0, LCK_PW, &lockh)) {
416 ldlm_lock_decref(&lockh, LCK_PW);
422 static int llu_inode_revalidate(struct inode *inode)
424 struct llu_inode_info *lli = llu_i2info(inode);
425 struct lov_stripe_md *lsm = NULL;
429 CERROR("REPORT THIS LINE TO PETER\n");
433 if (!llu_have_md_lock(inode)) {
435 struct ptlrpc_request *req = NULL;
436 struct llu_sb_info *sbi = llu_i2sbi(inode);
438 unsigned long valid = 0;
441 /* Why don't we update all valid MDS fields here, if we're
442 * doing an RPC anyways? -phil */
443 if (S_ISREG(lli->lli_st_mode)) {
444 ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
445 valid |= OBD_MD_FLEASIZE;
447 ll_inode2fid(&fid, inode);
448 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
450 CERROR("failure %d inode %lu\n", rc, lli->lli_st_ino);
453 rc = mdc_req2lustre_md(req, 0, sbi->ll_osc_exp, &md);
455 /* XXX Too paranoid? */
456 if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) &&
457 !((md.body->valid & OBD_MD_FLNLINK) &&
458 (md.body->nlink == 0))) {
459 CERROR("Asked for %s eadata but got %s (%d)\n",
460 (valid & OBD_MD_FLEASIZE) ? "some" : "no",
461 (md.body->valid & OBD_MD_FLEASIZE) ? "some":"none",
462 md.body->eadatasize);
465 ptlrpc_req_finished(req);
470 llu_update_inode(inode, md.body, md.lsm);
471 if (md.lsm != NULL && llu_i2info(inode)->lli_smd != md.lsm)
472 obd_free_memmd(sbi->ll_osc_exp, &md.lsm);
474 if (md.body->valid & OBD_MD_FLSIZE)
475 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
476 &llu_i2info(inode)->lli_flags);
477 ptlrpc_req_finished(req);
480 lsm = llu_i2info(inode)->lli_smd;
481 if (!lsm) /* object not yet allocated, don't validate size */
485 * unfortunately stat comes in through revalidate and we don't
486 * differentiate this use from initial instantiation. we're
487 * also being wildly conservative and flushing write caches
488 * so that stat really returns the proper size.
491 struct ldlm_extent extent = {0, OBD_OBJECT_EOF};
492 struct lustre_handle lockh = {0};
495 err = llu_extent_lock(NULL, inode, lsm, LCK_PR, &extent, &lockh);
499 llu_extent_unlock(NULL, inode, lsm, LCK_PR, &lockh);
504 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
506 struct llu_inode_info *lli = llu_i2info(ino);
508 b->st_dev = lli->lli_st_dev;
509 b->st_ino = lli->lli_st_ino;
510 b->st_mode = lli->lli_st_mode;
511 b->st_nlink = lli->lli_st_nlink;
512 b->st_uid = lli->lli_st_uid;
513 b->st_gid = lli->lli_st_gid;
514 b->st_rdev = lli->lli_st_rdev;
515 b->st_size = lli->lli_st_size;
516 b->st_blksize = lli->lli_st_blksize;
517 b->st_blocks = lli->lli_st_blocks;
518 b->st_atime = lli->lli_st_atime;
519 b->st_mtime = lli->lli_st_mtime;
520 b->st_ctime = lli->lli_st_ctime;
523 static int llu_iop_getattr(struct pnode *pno,
525 struct intnl_stat *b)
532 LASSERT(pno->p_base->pb_ino);
533 ino = pno->p_base->pb_ino;
535 LASSERT(!pno || pno->p_base->pb_ino == ino);
538 /* libsysio might call us directly without intent lock,
539 * we must re-fetch the attrs here
541 rc = llu_inode_revalidate(ino);
543 copy_stat_buf(ino, b);
545 if (llu_i2info(ino)->lli_it) {
546 struct lookup_intent *it;
548 LL_GET_INTENT(ino, it);
549 it->it_op_release(it);
550 OBD_FREE(it, sizeof(*it));
557 static int null_if_equal(struct ldlm_lock *lock, void *data)
559 if (data == lock->l_ast_data)
560 lock->l_ast_data = NULL;
562 if (lock->l_req_mode != lock->l_granted_mode)
563 return LDLM_ITER_STOP;
565 return LDLM_ITER_CONTINUE;
568 void llu_clear_inode(struct inode *inode)
571 struct llu_inode_info *lli = llu_i2info(inode);
572 struct llu_sb_info *sbi = llu_i2sbi(inode);
575 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu(%p)\n", lli->lli_st_ino,
576 lli->lli_st_generation, inode);
578 ll_inode2fid(&fid, inode);
579 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
580 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
583 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
584 null_if_equal, inode);
587 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
591 if (lli->lli_symlink_name) {
592 OBD_FREE(lli->lli_symlink_name,
593 strlen(lli->lli_symlink_name) + 1);
594 lli->lli_symlink_name = NULL;
600 void llu_iop_gone(struct inode *inode)
602 struct llu_inode_info *lli = llu_i2info(inode);
605 llu_clear_inode(inode);
607 OBD_FREE(lli, sizeof(*lli));
611 static int inode_setattr(struct inode * inode, struct iattr * attr)
613 unsigned int ia_valid = attr->ia_valid;
614 struct llu_inode_info *lli = llu_i2info(inode);
617 if (ia_valid & ATTR_SIZE) {
618 error = llu_vmtruncate(inode, attr->ia_size);
623 if (ia_valid & ATTR_UID)
624 lli->lli_st_uid = attr->ia_uid;
625 if (ia_valid & ATTR_GID)
626 lli->lli_st_gid = attr->ia_gid;
627 if (ia_valid & ATTR_ATIME)
628 lli->lli_st_atime = attr->ia_atime;
629 if (ia_valid & ATTR_MTIME)
630 lli->lli_st_mtime = attr->ia_mtime;
631 if (ia_valid & ATTR_CTIME)
632 lli->lli_st_ctime = attr->ia_ctime;
633 if (ia_valid & ATTR_MODE) {
634 lli->lli_st_mode = attr->ia_mode;
635 if (!in_group_p(lli->lli_st_gid) && !capable(CAP_FSETID))
636 lli->lli_st_mode &= ~S_ISGID;
638 /* mark_inode_dirty(inode); */
643 /* If this inode has objects allocated to it (lsm != NULL), then the OST
644 * object(s) determine the file size and mtime. Otherwise, the MDS will
645 * keep these values until such a time that objects are allocated for it.
646 * We do the MDS operations first, as it is checking permissions for us.
647 * We don't to the MDS RPC if there is nothing that we want to store there,
648 * otherwise there is no harm in updating mtime/atime on the MDS if we are
649 * going to do an RPC anyways.
651 * If we are doing a truncate, we will send the mtime and ctime updates
652 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
653 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
656 #define OST_ATTR (ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME | \
657 ATTR_ATIME | ATTR_ATIME_SET | ATTR_SIZE)
658 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
660 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
661 struct llu_sb_info *sbi = llu_i2sbi(inode);
662 struct llu_inode_info *lli = llu_i2info(inode);
663 struct ptlrpc_request *request = NULL;
664 struct mdc_op_data op_data;
665 int ia_valid = attr->ia_valid;
669 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
671 if (ia_valid & ATTR_SIZE) {
672 if (attr->ia_size > ll_file_maxbytes(inode)) {
673 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
674 attr->ia_size, ll_file_maxbytes(inode));
678 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
681 /* We mark all of the fields "set" so MDS/OST does not re-set them */
682 if (attr->ia_valid & ATTR_CTIME) {
683 attr->ia_ctime = CURRENT_TIME;
684 attr->ia_valid |= ATTR_CTIME_SET;
686 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
687 attr->ia_atime = CURRENT_TIME;
688 attr->ia_valid |= ATTR_ATIME_SET;
690 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
691 attr->ia_mtime = CURRENT_TIME;
692 attr->ia_valid |= ATTR_MTIME_SET;
695 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
696 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
697 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
698 LTIME_S(CURRENT_TIME));
700 attr->ia_valid &= ~ATTR_SIZE;
702 /* If only OST attributes being set on objects, don't do MDS RPC.
703 * In that case, we need to check permissions and update the local
704 * inode ourselves so we can call obdo_from_inode() always. */
705 if (ia_valid & (lsm ? ~(OST_ATTR | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
707 llu_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
709 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
710 attr, NULL, 0, NULL, 0, &request);
713 ptlrpc_req_finished(request);
714 if (rc != -EPERM && rc != -EACCES)
715 CERROR("mdc_setattr fails: rc = %d\n", rc);
719 rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
721 ptlrpc_req_finished(request);
724 llu_update_inode(inode, md.body, md.lsm);
725 ptlrpc_req_finished(request);
727 if (!md.lsm || !S_ISREG(lli->lli_st_mode)) {
728 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
732 /* The OST doesn't check permissions, but the alternative is
733 * a gratuitous RPC to the MDS. We already rely on the client
734 * to do read/write/truncate permission checks, so is mtime OK?
736 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
737 /* from sys_utime() */
738 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
739 if (current->fsuid != lli->lli_st_uid &&
740 (rc = ll_permission(inode, 0/*MAY_WRITE*/, NULL)) != 0)
743 /* from inode_change_ok() */
744 if (current->fsuid != lli->lli_st_uid &&
745 !capable(CAP_FOWNER))
750 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
751 inode_setattr(inode, attr);
754 if (ia_valid & ATTR_SIZE) {
755 struct ldlm_extent extent = { .start = attr->ia_size,
756 .end = OBD_OBJECT_EOF };
757 struct lustre_handle lockh = { 0 };
758 int err, ast_flags = 0;
759 /* XXX when we fix the AST intents to pass the discard-range
760 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
763 /* Writeback uses inode->i_size to determine how far out
764 * its cached pages go. ll_truncate gets a PW lock, canceling
765 * our lock, _after_ it has updated i_size. this can confuse
767 * We really need to get our PW lock before we change
768 * inode->i_size. If we don't we can race with other
769 * i_size updaters on our node, like ll_file_read. We
770 * can also race with i_size propogation to other
771 * nodes through dirtying and writeback of final cached
772 * pages. This last one is especially bad for racing
773 * o_append users on other nodes. */
774 if (extent.start == 0)
775 ast_flags = LDLM_AST_DISCARD_DATA;
776 rc = llu_extent_lock_no_validate(NULL, inode, lsm, LCK_PW,
777 &extent, &lockh, ast_flags);
778 if (rc != ELDLM_OK) {
784 rc = llu_vmtruncate(inode, attr->ia_size);
786 set_bit(LLI_F_HAVE_OST_SIZE_LOCK,
787 &llu_i2info(inode)->lli_flags);
789 /* unlock now as we don't mind others file lockers racing with
790 * the mds updates below? */
791 err = llu_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
793 CERROR("llu_extent_unlock failed: %d\n", err);
797 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
800 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
801 lli->lli_st_ino, LTIME_S(attr->ia_mtime));
802 oa.o_id = lsm->lsm_object_id;
803 oa.o_valid = OBD_MD_FLID;
804 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
805 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
806 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
808 CERROR("obd_setattr fails: rc=%d\n", rc);
813 /* FIXME here we simply act as a thin layer to glue it with
814 * llu_setattr_raw(), which is copy from kernel
816 static int llu_iop_setattr(struct pnode *pno,
819 struct intnl_stat *stbuf)
824 memset(&iattr, 0, sizeof(iattr));
826 if (mask & SETATTR_MODE) {
827 iattr.ia_mode = stbuf->st_mode;
828 iattr.ia_valid |= ATTR_MODE;
830 if (mask & SETATTR_MTIME) {
831 iattr.ia_mtime = stbuf->st_mtime;
832 iattr.ia_valid |= ATTR_MTIME;
834 if (mask & SETATTR_ATIME) {
835 iattr.ia_atime = stbuf->st_atime;
836 iattr.ia_valid |= ATTR_ATIME;
838 if (mask & SETATTR_UID) {
839 iattr.ia_uid = stbuf->st_uid;
840 iattr.ia_valid |= ATTR_UID;
842 if (mask & SETATTR_GID) {
843 iattr.ia_gid = stbuf->st_gid;
844 iattr.ia_valid |= ATTR_GID;
846 if (mask & SETATTR_LEN) {
847 iattr.ia_size = stbuf->st_size; /* FIXME signed expansion problem */
848 iattr.ia_valid |= ATTR_SIZE;
851 iattr.ia_valid |= ATTR_RAW;
853 RETURN(llu_setattr_raw(ino, &iattr));
856 #define EXT2_LINK_MAX 32000
858 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
860 struct inode *dir = pno->p_base->pb_parent->pb_ino;
861 struct qstr *qstr = &pno->p_base->pb_name;
862 const char *name = qstr->name;
864 struct ptlrpc_request *request = NULL;
865 struct llu_sb_info *sbi = llu_i2sbi(dir);
866 struct mdc_op_data op_data;
870 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
873 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
874 err = mdc_create(sbi->ll_mdc_exp, &op_data,
875 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
876 current->fsuid, current->fsgid, 0, &request);
877 ptlrpc_req_finished(request);
881 static int llu_readlink_internal(struct inode *inode,
882 struct ptlrpc_request **request,
885 struct llu_inode_info *lli = llu_i2info(inode);
886 struct llu_sb_info *sbi = llu_i2sbi(inode);
888 struct mds_body *body;
889 int rc, symlen = lli->lli_st_size + 1;
894 if (lli->lli_symlink_name) {
895 *symname = lli->lli_symlink_name;
896 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
900 ll_inode2fid(&fid, inode);
901 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
902 OBD_MD_LINKNAME, symlen, request);
904 CERROR("inode %lu: rc = %d\n", lli->lli_st_ino, rc);
908 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
909 LASSERT (body != NULL);
910 LASSERT_REPSWABBED (*request, 0);
912 if ((body->valid & OBD_MD_LINKNAME) == 0) {
913 CERROR ("OBD_MD_LINKNAME not set on reply\n");
914 GOTO (failed, rc = -EPROTO);
917 LASSERT (symlen != 0);
918 if (body->eadatasize != symlen) {
919 CERROR ("inode %lu: symlink length %d not expected %d\n",
920 lli->lli_st_ino, body->eadatasize - 1, symlen - 1);
921 GOTO (failed, rc = -EPROTO);
924 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
925 if (*symname == NULL ||
926 strnlen (*symname, symlen) != symlen - 1) {
927 /* not full/NULL terminated */
928 CERROR ("inode %lu: symlink not NULL terminated string"
929 "of length %d\n", lli->lli_st_ino, symlen - 1);
930 GOTO (failed, rc = -EPROTO);
933 OBD_ALLOC(lli->lli_symlink_name, symlen);
934 /* do not return an error if we cannot cache the symlink locally */
935 if (lli->lli_symlink_name)
936 memcpy(lli->lli_symlink_name, *symname, symlen);
941 ptlrpc_req_finished (*request);
945 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
947 struct inode *inode = pno->p_base->pb_ino;
948 struct ptlrpc_request *request;
953 /* on symlinks lli_open_sem protects lli_symlink_name allocation/data */
955 down(&lli->lli_open_sem);
957 rc = llu_readlink_internal(inode, &request, &symname);
962 strncpy(data, symname, bufsize);
964 ptlrpc_req_finished(request);
967 up(&lli->lli_open_sem);
972 static int llu_iop_mknod_raw(struct pnode *pno,
976 struct ptlrpc_request *request = NULL;
977 struct inode *dir = pno->p_parent->p_base->pb_ino;
978 struct llu_sb_info *sbi = llu_i2sbi(dir);
979 struct mdc_op_data op_data;
983 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu\n",
984 pno->p_base->pb_name.name, llu_i2info(dir)->lli_st_ino);
986 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
989 mode &= ~current->fs->umask;
991 switch (mode & S_IFMT) {
994 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
999 llu_prepare_mdc_op_data(&op_data, dir, NULL,
1000 pno->p_base->pb_name.name,
1001 pno->p_base->pb_name.len,
1003 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
1004 current->fsuid, current->fsgid, dev, &request);
1005 ptlrpc_req_finished(request);
1017 static int llu_mdc_unlink(struct inode *dir, struct inode *child, __u32 mode,
1018 const char *name, int len)
1020 struct ptlrpc_request *request = NULL;
1021 struct mds_body *body;
1022 struct lov_mds_md *eadata;
1023 struct lov_stripe_md *lsm = NULL;
1024 struct obd_trans_info oti = { 0 };
1025 struct mdc_op_data op_data;
1030 llu_prepare_mdc_op_data(&op_data, dir, child, name, len, mode);
1031 rc = mdc_unlink(&llu_i2sbi(dir)->ll_mdc_conn, &op_data, &request);
1034 /* req is swabbed so this is safe */
1035 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
1037 if (!(body->valid & OBD_MD_FLEASIZE))
1040 if (body->eadatasize == 0) {
1041 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
1042 GOTO(out, rc = -EPROTO);
1045 /* The MDS sent back the EA because we unlinked the last reference
1046 * to this file. Use this EA to unlink the objects on the OST.
1047 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
1048 * check it is complete and sensible. */
1049 eadata = lustre_swab_repbuf(request, 1, body->eadatasize, NULL);
1050 LASSERT(eadata != NULL);
1051 if (eadata == NULL) {
1052 CERROR("Can't unpack MDS EA data\n");
1053 GOTO(out, rc = -EPROTO);
1056 rc = obd_unpackmd(llu_i2obdconn(dir), &lsm, eadata, body->eadatasize);
1058 CERROR("obd_unpackmd: %d\n", rc);
1061 LASSERT(rc >= sizeof(*lsm));
1065 GOTO(out_free_memmd, rc = -ENOMEM);
1067 oa->o_id = lsm->lsm_object_id;
1068 oa->o_mode = body->mode & S_IFMT;
1069 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
1071 if (body->valid & OBD_MD_FLCOOKIE) {
1072 oa->o_valid |= OBD_MD_FLCOOKIE;
1073 oti.oti_logcookies = lustre_msg_buf(request->rq_repmsg, 3,
1077 rc = obd_destroy(llu_i2obdconn(dir), oa, lsm, &oti);
1080 CERROR("obd destroy objid 0x"LPX64" error %d\n",
1081 lsm->lsm_object_id, rc);
1083 obd_free_memmd(llu_i2obdconn(dir), &lsm);
1085 ptlrpc_req_finished(request);
1090 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
1092 struct inode *src = old->p_base->pb_ino;
1093 struct inode *dir = new->p_parent->p_base->pb_ino;
1094 const char *name = new->p_base->pb_name.name;
1095 int namelen = new->p_base->pb_name.len;
1096 struct ptlrpc_request *request = NULL;
1097 struct mdc_op_data op_data;
1104 llu_prepare_mdc_op_data(&op_data, src, dir, name, namelen, 0);
1105 rc = mdc_link(llu_i2sbi(src)->ll_mdc_exp, &op_data, &request);
1106 ptlrpc_req_finished(request);
1111 static int llu_iop_unlink_raw(struct pnode *pno)
1113 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1114 struct qstr *qstr = &pno->p_base->pb_name;
1115 const char *name = qstr->name;
1116 int len = qstr->len;
1117 struct inode *target = pno->p_base->pb_ino;
1118 struct ptlrpc_request *request = NULL;
1119 struct mdc_op_data op_data;
1125 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1126 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1128 rc = llu_objects_destroy(request, dir);
1130 llu_i2info(target)->lli_stale_flag = 1;
1131 unhook_stale_inode(pno);
1134 ptlrpc_req_finished(request);
1139 * following cases need to be considered later:
1140 * - rename an opened file/dir
1141 * - an opened file be removed in rename
1142 * - rename to remove and hardlink (?opened)
1144 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
1146 struct inode *src = old->p_parent->p_base->pb_ino;
1147 struct inode *tgt = new->p_parent->p_base->pb_ino;
1148 struct inode *tgtinode = new->p_base->pb_ino;
1149 const char *oldname = old->p_base->pb_name.name;
1150 int oldnamelen = old->p_base->pb_name.len;
1151 const char *newname = new->p_base->pb_name.name;
1152 int newnamelen = new->p_base->pb_name.len;
1153 struct ptlrpc_request *request = NULL;
1154 struct mdc_op_data op_data;
1161 llu_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0);
1162 rc = mdc_rename(llu_i2sbi(src)->ll_mdc_exp, &op_data,
1163 oldname, oldnamelen, newname, newnamelen,
1166 rc = llu_objects_destroy(request, src);
1169 llu_i2info(tgtinode)->lli_stale_flag = 1;
1170 unhook_stale_inode(new);
1174 ptlrpc_req_finished(request);
1180 static int llu_statfs_internal(struct llu_sb_info *sbi,
1181 struct obd_statfs *osfs,
1182 unsigned long max_age)
1184 struct obd_statfs obd_osfs;
1188 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1190 CERROR("mdc_statfs fails: rc = %d\n", rc);
1194 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1195 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1197 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1199 CERROR("obd_statfs fails: rc = %d\n", rc);
1203 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1204 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1207 osfs->os_blocks = obd_osfs.os_blocks;
1208 osfs->os_bfree = obd_osfs.os_bfree;
1209 osfs->os_bavail = obd_osfs.os_bavail;
1211 /* If we don't have as many objects free on the OST as inodes
1212 * on the MDS, we reduce the total number of inodes to
1213 * compensate, so that the "inodes in use" number is correct.
1215 if (obd_osfs.os_ffree < osfs->os_ffree) {
1216 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1218 osfs->os_ffree = obd_osfs.os_ffree;
1224 static int llu_statfs(struct llu_sb_info *sbi, struct kstatfs *sfs)
1226 struct obd_statfs osfs;
1229 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1231 /* For now we will always get up-to-date statfs values, but in the
1232 * future we may allow some amount of caching on the client (e.g.
1233 * from QOS or lprocfs updates). */
1234 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1238 statfs_unpack(sfs, &osfs);
1240 if (sizeof(sfs->f_blocks) == 4) {
1241 while (osfs.os_blocks > ~0UL) {
1244 osfs.os_blocks >>= 1;
1245 osfs.os_bfree >>= 1;
1246 osfs.os_bavail >>= 1;
1250 sfs->f_blocks = osfs.os_blocks;
1251 sfs->f_bfree = osfs.os_bfree;
1252 sfs->f_bavail = osfs.os_bavail;
1257 static int llu_iop_statvfs(struct pnode *pno,
1259 struct intnl_statvfs *buf)
1266 LASSERT(pno->p_base->pb_ino);
1267 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1271 /* from native driver */
1272 buf->f_bsize = fs.f_bsize; /* file system block size */
1273 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1274 buf->f_blocks = fs.f_blocks;
1275 buf->f_bfree = fs.f_bfree;
1276 buf->f_bavail = fs.f_bavail;
1277 buf->f_files = fs.f_files; /* Total number serial numbers */
1278 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1279 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1280 buf->f_fsid = fs.f_fsid.__val[1];
1281 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1282 buf->f_namemax = fs.f_namelen;
1289 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1291 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1292 struct qstr *qstr = &pno->p_base->pb_name;
1293 const char *name = qstr->name;
1294 int len = qstr->len;
1295 struct ptlrpc_request *request = NULL;
1296 struct llu_inode_info *lli = llu_i2info(dir);
1297 struct mdc_op_data op_data;
1300 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1301 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1303 if (lli->lli_st_nlink >= EXT2_LINK_MAX)
1306 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
1307 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1308 err = mdc_create(llu_i2sbi(dir)->ll_mdc_exp, &op_data, NULL, 0, mode,
1309 current->fsuid, current->fsgid, 0, &request);
1310 ptlrpc_req_finished(request);
1314 static int llu_iop_rmdir_raw(struct pnode *pno)
1316 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1317 struct qstr *qstr = &pno->p_base->pb_name;
1318 const char *name = qstr->name;
1319 int len = qstr->len;
1320 struct ptlrpc_request *request = NULL;
1321 struct mdc_op_data op_data;
1322 struct llu_inode_info *lli = llu_i2info(dir);
1325 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1326 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1328 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, S_IFDIR);
1329 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1330 ptlrpc_req_finished(request);
1332 /* libsysio: remove the pnode right away */
1334 llu_i2info(pno->p_base->pb_ino)->lli_stale_flag = 1;
1335 unhook_stale_inode(pno);
1341 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap)
1343 CERROR("liblustre did not support fcntl\n");
1347 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1350 CERROR("liblustre did not support ioctl\n");
1355 * we already do syncronous read/write
1357 static int llu_iop_sync(struct inode *inode)
1362 static int llu_iop_datasync(struct inode *inode)
1367 struct filesys_ops llu_filesys_ops =
1369 fsop_gone: llu_fsop_gone,
1372 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1374 struct inode *inode;
1376 struct file_identifier fileid = {&fid, sizeof(fid)};
1378 if ((md->body->valid &
1379 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1380 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE))
1381 CERROR("invalide fields!\n");
1383 /* try to find existing inode */
1384 fid.id = md->body->ino;
1385 fid.generation = md->body->generation;
1386 fid.f_type = md->body->mode & S_IFMT;
1388 inode = _sysio_i_find(fs, &fileid);
1390 if (llu_i2info(inode)->lli_st_generation ==
1391 md->body->generation) {
1392 llu_update_inode(inode, md->body, md->lsm);
1398 inode = llu_new_inode(fs, &fid);
1400 llu_update_inode(inode, md->body, md->lsm);
1405 extern struct list_head lustre_profile_list;
1408 llu_fsswop_mount(const char *source,
1410 const void *data __IS_UNUSED,
1411 struct pnode *tocover,
1412 struct mount **mntp)
1416 struct pnode_base *rootpb;
1417 struct obd_device *obd;
1418 struct ll_fid rootfid;
1419 struct llu_sb_info *sbi;
1420 struct obd_statfs osfs;
1421 static struct qstr noname = { NULL, 0, 0 };
1422 struct ptlrpc_request *request = NULL;
1423 struct lustre_handle mdc_conn = {0, };
1424 struct lustre_handle osc_conn = {0, };
1425 struct lustre_md md;
1427 struct lustre_profile *lprof;
1428 char *osc = NULL, *mdc = NULL;
1433 /* allocate & initialize sbi */
1434 OBD_ALLOC(sbi, sizeof(*sbi));
1438 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1439 generate_random_uuid(uuid);
1440 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1444 struct config_llog_instance cfg;
1447 if (!g_zconf_mdsname) {
1448 CERROR("no mds name\n");
1449 GOTO(out_free, err = -EINVAL);
1453 /* generate a string unique to this super, let's try
1454 the address of the super itself.*/
1455 len = (sizeof(sbi) * 2) + 1;
1456 OBD_ALLOC(sbi->ll_instance, len);
1457 if (sbi->ll_instance == NULL)
1458 GOTO(out_free, err = -ENOMEM);
1459 sprintf(sbi->ll_instance, "%p", sbi);
1461 cfg.cfg_instance = sbi->ll_instance;
1462 cfg.cfg_uuid = sbi->ll_sb_uuid;
1463 err = liblustre_process_log(&cfg);
1465 CERROR("Unable to process log: %s\n", g_zconf_profile);
1467 GOTO(out_free, err);
1470 lprof = class_get_profile(g_zconf_profile);
1471 if (lprof == NULL) {
1472 CERROR("No profile found: %s\n", g_zconf_profile);
1473 GOTO(out_free, err = -EINVAL);
1476 OBD_FREE(osc, strlen(osc) + 1);
1477 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
1478 strlen(sbi->ll_instance) + 2);
1479 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
1482 OBD_FREE(mdc, strlen(mdc) + 1);
1483 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
1484 strlen(sbi->ll_instance) + 2);
1485 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
1487 /* setup from dump_file */
1488 if (list_empty(&lustre_profile_list)) {
1489 CERROR("no profile\n");
1490 GOTO(out_free, err = -EINVAL);
1493 lprof = list_entry(lustre_profile_list.next,
1494 struct lustre_profile, lp_list);
1495 osc = lprof->lp_osc;
1496 mdc = lprof->lp_mdc;
1501 GOTO(out_free, err = -EINVAL);
1505 GOTO(out_free, err = -EINVAL);
1508 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1514 obd = class_name2obd(mdc);
1516 CERROR("MDC %s: not setup or attached\n", mdc);
1517 GOTO(out_free, err = -EINVAL);
1520 if (mdc_init_ea_size(obd, osc))
1521 GOTO(out_free, err = -EINVAL);
1524 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
1526 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
1527 GOTO(out_free, err);
1529 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
1531 err = obd_statfs(obd, &osfs, 100000000);
1536 * FIXME fill fs stat data into sbi here!!! FIXME
1540 obd = class_name2obd(osc);
1542 CERROR("OSC %s: not setup or attached\n", osc);
1543 GOTO(out_mdc, err = -EINVAL);
1546 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
1548 CERROR("cannot connect to %s: rc = %d\n", osc, err);
1551 sbi->ll_osc_exp = class_conn2export(&osc_conn);
1553 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
1555 CERROR("cannot mds_connect: rc = %d\n", err);
1558 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
1559 sbi->ll_rootino = rootfid.id;
1561 /* fetch attr of root inode */
1562 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
1563 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
1565 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1569 err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
1571 CERROR("failed to understand root inode md: rc = %d\n",err);
1572 GOTO(out_request, err);
1575 LASSERT(sbi->ll_rootino != 0);
1577 root = llu_iget(fs, &md);
1579 CERROR("fail to generate root inode\n");
1580 GOTO(out_request, err = -EBADF);
1584 * Generate base path-node for root.
1586 rootpb = _sysio_pb_new(&noname, NULL, root);
1592 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1594 _sysio_pb_gone(rootpb);
1598 ptlrpc_req_finished(request);
1600 printf("LibLustre: namespace mounted successfully!\n");
1605 _sysio_i_gone(root);
1607 ptlrpc_req_finished(request);
1609 obd_disconnect(sbi->ll_osc_exp, 0);
1611 obd_disconnect(sbi->ll_mdc_exp, 0);
1613 OBD_FREE(sbi, sizeof(*sbi));
1617 struct fssw_ops llu_fssw_ops = {
1621 static struct inode_ops llu_inode_ops = {
1622 inop_lookup: llu_iop_lookup,
1623 inop_getattr: llu_iop_getattr,
1624 inop_setattr: llu_iop_setattr,
1625 inop_getdirentries: NULL,
1626 inop_mkdir: llu_iop_mkdir_raw,
1627 inop_rmdir: llu_iop_rmdir_raw,
1628 inop_symlink: llu_iop_symlink_raw,
1629 inop_readlink: llu_iop_readlink,
1630 inop_open: llu_iop_open,
1631 inop_close: llu_iop_close,
1632 inop_link: llu_iop_link_raw,
1633 inop_unlink: llu_iop_unlink_raw,
1634 inop_rename: llu_iop_rename_raw,
1635 inop_ipreadv: llu_iop_ipreadv,
1636 inop_ipwritev: llu_iop_ipwritev,
1637 inop_iodone: llu_iop_iodone,
1638 inop_fcntl: llu_iop_fcntl,
1639 inop_sync: llu_iop_sync,
1640 inop_datasync: llu_iop_datasync,
1641 inop_ioctl: llu_iop_ioctl,
1642 inop_mknod: llu_iop_mknod_raw,
1644 inop_statvfs: llu_iop_statvfs,
1646 inop_gone: llu_iop_gone,