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_FLNLINK)
170 lli->lli_st_nlink = src->o_nlink;
171 if (valid & OBD_MD_FLGENER)
172 lli->lli_st_generation = src->o_generation;
173 if (valid & OBD_MD_FLRDEV)
174 lli->lli_st_rdev = to_kdev_t(src->o_rdev);
177 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
178 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
180 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
182 struct llu_inode_info *lli = llu_i2info(src);
183 obd_flag newvalid = 0;
185 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
186 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
187 valid, LTIME_S(lli->lli_st_mtime),
188 LTIME_S(lli->lli_st_ctime));
190 if (valid & OBD_MD_FLATIME) {
191 dst->o_atime = LTIME_S(lli->lli_st_atime);
192 newvalid |= OBD_MD_FLATIME;
194 if (valid & OBD_MD_FLMTIME) {
195 dst->o_mtime = LTIME_S(lli->lli_st_mtime);
196 newvalid |= OBD_MD_FLMTIME;
198 if (valid & OBD_MD_FLCTIME) {
199 dst->o_ctime = LTIME_S(lli->lli_st_ctime);
200 newvalid |= OBD_MD_FLCTIME;
202 if (valid & OBD_MD_FLSIZE) {
203 dst->o_size = lli->lli_st_size;
204 newvalid |= OBD_MD_FLSIZE;
206 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
207 dst->o_blocks = lli->lli_st_blocks;
208 newvalid |= OBD_MD_FLBLOCKS;
210 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
211 dst->o_blksize = lli->lli_st_blksize;
212 newvalid |= OBD_MD_FLBLKSZ;
214 if (valid & OBD_MD_FLTYPE) {
215 dst->o_mode = (dst->o_mode & S_IALLUGO)|(lli->lli_st_mode & S_IFMT);
216 newvalid |= OBD_MD_FLTYPE;
218 if (valid & OBD_MD_FLMODE) {
219 dst->o_mode = (dst->o_mode & S_IFMT)|(lli->lli_st_mode & S_IALLUGO);
220 newvalid |= OBD_MD_FLMODE;
222 if (valid & OBD_MD_FLUID) {
223 dst->o_uid = lli->lli_st_uid;
224 newvalid |= OBD_MD_FLUID;
226 if (valid & OBD_MD_FLGID) {
227 dst->o_gid = lli->lli_st_gid;
228 newvalid |= OBD_MD_FLGID;
230 if (valid & OBD_MD_FLFLAGS) {
231 dst->o_flags = lli->lli_st_flags;
232 newvalid |= OBD_MD_FLFLAGS;
234 if (valid & OBD_MD_FLNLINK) {
235 dst->o_nlink = lli->lli_st_nlink;
236 newvalid |= OBD_MD_FLNLINK;
238 if (valid & OBD_MD_FLGENER) {
239 dst->o_generation = lli->lli_st_generation;
240 newvalid |= OBD_MD_FLGENER;
242 if (valid & OBD_MD_FLRDEV) {
243 dst->o_rdev = (__u32)kdev_t_to_nr(lli->lli_st_rdev);
244 newvalid |= OBD_MD_FLRDEV;
247 dst->o_valid |= newvalid;
251 * really does the getattr on the inode and updates its fields
253 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
255 struct llu_inode_info *lli = llu_i2info(inode);
256 struct obd_export *exp = llu_i2obdexp(inode);
257 struct ptlrpc_request_set *set;
259 obd_flag refresh_valid;
266 memset(&oa, 0, sizeof oa);
267 oa.o_id = lsm->lsm_object_id;
269 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
270 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
273 set = ptlrpc_prep_set();
275 CERROR ("ENOMEM allocing request set\n");
278 rc = obd_getattr_async(exp, &oa, lsm, set);
280 rc = ptlrpc_set_wait(set);
281 ptlrpc_set_destroy(set);
286 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
287 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
289 /* We set this flag in commit write as we extend the file size. When
290 * the bit is set and the lock is canceled that covers the file size,
291 * we clear the bit. This is enough to protect the window where our
292 * local size extension is needed for writeback. However, it relies on
293 * behaviour that won't be true in the near future. This assumes that
294 * all getattr callers get extent locks, which they currnetly do. It
295 * also assumes that we only send discarding asts for {0,eof} truncates
296 * as is currently the case. This will have to be replaced by the
297 * proper eoc communication between clients and the ost, which is on
299 if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
300 if (oa.o_size < lli->lli_st_size)
301 refresh_valid &= ~OBD_MD_FLSIZE;
303 clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
306 obdo_refresh_inode(inode, &oa, refresh_valid);
309 if (inode->i_blksize < PAGE_CACHE_SIZE)
310 inode->i_blksize = PAGE_CACHE_SIZE;
312 CDEBUG(D_INODE, "objid "LPX64" size %Lu, blocks %lu, blksize %lu\n",
313 lsm->lsm_object_id, inode->i_size, inode->i_blocks,
319 static struct inode* llu_new_inode(struct filesys *fs,
323 struct llu_inode_info *lli;
325 OBD_ALLOC(lli, sizeof(*lli));
329 /* initialize lli here */
330 lli->lli_sbi = llu_fs2sbi(fs);
332 lli->lli_symlink_name = NULL;
334 lli->lli_maxbytes = (__u64)(~0UL);
335 lli->lli_file_data = NULL;
337 lli->lli_sysio_fid.fid_data = &lli->lli_fid;
338 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_fid);
340 memcpy(&lli->lli_fid, fid, sizeof(*fid));
342 /* file identifier is needed by functions like _sysio_i_find() */
343 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
344 #ifndef AUTOMOUNT_FILE_NAME
345 fid->f_type & S_IFMT,
347 fid->f_type, /* all of the bits! */
350 &llu_inode_ops, lli);
353 OBD_FREE(lli, sizeof(*lli));
359 static int ll_intent_to_lock_mode(struct lookup_intent *it)
361 /* CREAT needs to be tested before open (both could be set) */
362 if (it->it_op & IT_CREAT)
364 else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
373 int ll_it_open_error(int phase, struct lookup_intent *it)
375 if (it_disposition(it, DISP_OPEN_OPEN)) {
376 if (phase == DISP_OPEN_OPEN)
377 return it->d.lustre.it_status;
382 if (it_disposition(it, DISP_OPEN_CREATE)) {
383 if (phase == DISP_OPEN_CREATE)
384 return it->d.lustre.it_status;
389 if (it_disposition(it, DISP_LOOKUP_EXECD)) {
390 if (phase == DISP_LOOKUP_EXECD)
391 return it->d.lustre.it_status;
395 CERROR("it disp: %X, status: %d\n", it->d.lustre.it_disposition, it->d.lustre.it_status);
401 static int llu_have_md_lock(struct inode *inode)
403 struct llu_sb_info *sbi = llu_i2sbi(inode);
404 struct llu_inode_info *lli = llu_i2info(inode);
405 struct lustre_handle lockh;
406 struct ldlm_res_id res_id = { .name = {0} };
407 struct obd_device *obddev;
413 obddev = sbi->ll_mdc_exp->exp_obd;
414 res_id.name[0] = lli->lli_st_ino;
415 res_id.name[1] = lli->lli_st_generation;
417 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
419 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
420 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
421 NULL, 0, LCK_PR, &lockh)) {
422 ldlm_lock_decref(&lockh, LCK_PR);
426 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
427 NULL, 0, LCK_PW, &lockh)) {
428 ldlm_lock_decref(&lockh, LCK_PW);
434 static int llu_inode_revalidate(struct inode *inode)
436 struct llu_inode_info *lli = llu_i2info(inode);
437 struct lov_stripe_md *lsm = NULL;
441 CERROR("REPORT THIS LINE TO PETER\n");
445 if (!llu_have_md_lock(inode)) {
447 struct ptlrpc_request *req = NULL;
448 struct llu_sb_info *sbi = llu_i2sbi(inode);
450 unsigned long valid = 0;
453 /* Why don't we update all valid MDS fields here, if we're
454 * doing an RPC anyways? -phil */
455 if (S_ISREG(lli->lli_st_mode)) {
456 ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
457 valid |= OBD_MD_FLEASIZE;
459 ll_inode2fid(&fid, inode);
460 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
462 CERROR("failure %d inode %lu\n", rc, lli->lli_st_ino);
465 rc = mdc_req2lustre_md(req, 0, sbi->ll_osc_exp, &md);
467 /* XXX Too paranoid? */
468 if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) &&
469 !((md.body->valid & OBD_MD_FLNLINK) &&
470 (md.body->nlink == 0))) {
471 CERROR("Asked for %s eadata but got %s (%d)\n",
472 (valid & OBD_MD_FLEASIZE) ? "some" : "no",
473 (md.body->valid & OBD_MD_FLEASIZE) ? "some":"none",
474 md.body->eadatasize);
477 ptlrpc_req_finished(req);
482 llu_update_inode(inode, md.body, md.lsm);
483 if (md.lsm != NULL && llu_i2info(inode)->lli_smd != md.lsm)
484 obd_free_memmd(sbi->ll_osc_exp, &md.lsm);
486 if (md.body->valid & OBD_MD_FLSIZE)
487 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
488 &llu_i2info(inode)->lli_flags);
489 ptlrpc_req_finished(req);
492 lsm = llu_i2info(inode)->lli_smd;
493 if (!lsm) /* object not yet allocated, don't validate size */
497 * unfortunately stat comes in through revalidate and we don't
498 * differentiate this use from initial instantiation. we're
499 * also being wildly conservative and flushing write caches
500 * so that stat really returns the proper size.
503 struct ldlm_extent extent = {0, OBD_OBJECT_EOF};
504 struct lustre_handle lockh = {0};
507 err = llu_extent_lock(NULL, inode, lsm, LCK_PR, &extent, &lockh);
511 llu_extent_unlock(NULL, inode, lsm, LCK_PR, &lockh);
516 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
518 struct llu_inode_info *lli = llu_i2info(ino);
520 b->st_dev = lli->lli_st_dev;
521 b->st_ino = lli->lli_st_ino;
522 b->st_mode = lli->lli_st_mode;
523 b->st_nlink = lli->lli_st_nlink;
524 b->st_uid = lli->lli_st_uid;
525 b->st_gid = lli->lli_st_gid;
526 b->st_rdev = lli->lli_st_rdev;
527 b->st_size = lli->lli_st_size;
528 b->st_blksize = lli->lli_st_blksize;
529 b->st_blocks = lli->lli_st_blocks;
530 b->st_atime = lli->lli_st_atime;
531 b->st_mtime = lli->lli_st_mtime;
532 b->st_ctime = lli->lli_st_ctime;
535 static int llu_iop_getattr(struct pnode *pno,
537 struct intnl_stat *b)
544 LASSERT(pno->p_base->pb_ino);
545 ino = pno->p_base->pb_ino;
547 LASSERT(!pno || pno->p_base->pb_ino == ino);
550 /* libsysio might call us directly without intent lock,
551 * we must re-fetch the attrs here
553 rc = llu_inode_revalidate(ino);
555 copy_stat_buf(ino, b);
557 if (llu_i2info(ino)->lli_it) {
558 struct lookup_intent *it;
560 LL_GET_INTENT(ino, it);
561 it->it_op_release(it);
562 OBD_FREE(it, sizeof(*it));
569 static int null_if_equal(struct ldlm_lock *lock, void *data)
571 if (data == lock->l_ast_data)
572 lock->l_ast_data = NULL;
574 if (lock->l_req_mode != lock->l_granted_mode)
575 return LDLM_ITER_STOP;
577 return LDLM_ITER_CONTINUE;
580 void llu_clear_inode(struct inode *inode)
583 struct llu_inode_info *lli = llu_i2info(inode);
584 struct llu_sb_info *sbi = llu_i2sbi(inode);
587 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu(%p)\n", lli->lli_st_ino,
588 lli->lli_st_generation, inode);
590 ll_inode2fid(&fid, inode);
591 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
592 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
595 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
596 null_if_equal, inode);
599 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
603 if (lli->lli_symlink_name) {
604 OBD_FREE(lli->lli_symlink_name,
605 strlen(lli->lli_symlink_name) + 1);
606 lli->lli_symlink_name = NULL;
612 void llu_iop_gone(struct inode *inode)
614 struct llu_inode_info *lli = llu_i2info(inode);
617 llu_clear_inode(inode);
619 OBD_FREE(lli, sizeof(*lli));
623 static int inode_setattr(struct inode * inode, struct iattr * attr)
625 unsigned int ia_valid = attr->ia_valid;
626 struct llu_inode_info *lli = llu_i2info(inode);
629 if (ia_valid & ATTR_SIZE) {
630 error = llu_vmtruncate(inode, attr->ia_size);
635 if (ia_valid & ATTR_UID)
636 lli->lli_st_uid = attr->ia_uid;
637 if (ia_valid & ATTR_GID)
638 lli->lli_st_gid = attr->ia_gid;
639 if (ia_valid & ATTR_ATIME)
640 lli->lli_st_atime = attr->ia_atime;
641 if (ia_valid & ATTR_MTIME)
642 lli->lli_st_mtime = attr->ia_mtime;
643 if (ia_valid & ATTR_CTIME)
644 lli->lli_st_ctime = attr->ia_ctime;
645 if (ia_valid & ATTR_MODE) {
646 lli->lli_st_mode = attr->ia_mode;
647 if (!in_group_p(lli->lli_st_gid) && !capable(CAP_FSETID))
648 lli->lli_st_mode &= ~S_ISGID;
650 /* mark_inode_dirty(inode); */
655 /* If this inode has objects allocated to it (lsm != NULL), then the OST
656 * object(s) determine the file size and mtime. Otherwise, the MDS will
657 * keep these values until such a time that objects are allocated for it.
658 * We do the MDS operations first, as it is checking permissions for us.
659 * We don't to the MDS RPC if there is nothing that we want to store there,
660 * otherwise there is no harm in updating mtime/atime on the MDS if we are
661 * going to do an RPC anyways.
663 * If we are doing a truncate, we will send the mtime and ctime updates
664 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
665 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
668 #define OST_ATTR (ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME | \
669 ATTR_ATIME | ATTR_ATIME_SET | ATTR_SIZE)
670 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
672 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
673 struct llu_sb_info *sbi = llu_i2sbi(inode);
674 struct llu_inode_info *lli = llu_i2info(inode);
675 struct ptlrpc_request *request = NULL;
676 struct mdc_op_data op_data;
677 int ia_valid = attr->ia_valid;
681 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
683 if (ia_valid & ATTR_SIZE) {
684 if (attr->ia_size > ll_file_maxbytes(inode)) {
685 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
686 attr->ia_size, ll_file_maxbytes(inode));
690 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
693 /* We mark all of the fields "set" so MDS/OST does not re-set them */
694 if (attr->ia_valid & ATTR_CTIME) {
695 attr->ia_ctime = CURRENT_TIME;
696 attr->ia_valid |= ATTR_CTIME_SET;
698 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
699 attr->ia_atime = CURRENT_TIME;
700 attr->ia_valid |= ATTR_ATIME_SET;
702 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
703 attr->ia_mtime = CURRENT_TIME;
704 attr->ia_valid |= ATTR_MTIME_SET;
707 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
708 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
709 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
710 LTIME_S(CURRENT_TIME));
712 attr->ia_valid &= ~ATTR_SIZE;
714 /* If only OST attributes being set on objects, don't do MDS RPC.
715 * In that case, we need to check permissions and update the local
716 * inode ourselves so we can call obdo_from_inode() always. */
717 if (ia_valid & (lsm ? ~(OST_ATTR | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
719 llu_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
721 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
722 attr, NULL, 0, NULL, 0, &request);
725 ptlrpc_req_finished(request);
726 if (rc != -EPERM && rc != -EACCES)
727 CERROR("mdc_setattr fails: rc = %d\n", rc);
731 rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
733 ptlrpc_req_finished(request);
736 llu_update_inode(inode, md.body, md.lsm);
737 ptlrpc_req_finished(request);
739 if (!md.lsm || !S_ISREG(lli->lli_st_mode)) {
740 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
744 /* The OST doesn't check permissions, but the alternative is
745 * a gratuitous RPC to the MDS. We already rely on the client
746 * to do read/write/truncate permission checks, so is mtime OK?
748 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
749 /* from sys_utime() */
750 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
751 if (current->fsuid != lli->lli_st_uid &&
752 (rc = ll_permission(inode, 0/*MAY_WRITE*/, NULL)) != 0)
755 /* from inode_change_ok() */
756 if (current->fsuid != lli->lli_st_uid &&
757 !capable(CAP_FOWNER))
762 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
763 inode_setattr(inode, attr);
766 if (ia_valid & ATTR_SIZE) {
767 struct ldlm_extent extent = { .start = attr->ia_size,
768 .end = OBD_OBJECT_EOF };
769 struct lustre_handle lockh = { 0 };
770 int err, ast_flags = 0;
771 /* XXX when we fix the AST intents to pass the discard-range
772 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
775 /* Writeback uses inode->i_size to determine how far out
776 * its cached pages go. ll_truncate gets a PW lock, canceling
777 * our lock, _after_ it has updated i_size. this can confuse
779 * We really need to get our PW lock before we change
780 * inode->i_size. If we don't we can race with other
781 * i_size updaters on our node, like ll_file_read. We
782 * can also race with i_size propogation to other
783 * nodes through dirtying and writeback of final cached
784 * pages. This last one is especially bad for racing
785 * o_append users on other nodes. */
786 if (extent.start == 0)
787 ast_flags = LDLM_AST_DISCARD_DATA;
788 rc = llu_extent_lock_no_validate(NULL, inode, lsm, LCK_PW,
789 &extent, &lockh, ast_flags);
790 if (rc != ELDLM_OK) {
796 rc = llu_vmtruncate(inode, attr->ia_size);
798 set_bit(LLI_F_HAVE_OST_SIZE_LOCK,
799 &llu_i2info(inode)->lli_flags);
801 /* unlock now as we don't mind others file lockers racing with
802 * the mds updates below? */
803 err = llu_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
805 CERROR("llu_extent_unlock failed: %d\n", err);
809 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
812 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
813 lli->lli_st_ino, LTIME_S(attr->ia_mtime));
814 oa.o_id = lsm->lsm_object_id;
815 oa.o_valid = OBD_MD_FLID;
816 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
817 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
818 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
820 CERROR("obd_setattr fails: rc=%d\n", rc);
825 /* FIXME here we simply act as a thin layer to glue it with
826 * llu_setattr_raw(), which is copy from kernel
828 static int llu_iop_setattr(struct pnode *pno,
831 struct intnl_stat *stbuf)
836 memset(&iattr, 0, sizeof(iattr));
838 if (mask & SETATTR_MODE) {
839 iattr.ia_mode = stbuf->st_mode;
840 iattr.ia_valid |= ATTR_MODE;
842 if (mask & SETATTR_MTIME) {
843 iattr.ia_mtime = stbuf->st_mtime;
844 iattr.ia_valid |= ATTR_MTIME;
846 if (mask & SETATTR_ATIME) {
847 iattr.ia_atime = stbuf->st_atime;
848 iattr.ia_valid |= ATTR_ATIME;
850 if (mask & SETATTR_UID) {
851 iattr.ia_uid = stbuf->st_uid;
852 iattr.ia_valid |= ATTR_UID;
854 if (mask & SETATTR_GID) {
855 iattr.ia_gid = stbuf->st_gid;
856 iattr.ia_valid |= ATTR_GID;
858 if (mask & SETATTR_LEN) {
859 iattr.ia_size = stbuf->st_size; /* FIXME signed expansion problem */
860 iattr.ia_valid |= ATTR_SIZE;
863 iattr.ia_valid |= ATTR_RAW;
865 RETURN(llu_setattr_raw(ino, &iattr));
868 #define EXT2_LINK_MAX 32000
870 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
872 struct inode *dir = pno->p_base->pb_parent->pb_ino;
873 struct qstr *qstr = &pno->p_base->pb_name;
874 const char *name = qstr->name;
876 struct ptlrpc_request *request = NULL;
877 struct llu_sb_info *sbi = llu_i2sbi(dir);
878 struct mdc_op_data op_data;
882 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
885 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
886 err = mdc_create(sbi->ll_mdc_exp, &op_data,
887 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
888 current->fsuid, current->fsgid, 0, &request);
889 ptlrpc_req_finished(request);
893 static int llu_readlink_internal(struct inode *inode,
894 struct ptlrpc_request **request,
897 struct llu_inode_info *lli = llu_i2info(inode);
898 struct llu_sb_info *sbi = llu_i2sbi(inode);
900 struct mds_body *body;
901 int rc, symlen = lli->lli_st_size + 1;
906 if (lli->lli_symlink_name) {
907 *symname = lli->lli_symlink_name;
908 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
912 ll_inode2fid(&fid, inode);
913 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
914 OBD_MD_LINKNAME, symlen, request);
916 CERROR("inode %lu: rc = %d\n", lli->lli_st_ino, rc);
920 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
921 LASSERT (body != NULL);
922 LASSERT_REPSWABBED (*request, 0);
924 if ((body->valid & OBD_MD_LINKNAME) == 0) {
925 CERROR ("OBD_MD_LINKNAME not set on reply\n");
926 GOTO (failed, rc = -EPROTO);
929 LASSERT (symlen != 0);
930 if (body->eadatasize != symlen) {
931 CERROR ("inode %lu: symlink length %d not expected %d\n",
932 lli->lli_st_ino, body->eadatasize - 1, symlen - 1);
933 GOTO (failed, rc = -EPROTO);
936 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
937 if (*symname == NULL ||
938 strnlen (*symname, symlen) != symlen - 1) {
939 /* not full/NULL terminated */
940 CERROR ("inode %lu: symlink not NULL terminated string"
941 "of length %d\n", lli->lli_st_ino, symlen - 1);
942 GOTO (failed, rc = -EPROTO);
945 OBD_ALLOC(lli->lli_symlink_name, symlen);
946 /* do not return an error if we cannot cache the symlink locally */
947 if (lli->lli_symlink_name)
948 memcpy(lli->lli_symlink_name, *symname, symlen);
953 ptlrpc_req_finished (*request);
957 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
959 struct inode *inode = pno->p_base->pb_ino;
960 struct ptlrpc_request *request;
965 /* on symlinks lli_open_sem protects lli_symlink_name allocation/data */
967 down(&lli->lli_open_sem);
969 rc = llu_readlink_internal(inode, &request, &symname);
974 strncpy(data, symname, bufsize);
976 ptlrpc_req_finished(request);
979 up(&lli->lli_open_sem);
984 static int llu_iop_mknod_raw(struct pnode *pno,
988 struct ptlrpc_request *request = NULL;
989 struct inode *dir = pno->p_parent->p_base->pb_ino;
990 struct llu_sb_info *sbi = llu_i2sbi(dir);
991 struct mdc_op_data op_data;
995 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu\n",
996 pno->p_base->pb_name.name, llu_i2info(dir)->lli_st_ino);
998 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
1001 mode &= ~current->fs->umask;
1003 switch (mode & S_IFMT) {
1006 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
1011 llu_prepare_mdc_op_data(&op_data, dir, NULL,
1012 pno->p_base->pb_name.name,
1013 pno->p_base->pb_name.len,
1015 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
1016 current->fsuid, current->fsgid, dev, &request);
1017 ptlrpc_req_finished(request);
1029 static int llu_mdc_unlink(struct inode *dir, struct inode *child, __u32 mode,
1030 const char *name, int len)
1032 struct ptlrpc_request *request = NULL;
1033 struct mds_body *body;
1034 struct lov_mds_md *eadata;
1035 struct lov_stripe_md *lsm = NULL;
1036 struct obd_trans_info oti = { 0 };
1037 struct mdc_op_data op_data;
1042 llu_prepare_mdc_op_data(&op_data, dir, child, name, len, mode);
1043 rc = mdc_unlink(&llu_i2sbi(dir)->ll_mdc_conn, &op_data, &request);
1046 /* req is swabbed so this is safe */
1047 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
1049 if (!(body->valid & OBD_MD_FLEASIZE))
1052 if (body->eadatasize == 0) {
1053 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
1054 GOTO(out, rc = -EPROTO);
1057 /* The MDS sent back the EA because we unlinked the last reference
1058 * to this file. Use this EA to unlink the objects on the OST.
1059 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
1060 * check it is complete and sensible. */
1061 eadata = lustre_swab_repbuf(request, 1, body->eadatasize, NULL);
1062 LASSERT(eadata != NULL);
1063 if (eadata == NULL) {
1064 CERROR("Can't unpack MDS EA data\n");
1065 GOTO(out, rc = -EPROTO);
1068 rc = obd_unpackmd(llu_i2obdconn(dir), &lsm, eadata, body->eadatasize);
1070 CERROR("obd_unpackmd: %d\n", rc);
1073 LASSERT(rc >= sizeof(*lsm));
1077 GOTO(out_free_memmd, rc = -ENOMEM);
1079 oa->o_id = lsm->lsm_object_id;
1080 oa->o_mode = body->mode & S_IFMT;
1081 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
1083 if (body->valid & OBD_MD_FLCOOKIE) {
1084 oa->o_valid |= OBD_MD_FLCOOKIE;
1085 oti.oti_logcookies = lustre_msg_buf(request->rq_repmsg, 3,
1089 rc = obd_destroy(llu_i2obdconn(dir), oa, lsm, &oti);
1092 CERROR("obd destroy objid 0x"LPX64" error %d\n",
1093 lsm->lsm_object_id, rc);
1095 obd_free_memmd(llu_i2obdconn(dir), &lsm);
1097 ptlrpc_req_finished(request);
1102 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
1104 struct inode *src = old->p_base->pb_ino;
1105 struct inode *dir = new->p_parent->p_base->pb_ino;
1106 const char *name = new->p_base->pb_name.name;
1107 int namelen = new->p_base->pb_name.len;
1108 struct ptlrpc_request *request = NULL;
1109 struct mdc_op_data op_data;
1116 llu_prepare_mdc_op_data(&op_data, src, dir, name, namelen, 0);
1117 rc = mdc_link(llu_i2sbi(src)->ll_mdc_exp, &op_data, &request);
1118 ptlrpc_req_finished(request);
1123 static int llu_iop_unlink_raw(struct pnode *pno)
1125 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1126 struct qstr *qstr = &pno->p_base->pb_name;
1127 const char *name = qstr->name;
1128 int len = qstr->len;
1129 struct inode *target = pno->p_base->pb_ino;
1130 struct ptlrpc_request *request = NULL;
1131 struct mdc_op_data op_data;
1137 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1138 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1140 rc = llu_objects_destroy(request, dir);
1142 llu_i2info(target)->lli_stale_flag = 1;
1143 unhook_stale_inode(pno);
1146 ptlrpc_req_finished(request);
1151 * following cases need to be considered later:
1152 * - rename an opened file/dir
1153 * - an opened file be removed in rename
1154 * - rename to remove and hardlink (?opened)
1156 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
1158 struct inode *src = old->p_parent->p_base->pb_ino;
1159 struct inode *tgt = new->p_parent->p_base->pb_ino;
1160 struct inode *tgtinode = new->p_base->pb_ino;
1161 const char *oldname = old->p_base->pb_name.name;
1162 int oldnamelen = old->p_base->pb_name.len;
1163 const char *newname = new->p_base->pb_name.name;
1164 int newnamelen = new->p_base->pb_name.len;
1165 struct ptlrpc_request *request = NULL;
1166 struct mdc_op_data op_data;
1173 llu_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0);
1174 rc = mdc_rename(llu_i2sbi(src)->ll_mdc_exp, &op_data,
1175 oldname, oldnamelen, newname, newnamelen,
1178 rc = llu_objects_destroy(request, src);
1181 llu_i2info(tgtinode)->lli_stale_flag = 1;
1182 unhook_stale_inode(new);
1186 ptlrpc_req_finished(request);
1192 static int llu_statfs_internal(struct llu_sb_info *sbi,
1193 struct obd_statfs *osfs,
1194 unsigned long max_age)
1196 struct obd_statfs obd_osfs;
1200 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1202 CERROR("mdc_statfs fails: rc = %d\n", rc);
1206 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1207 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1209 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1211 CERROR("obd_statfs fails: rc = %d\n", rc);
1215 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1216 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1219 osfs->os_blocks = obd_osfs.os_blocks;
1220 osfs->os_bfree = obd_osfs.os_bfree;
1221 osfs->os_bavail = obd_osfs.os_bavail;
1223 /* If we don't have as many objects free on the OST as inodes
1224 * on the MDS, we reduce the total number of inodes to
1225 * compensate, so that the "inodes in use" number is correct.
1227 if (obd_osfs.os_ffree < osfs->os_ffree) {
1228 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1230 osfs->os_ffree = obd_osfs.os_ffree;
1236 static int llu_statfs(struct llu_sb_info *sbi, struct kstatfs *sfs)
1238 struct obd_statfs osfs;
1241 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1243 /* For now we will always get up-to-date statfs values, but in the
1244 * future we may allow some amount of caching on the client (e.g.
1245 * from QOS or lprocfs updates). */
1246 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1250 statfs_unpack(sfs, &osfs);
1252 if (sizeof(sfs->f_blocks) == 4) {
1253 while (osfs.os_blocks > ~0UL) {
1256 osfs.os_blocks >>= 1;
1257 osfs.os_bfree >>= 1;
1258 osfs.os_bavail >>= 1;
1262 sfs->f_blocks = osfs.os_blocks;
1263 sfs->f_bfree = osfs.os_bfree;
1264 sfs->f_bavail = osfs.os_bavail;
1269 static int llu_iop_statvfs(struct pnode *pno,
1271 struct intnl_statvfs *buf)
1278 LASSERT(pno->p_base->pb_ino);
1279 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1283 /* from native driver */
1284 buf->f_bsize = fs.f_bsize; /* file system block size */
1285 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1286 buf->f_blocks = fs.f_blocks;
1287 buf->f_bfree = fs.f_bfree;
1288 buf->f_bavail = fs.f_bavail;
1289 buf->f_files = fs.f_files; /* Total number serial numbers */
1290 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1291 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1292 buf->f_fsid = fs.f_fsid.__val[1];
1293 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1294 buf->f_namemax = fs.f_namelen;
1301 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1303 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1304 struct qstr *qstr = &pno->p_base->pb_name;
1305 const char *name = qstr->name;
1306 int len = qstr->len;
1307 struct ptlrpc_request *request = NULL;
1308 struct llu_inode_info *lli = llu_i2info(dir);
1309 struct mdc_op_data op_data;
1312 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1313 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1315 if (lli->lli_st_nlink >= EXT2_LINK_MAX)
1318 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
1319 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1320 err = mdc_create(llu_i2sbi(dir)->ll_mdc_exp, &op_data, NULL, 0, mode,
1321 current->fsuid, current->fsgid, 0, &request);
1322 ptlrpc_req_finished(request);
1326 static int llu_iop_rmdir_raw(struct pnode *pno)
1328 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1329 struct qstr *qstr = &pno->p_base->pb_name;
1330 const char *name = qstr->name;
1331 int len = qstr->len;
1332 struct ptlrpc_request *request = NULL;
1333 struct mdc_op_data op_data;
1334 struct llu_inode_info *lli = llu_i2info(dir);
1337 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1338 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1340 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, S_IFDIR);
1341 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1342 ptlrpc_req_finished(request);
1344 /* libsysio: remove the pnode right away */
1346 llu_i2info(pno->p_base->pb_ino)->lli_stale_flag = 1;
1347 unhook_stale_inode(pno);
1353 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap)
1355 CERROR("liblustre did not support fcntl\n");
1359 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1362 CERROR("liblustre did not support ioctl\n");
1367 * we already do syncronous read/write
1369 static int llu_iop_sync(struct inode *inode)
1374 static int llu_iop_datasync(struct inode *inode)
1379 struct filesys_ops llu_filesys_ops =
1381 fsop_gone: llu_fsop_gone,
1384 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1386 struct inode *inode;
1388 struct file_identifier fileid = {&fid, sizeof(fid)};
1390 if ((md->body->valid &
1391 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1392 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE))
1393 CERROR("invalide fields!\n");
1395 /* try to find existing inode */
1396 fid.id = md->body->ino;
1397 fid.generation = md->body->generation;
1398 fid.f_type = md->body->mode & S_IFMT;
1400 inode = _sysio_i_find(fs, &fileid);
1402 if (llu_i2info(inode)->lli_st_generation ==
1403 md->body->generation) {
1404 llu_update_inode(inode, md->body, md->lsm);
1410 inode = llu_new_inode(fs, &fid);
1412 llu_update_inode(inode, md->body, md->lsm);
1417 extern struct list_head lustre_profile_list;
1420 llu_fsswop_mount(const char *source,
1422 const void *data __IS_UNUSED,
1423 struct pnode *tocover,
1424 struct mount **mntp)
1428 struct pnode_base *rootpb;
1429 struct obd_device *obd;
1430 struct ll_fid rootfid;
1431 struct llu_sb_info *sbi;
1432 struct obd_statfs osfs;
1433 static struct qstr noname = { NULL, 0, 0 };
1434 struct ptlrpc_request *request = NULL;
1435 struct lustre_handle mdc_conn = {0, };
1436 struct lustre_handle osc_conn = {0, };
1437 struct lustre_md md;
1439 struct lustre_profile *lprof;
1440 char *osc = NULL, *mdc = NULL;
1445 /* allocate & initialize sbi */
1446 OBD_ALLOC(sbi, sizeof(*sbi));
1450 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1451 generate_random_uuid(uuid);
1452 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1456 struct config_llog_instance cfg;
1459 if (!g_zconf_mdsname) {
1460 CERROR("no mds name\n");
1461 GOTO(out_free, err = -EINVAL);
1465 /* generate a string unique to this super, let's try
1466 the address of the super itself.*/
1467 len = (sizeof(sbi) * 2) + 1;
1468 OBD_ALLOC(sbi->ll_instance, len);
1469 if (sbi->ll_instance == NULL)
1470 GOTO(out_free, err = -ENOMEM);
1471 sprintf(sbi->ll_instance, "%p", sbi);
1473 cfg.cfg_instance = sbi->ll_instance;
1474 cfg.cfg_uuid = sbi->ll_sb_uuid;
1475 err = liblustre_process_log(&cfg);
1477 CERROR("Unable to process log: %s\n", g_zconf_profile);
1479 GOTO(out_free, err);
1482 lprof = class_get_profile(g_zconf_profile);
1483 if (lprof == NULL) {
1484 CERROR("No profile found: %s\n", g_zconf_profile);
1485 GOTO(out_free, err = -EINVAL);
1488 OBD_FREE(osc, strlen(osc) + 1);
1489 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
1490 strlen(sbi->ll_instance) + 2);
1491 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
1494 OBD_FREE(mdc, strlen(mdc) + 1);
1495 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
1496 strlen(sbi->ll_instance) + 2);
1497 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
1499 /* setup from dump_file */
1500 if (list_empty(&lustre_profile_list)) {
1501 CERROR("no profile\n");
1502 GOTO(out_free, err = -EINVAL);
1505 lprof = list_entry(lustre_profile_list.next,
1506 struct lustre_profile, lp_list);
1507 osc = lprof->lp_osc;
1508 mdc = lprof->lp_mdc;
1513 GOTO(out_free, err = -EINVAL);
1517 GOTO(out_free, err = -EINVAL);
1520 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1526 obd = class_name2obd(mdc);
1528 CERROR("MDC %s: not setup or attached\n", mdc);
1529 GOTO(out_free, err = -EINVAL);
1532 if (mdc_init_ea_size(obd, osc))
1533 GOTO(out_free, err = -EINVAL);
1536 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
1538 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
1539 GOTO(out_free, err);
1541 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
1543 err = obd_statfs(obd, &osfs, 100000000);
1548 * FIXME fill fs stat data into sbi here!!! FIXME
1552 obd = class_name2obd(osc);
1554 CERROR("OSC %s: not setup or attached\n", osc);
1555 GOTO(out_mdc, err = -EINVAL);
1558 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
1560 CERROR("cannot connect to %s: rc = %d\n", osc, err);
1563 sbi->ll_osc_exp = class_conn2export(&osc_conn);
1565 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
1567 CERROR("cannot mds_connect: rc = %d\n", err);
1570 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
1571 sbi->ll_rootino = rootfid.id;
1573 /* fetch attr of root inode */
1574 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
1575 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
1577 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1581 err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
1583 CERROR("failed to understand root inode md: rc = %d\n",err);
1584 GOTO(out_request, err);
1587 LASSERT(sbi->ll_rootino != 0);
1589 root = llu_iget(fs, &md);
1591 CERROR("fail to generate root inode\n");
1592 GOTO(out_request, err = -EBADF);
1596 * Generate base path-node for root.
1598 rootpb = _sysio_pb_new(&noname, NULL, root);
1604 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1606 _sysio_pb_gone(rootpb);
1610 ptlrpc_req_finished(request);
1612 printf("LibLustre: namespace mounted successfully!\n");
1617 _sysio_i_gone(root);
1619 ptlrpc_req_finished(request);
1621 obd_disconnect(sbi->ll_osc_exp, 0);
1623 obd_disconnect(sbi->ll_mdc_exp, 0);
1625 OBD_FREE(sbi, sizeof(*sbi));
1629 struct fssw_ops llu_fssw_ops = {
1633 static struct inode_ops llu_inode_ops = {
1634 inop_lookup: llu_iop_lookup,
1635 inop_getattr: llu_iop_getattr,
1636 inop_setattr: llu_iop_setattr,
1637 inop_getdirentries: NULL,
1638 inop_mkdir: llu_iop_mkdir_raw,
1639 inop_rmdir: llu_iop_rmdir_raw,
1640 inop_symlink: llu_iop_symlink_raw,
1641 inop_readlink: llu_iop_readlink,
1642 inop_open: llu_iop_open,
1643 inop_close: llu_iop_close,
1644 inop_link: llu_iop_link_raw,
1645 inop_unlink: llu_iop_unlink_raw,
1646 inop_rename: llu_iop_rename_raw,
1647 inop_ipreadv: llu_iop_ipreadv,
1648 inop_ipwritev: llu_iop_ipwritev,
1649 inop_iodone: llu_iop_iodone,
1650 inop_fcntl: llu_iop_fcntl,
1651 inop_sync: llu_iop_sync,
1652 inop_datasync: llu_iop_datasync,
1653 inop_ioctl: llu_iop_ioctl,
1654 inop_mknod: llu_iop_mknod_raw,
1656 inop_statvfs: llu_iop_statvfs,
1658 inop_gone: llu_iop_gone,