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-2004 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>
36 # include <sys/statvfs.h>
38 # include <sys/statfs.h>
48 #include "llite_lib.h"
56 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
58 static int ll_permission(struct inode *inode, int mask)
60 struct llu_inode_info *lli = llu_i2info(inode);
61 mode_t mode = lli->lli_st_mode;
63 if (current->fsuid == lli->lli_st_uid)
65 else if (in_group_p(lli->lli_st_gid))
68 if ((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask)
71 if ((mask & (MAY_READ|MAY_WRITE)) ||
72 (lli->lli_st_mode & S_IXUGO))
73 if (capable(CAP_DAC_OVERRIDE))
76 if (mask == MAY_READ ||
77 (S_ISDIR(lli->lli_st_mode) && !(mask & MAY_WRITE))) {
78 if (capable(CAP_DAC_READ_SEARCH))
85 static void llu_fsop_gone(struct filesys *fs)
87 struct llu_sb_info *sbi = (struct llu_sb_info *) fs->fs_private;
88 struct obd_device *obd = class_exp2obd(sbi->ll_md_exp);
89 struct lustre_cfg lcfg;
93 list_del(&sbi->ll_conn_chain);
94 obd_disconnect(sbi->ll_dt_exp, 0);
95 obd_disconnect(sbi->ll_md_exp, 0);
97 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL)
101 LCFG_INIT(lcfg, LCFG_CLEANUP, obd->obd_name);
102 err = class_process_config(&lcfg);
104 CERROR("cleanup failed: %s\n", obd->obd_name);
107 LCFG_INIT(lcfg, LCFG_DETACH, obd->obd_name);
108 err = class_process_config(&lcfg);
110 CERROR("detach failed: %s\n", obd->obd_name);
114 obd_disconnect(sbi->ll_md_exp, 0);
115 OBD_FREE(sbi, sizeof(*sbi));
119 struct inode_ops llu_inode_ops;
121 void llu_update_inode(struct inode *inode, struct mds_body *body,
122 struct lov_stripe_md *lsm)
124 struct llu_inode_info *lli = llu_i2info(inode);
126 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
128 if (lli->lli_smd == NULL) {
130 lli->lli_maxbytes = lsm->lsm_maxbytes;
131 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
132 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
134 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
135 CERROR("lsm mismatch for inode %ld\n",
142 id_assign_fid(&lli->lli_id, &body->id1);
144 if ((body->valid & OBD_MD_FLID) || (body->valid & OBD_MD_FLGENER))
145 id_assign_stc(&lli->lli_id, &body->id1);
146 if (body->valid & OBD_MD_FLID)
147 lli->lli_st_ino = id_ino(&body->id1);
148 if (body->valid & OBD_MD_FLGENER)
149 lli->lli_st_generation = id_gen(&body->id1);
151 if (body->valid & OBD_MD_FLATIME)
152 LTIME_S(lli->lli_st_atime) = body->atime;
153 if (body->valid & OBD_MD_FLMTIME)
154 LTIME_S(lli->lli_st_mtime) = body->mtime;
155 if (body->valid & OBD_MD_FLCTIME)
156 LTIME_S(lli->lli_st_ctime) = body->ctime;
157 if (body->valid & OBD_MD_FLMODE)
158 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT)|(body->mode & ~S_IFMT);
159 if (body->valid & OBD_MD_FLTYPE)
160 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT)|(body->mode & S_IFMT);
161 if (body->valid & OBD_MD_FLUID)
162 lli->lli_st_uid = body->uid;
163 if (body->valid & OBD_MD_FLGID)
164 lli->lli_st_gid = body->gid;
165 if (body->valid & OBD_MD_FLFLAGS)
166 lli->lli_st_flags = body->flags;
167 if (body->valid & OBD_MD_FLNLINK)
168 lli->lli_st_nlink = body->nlink;
169 if (body->valid & OBD_MD_FLRDEV)
170 lli->lli_st_rdev = body->rdev;
171 if (body->valid & OBD_MD_FLSIZE)
172 lli->lli_st_size = body->size;
173 if (body->valid & OBD_MD_FLBLOCKS)
174 lli->lli_st_blocks = body->blocks;
177 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid)
179 struct llu_inode_info *lli = llu_i2info(dst);
181 valid &= src->o_valid;
183 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
184 CDEBUG(D_INODE, "valid %llx, cur time %lu/%lu, new %lu/%lu\n",
185 (unsigned long long)src->o_valid,
186 LTIME_S(lli->lli_st_mtime), LTIME_S(lli->lli_st_ctime),
187 (long)src->o_mtime, (long)src->o_ctime);
189 if (valid & OBD_MD_FLATIME)
190 LTIME_S(lli->lli_st_atime) = src->o_atime;
191 if (valid & OBD_MD_FLMTIME)
192 LTIME_S(lli->lli_st_mtime) = src->o_mtime;
193 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(lli->lli_st_ctime))
194 LTIME_S(lli->lli_st_ctime) = src->o_ctime;
195 if (valid & OBD_MD_FLSIZE)
196 lli->lli_st_size = src->o_size;
197 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
198 lli->lli_st_blocks = src->o_blocks;
199 if (valid & OBD_MD_FLBLKSZ)
200 lli->lli_st_blksize = src->o_blksize;
201 if (valid & OBD_MD_FLTYPE)
202 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
203 if (valid & OBD_MD_FLMODE)
204 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
205 if (valid & OBD_MD_FLUID)
206 lli->lli_st_uid = src->o_uid;
207 if (valid & OBD_MD_FLGID)
208 lli->lli_st_gid = src->o_gid;
209 if (valid & OBD_MD_FLFLAGS)
210 lli->lli_st_flags = src->o_flags;
211 if (valid & OBD_MD_FLGENER)
212 lli->lli_st_generation = src->o_generation;
215 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
216 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
218 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid)
220 struct llu_inode_info *lli = llu_i2info(src);
221 obd_valid newvalid = 0;
223 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
224 CDEBUG(D_INODE, "valid %llx, new time %lu/%lu\n",
225 (unsigned long long)valid, LTIME_S(lli->lli_st_mtime),
226 LTIME_S(lli->lli_st_ctime));
228 if (valid & OBD_MD_FLATIME) {
229 dst->o_atime = LTIME_S(lli->lli_st_atime);
230 newvalid |= OBD_MD_FLATIME;
232 if (valid & OBD_MD_FLMTIME) {
233 dst->o_mtime = LTIME_S(lli->lli_st_mtime);
234 newvalid |= OBD_MD_FLMTIME;
236 if (valid & OBD_MD_FLCTIME) {
237 dst->o_ctime = LTIME_S(lli->lli_st_ctime);
238 newvalid |= OBD_MD_FLCTIME;
240 if (valid & OBD_MD_FLSIZE) {
241 dst->o_size = lli->lli_st_size;
242 newvalid |= OBD_MD_FLSIZE;
244 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
245 dst->o_blocks = lli->lli_st_blocks;
246 newvalid |= OBD_MD_FLBLOCKS;
248 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
249 dst->o_blksize = lli->lli_st_blksize;
250 newvalid |= OBD_MD_FLBLKSZ;
252 if (valid & OBD_MD_FLTYPE) {
253 dst->o_mode = (dst->o_mode & S_IALLUGO)|(lli->lli_st_mode & S_IFMT);
254 newvalid |= OBD_MD_FLTYPE;
256 if (valid & OBD_MD_FLMODE) {
257 dst->o_mode = (dst->o_mode & S_IFMT)|(lli->lli_st_mode & S_IALLUGO);
258 newvalid |= OBD_MD_FLMODE;
260 if (valid & OBD_MD_FLUID) {
261 dst->o_uid = lli->lli_st_uid;
262 newvalid |= OBD_MD_FLUID;
264 if (valid & OBD_MD_FLGID) {
265 dst->o_gid = lli->lli_st_gid;
266 newvalid |= OBD_MD_FLGID;
268 if (valid & OBD_MD_FLFLAGS) {
269 dst->o_flags = lli->lli_st_flags;
270 newvalid |= OBD_MD_FLFLAGS;
272 if (valid & OBD_MD_FLGENER) {
273 dst->o_generation = lli->lli_st_generation;
274 newvalid |= OBD_MD_FLGENER;
277 dst->o_valid |= newvalid;
281 * really does the getattr on the inode and updates its fields
283 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
285 struct llu_inode_info *lli = llu_i2info(inode);
286 struct obd_export *exp = llu_i2dtexp(inode);
287 struct ptlrpc_request_set *set;
289 obd_valid refresh_valid;
296 memset(&oa, 0, sizeof oa);
297 oa.o_id = lsm->lsm_object_id;
299 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
300 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
303 set = ptlrpc_prep_set();
305 CERROR ("ENOMEM allocing request set\n");
308 rc = obd_getattr_async(exp, &oa, lsm, set);
310 rc = ptlrpc_set_wait(set);
311 ptlrpc_set_destroy(set);
316 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
317 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
319 /* We set this flag in commit write as we extend the file size. When
320 * the bit is set and the lock is canceled that covers the file size,
321 * we clear the bit. This is enough to protect the window where our
322 * local size extension is needed for writeback. However, it relies on
323 * behaviour that won't be true in the near future. This assumes that
324 * all getattr callers get extent locks, which they currnetly do. It
325 * also assumes that we only send discarding asts for {0,eof} truncates
326 * as is currently the case. This will have to be replaced by the
327 * proper eoc communication between clients and the ost, which is on
329 if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
330 if (oa.o_size < lli->lli_st_size)
331 refresh_valid &= ~OBD_MD_FLSIZE;
333 clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
336 obdo_refresh_inode(inode, &oa, refresh_valid);
341 static struct inode* llu_new_inode(struct filesys *fs,
342 struct lustre_id *id)
345 struct llu_inode_info *lli;
347 OBD_ALLOC(lli, sizeof(*lli));
351 /* initialize lli here */
352 lli->lli_sbi = llu_fs2sbi(fs);
354 lli->lli_symlink_name = NULL;
356 lli->lli_maxbytes = (__u64)(~0UL);
357 lli->lli_file_data = NULL;
359 lli->lli_sysio_fid.fid_data = &lli->lli_id;
360 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_id);
362 memcpy(&lli->lli_id, id, sizeof(*id));
364 /* file identifier is needed by functions like _sysio_i_find() */
365 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
366 #ifndef AUTOMOUNT_FILE_NAME
367 id->li_stc.u.e3s.l3s_type & S_IFMT,
369 id->li_stc.u.e3s.l3s_type, /* all of the bits! */
372 &llu_inode_ops, lli);
375 OBD_FREE(lli, sizeof(*lli));
380 static int llu_have_md_lock(struct inode *inode, __u64 lockpart)
382 struct llu_sb_info *sbi = llu_i2sbi(inode);
383 struct llu_inode_info *lli = llu_i2info(inode);
384 struct lustre_handle lockh;
385 struct ldlm_res_id res_id = { .name = {0} };
386 struct obd_device *obddev;
387 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
393 obddev = sbi->ll_md_exp->exp_obd;
394 res_id.name[0] = id_fid(&lli->lli_id);
395 res_id.name[1] = id_group(&lli->lli_id);
397 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
399 /* FIXME use LDLM_FL_TEST_LOCK instead */
400 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
401 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
402 &policy, LCK_PR, &lockh)) {
403 ldlm_lock_decref(&lockh, LCK_PR);
407 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
408 &policy, LCK_PW, &lockh)) {
409 ldlm_lock_decref(&lockh, LCK_PW);
415 static int llu_inode_revalidate(struct inode *inode)
417 struct llu_inode_info *lli = llu_i2info(inode);
418 struct lov_stripe_md *lsm = NULL;
422 CERROR("REPORT THIS LINE TO PETER\n");
426 if (!llu_have_md_lock(inode, MDS_INODELOCK_UPDATE)) {
428 struct ptlrpc_request *req = NULL;
429 struct llu_sb_info *sbi = llu_i2sbi(inode);
434 /* Why don't we update all valid MDS fields here, if we're doing
435 * an RPC anyways? -phil */
436 if (S_ISREG(lli->lli_st_mode)) {
437 ealen = obd_size_diskmd(sbi->ll_dt_exp, NULL);
438 valid |= OBD_MD_FLEASIZE;
440 ll_inode2id(&id, inode);
441 rc = mdc_getattr(sbi->ll_md_exp, &id, valid, NULL, 0,
444 CERROR("failure %d inode %lu\n", rc, lli->lli_st_ino);
447 rc = mdc_req2lustre_md(sbi->ll_md_exp, req, 0,
448 sbi->ll_dt_exp, &md);
450 /* XXX Too paranoid? */
451 if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) &&
452 !((md.body->valid & OBD_MD_FLNLINK) &&
453 (md.body->nlink == 0))) {
454 CERROR("Asked for %s eadata but got %s (%d)\n",
455 (valid & OBD_MD_FLEASIZE) ? "some" : "no",
456 (md.body->valid & OBD_MD_FLEASIZE) ? "some":"none",
457 md.body->eadatasize);
460 ptlrpc_req_finished(req);
465 llu_update_inode(inode, md.body, md.lsm);
466 if (md.lsm != NULL && llu_i2info(inode)->lli_smd != md.lsm)
467 obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
469 if (md.body->valid & OBD_MD_FLSIZE)
470 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
471 &llu_i2info(inode)->lli_flags);
472 ptlrpc_req_finished(req);
475 lsm = llu_i2info(inode)->lli_smd;
476 if (!lsm) /* object not yet allocated, don't validate size */
479 /* ll_glimpse_size will prefer locally cached writes if they extend
481 RETURN(llu_glimpse_size(inode));
484 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
486 struct llu_inode_info *lli = llu_i2info(ino);
488 b->st_dev = lli->lli_st_dev;
489 b->st_ino = lli->lli_st_ino;
490 b->st_mode = lli->lli_st_mode;
491 b->st_nlink = lli->lli_st_nlink;
492 b->st_uid = lli->lli_st_uid;
493 b->st_gid = lli->lli_st_gid;
494 b->st_rdev = lli->lli_st_rdev;
495 b->st_size = lli->lli_st_size;
496 b->st_blksize = lli->lli_st_blksize;
497 b->st_blocks = lli->lli_st_blocks;
498 b->st_atime = lli->lli_st_atime;
499 b->st_mtime = lli->lli_st_mtime;
500 b->st_ctime = lli->lli_st_ctime;
503 static int llu_iop_getattr(struct pnode *pno,
505 struct intnl_stat *b)
510 liblustre_wait_event(0);
514 LASSERT(pno->p_base->pb_ino);
515 ino = pno->p_base->pb_ino;
517 LASSERT(!pno || pno->p_base->pb_ino == ino);
520 /* libsysio might call us directly without intent lock,
521 * we must re-fetch the attrs here
523 rc = llu_inode_revalidate(ino);
525 copy_stat_buf(ino, b);
526 LASSERT(!llu_i2info(ino)->lli_it);
532 static int null_if_equal(struct ldlm_lock *lock, void *data)
534 if (data == lock->l_ast_data) {
535 lock->l_ast_data = NULL;
537 if (lock->l_req_mode != lock->l_granted_mode)
538 LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
541 return LDLM_ITER_CONTINUE;
544 void llu_clear_inode(struct inode *inode)
547 struct llu_inode_info *lli = llu_i2info(inode);
548 struct llu_sb_info *sbi = llu_i2sbi(inode);
551 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu(%p)\n", lli->lli_st_ino,
552 lli->lli_st_generation, inode);
554 ll_inode2id(&id, inode);
555 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
556 mdc_change_cbdata(sbi->ll_md_exp, &id, null_if_equal, inode);
559 obd_change_cbdata(sbi->ll_dt_exp, lli->lli_smd,
560 null_if_equal, inode);
563 obd_free_memmd(sbi->ll_dt_exp, &lli->lli_smd);
567 if (lli->lli_symlink_name) {
568 OBD_FREE(lli->lli_symlink_name,
569 strlen(lli->lli_symlink_name) + 1);
570 lli->lli_symlink_name = NULL;
576 void llu_iop_gone(struct inode *inode)
578 struct llu_inode_info *lli = llu_i2info(inode);
581 liblustre_wait_event(0);
582 llu_clear_inode(inode);
584 OBD_FREE(lli, sizeof(*lli));
588 static int inode_setattr(struct inode * inode, struct iattr * attr)
590 unsigned int ia_valid = attr->ia_valid;
591 struct llu_inode_info *lli = llu_i2info(inode);
594 if (ia_valid & ATTR_SIZE) {
595 error = llu_vmtruncate(inode, attr->ia_size);
600 if (ia_valid & ATTR_UID)
601 lli->lli_st_uid = attr->ia_uid;
602 if (ia_valid & ATTR_GID)
603 lli->lli_st_gid = attr->ia_gid;
604 if (ia_valid & ATTR_ATIME)
605 lli->lli_st_atime = attr->ia_atime;
606 if (ia_valid & ATTR_MTIME)
607 lli->lli_st_mtime = attr->ia_mtime;
608 if (ia_valid & ATTR_CTIME)
609 lli->lli_st_ctime = attr->ia_ctime;
610 if (ia_valid & ATTR_MODE) {
611 lli->lli_st_mode = attr->ia_mode;
612 if (!in_group_p(lli->lli_st_gid) && !capable(CAP_FSETID))
613 lli->lli_st_mode &= ~S_ISGID;
615 /* mark_inode_dirty(inode); */
620 /* If this inode has objects allocated to it (lsm != NULL), then the OST
621 * object(s) determine the file size and mtime. Otherwise, the MDS will
622 * keep these values until such a time that objects are allocated for it.
623 * We do the MDS operations first, as it is checking permissions for us.
624 * We don't to the MDS RPC if there is nothing that we want to store there,
625 * otherwise there is no harm in updating mtime/atime on the MDS if we are
626 * going to do an RPC anyways.
628 * If we are doing a truncate, we will send the mtime and ctime updates
629 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
630 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
633 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
635 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
636 struct llu_sb_info *sbi = llu_i2sbi(inode);
637 struct llu_inode_info *lli = llu_i2info(inode);
638 struct ptlrpc_request *request = NULL;
639 struct mdc_op_data op_data;
640 int ia_valid = attr->ia_valid;
644 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
646 if (ia_valid & ATTR_SIZE) {
647 if (attr->ia_size > ll_file_maxbytes(inode)) {
648 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
649 attr->ia_size, ll_file_maxbytes(inode));
653 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
656 /* We mark all of the fields "set" so MDS/OST does not re-set them */
657 if (attr->ia_valid & ATTR_CTIME) {
658 attr->ia_ctime = CURRENT_TIME;
659 attr->ia_valid |= ATTR_CTIME_SET;
661 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
662 attr->ia_atime = CURRENT_TIME;
663 attr->ia_valid |= ATTR_ATIME_SET;
665 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
666 attr->ia_mtime = CURRENT_TIME;
667 attr->ia_valid |= ATTR_MTIME_SET;
670 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
671 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
672 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
673 LTIME_S(CURRENT_TIME));
675 attr->ia_valid &= ~ATTR_SIZE;
677 /* If only OST attributes being set on objects, don't do MDS RPC.
678 * In that case, we need to check permissions and update the local
679 * inode ourselves so we can call obdo_from_inode() always. */
680 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
682 llu_prepare_mdc_data(&op_data, inode, NULL, NULL, 0, 0);
684 rc = mdc_setattr(sbi->ll_md_exp, &op_data,
685 attr, NULL, 0, NULL, 0, &request);
688 ptlrpc_req_finished(request);
689 if (rc != -EPERM && rc != -EACCES)
690 CERROR("mdc_setattr fails: rc = %d\n", rc);
694 rc = mdc_req2lustre_md(sbi->ll_md_exp, request, 0,
695 sbi->ll_dt_exp, &md);
697 ptlrpc_req_finished(request);
701 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
702 * but needed to set timestamps backwards on utime. */
703 inode_setattr(inode, attr);
704 llu_update_inode(inode, md.body, md.lsm);
705 ptlrpc_req_finished(request);
707 if (!md.lsm || !S_ISREG(lli->lli_st_mode)) {
708 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
712 /* The OST doesn't check permissions, but the alternative is
713 * a gratuitous RPC to the MDS. We already rely on the client
714 * to do read/write/truncate permission checks, so is mtime OK?
716 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
717 /* from sys_utime() */
718 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
719 if (current->fsuid != lli->lli_st_uid &&
720 (rc = ll_permission(inode, MAY_WRITE)) != 0)
723 /* from inode_change_ok() */
724 if (current->fsuid != lli->lli_st_uid &&
725 !capable(CAP_FOWNER))
730 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
731 inode_setattr(inode, attr);
734 if (ia_valid & ATTR_SIZE) {
735 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
737 struct lustre_handle lockh = { 0 };
738 int err, ast_flags = 0;
739 /* XXX when we fix the AST intents to pass the discard-range
740 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
742 if (attr->ia_size == 0)
743 ast_flags = LDLM_AST_DISCARD_DATA;
745 rc = llu_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
747 if (rc != ELDLM_OK) {
753 rc = llu_vmtruncate(inode, attr->ia_size);
755 /* unlock now as we don't mind others file lockers racing with
756 * the mds updates below? */
757 err = llu_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
759 CERROR("llu_extent_unlock failed: %d\n", err);
763 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
766 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
767 lli->lli_st_ino, LTIME_S(attr->ia_mtime));
768 oa.o_id = lsm->lsm_object_id;
769 oa.o_valid = OBD_MD_FLID;
770 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
771 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
772 rc = obd_setattr(sbi->ll_dt_exp, &oa, lsm, NULL);
774 CERROR("obd_setattr fails: rc=%d\n", rc);
779 /* here we simply act as a thin layer to glue it with
780 * llu_setattr_raw(), which is copy from kernel
782 static int llu_iop_setattr(struct pnode *pno,
785 struct intnl_stat *stbuf)
790 liblustre_wait_event(0);
792 LASSERT(!(mask & ~(SETATTR_MTIME | SETATTR_ATIME |
793 SETATTR_UID | SETATTR_GID |
794 SETATTR_LEN | SETATTR_MODE)));
795 memset(&iattr, 0, sizeof(iattr));
797 if (mask & SETATTR_MODE) {
798 iattr.ia_mode = stbuf->st_mode;
799 iattr.ia_valid |= ATTR_MODE;
801 if (mask & SETATTR_MTIME) {
802 iattr.ia_mtime = stbuf->st_mtime;
803 iattr.ia_valid |= ATTR_MTIME;
805 if (mask & SETATTR_ATIME) {
806 iattr.ia_atime = stbuf->st_atime;
807 iattr.ia_valid |= ATTR_ATIME;
809 if (mask & SETATTR_UID) {
810 iattr.ia_uid = stbuf->st_uid;
811 iattr.ia_valid |= ATTR_UID;
813 if (mask & SETATTR_GID) {
814 iattr.ia_gid = stbuf->st_gid;
815 iattr.ia_valid |= ATTR_GID;
817 if (mask & SETATTR_LEN) {
818 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
819 iattr.ia_valid |= ATTR_SIZE;
822 iattr.ia_valid |= ATTR_RAW;
824 RETURN(llu_setattr_raw(ino, &iattr));
827 #define EXT2_LINK_MAX 32000
829 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
831 struct inode *dir = pno->p_base->pb_parent->pb_ino;
832 struct qstr *qstr = &pno->p_base->pb_name;
833 const char *name = qstr->name;
835 struct ptlrpc_request *request = NULL;
836 struct llu_sb_info *sbi = llu_i2sbi(dir);
837 struct mdc_op_data op_data;
841 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
844 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, 0);
845 err = mdc_create(sbi->ll_md_exp, &op_data,
846 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
847 current->fsuid, current->fsgid, 0, &request);
848 ptlrpc_req_finished(request);
852 static int llu_readlink_internal(struct inode *inode,
853 struct ptlrpc_request **request,
856 struct llu_inode_info *lli = llu_i2info(inode);
857 struct llu_sb_info *sbi = llu_i2sbi(inode);
859 struct mds_body *body;
860 int rc, symlen = lli->lli_st_size + 1;
865 if (lli->lli_symlink_name) {
866 *symname = lli->lli_symlink_name;
867 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
871 ll_inode2id(&id, inode);
872 rc = mdc_getattr(sbi->ll_md_exp, &id,
873 OBD_MD_LINKNAME, NULL, 0, symlen, request);
875 CERROR("inode %lu: rc = %d\n", lli->lli_st_ino, rc);
879 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
880 LASSERT (body != NULL);
881 LASSERT_REPSWABBED (*request, 0);
883 if ((body->valid & OBD_MD_LINKNAME) == 0) {
884 CERROR ("OBD_MD_LINKNAME not set on reply\n");
885 GOTO (failed, rc = -EPROTO);
888 LASSERT (symlen != 0);
889 if (body->eadatasize != symlen) {
890 CERROR ("inode %lu: symlink length %d not expected %d\n",
891 lli->lli_st_ino, body->eadatasize - 1, symlen - 1);
892 GOTO (failed, rc = -EPROTO);
895 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
896 if (*symname == NULL ||
897 strnlen (*symname, symlen) != symlen - 1) {
898 /* not full/NULL terminated */
899 CERROR ("inode %lu: symlink not NULL terminated string"
900 "of length %d\n", lli->lli_st_ino, symlen - 1);
901 GOTO (failed, rc = -EPROTO);
904 OBD_ALLOC(lli->lli_symlink_name, symlen);
905 /* do not return an error if we cannot cache the symlink locally */
906 if (lli->lli_symlink_name)
907 memcpy(lli->lli_symlink_name, *symname, symlen);
912 ptlrpc_req_finished (*request);
916 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
918 struct inode *inode = pno->p_base->pb_ino;
919 struct ptlrpc_request *request;
924 rc = llu_readlink_internal(inode, &request, &symname);
929 strncpy(data, symname, bufsize);
931 ptlrpc_req_finished(request);
936 static int llu_iop_mknod_raw(struct pnode *pno,
940 struct ptlrpc_request *request = NULL;
941 struct inode *dir = pno->p_parent->p_base->pb_ino;
942 struct llu_sb_info *sbi = llu_i2sbi(dir);
943 struct mdc_op_data op_data;
947 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu\n",
948 pno->p_base->pb_name.name, llu_i2info(dir)->lli_st_ino);
950 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
953 mode &= ~current->fs->umask;
955 switch (mode & S_IFMT) {
958 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
963 llu_prepare_mdc_data(&op_data, dir, NULL,
964 pno->p_base->pb_name.name,
965 pno->p_base->pb_name.len,
967 err = mdc_create(sbi->ll_md_exp, &op_data, NULL, 0, mode,
968 current->fsuid, current->fsgid, dev, &request);
969 ptlrpc_req_finished(request);
980 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
982 struct inode *src = old->p_base->pb_ino;
983 struct inode *dir = new->p_parent->p_base->pb_ino;
984 const char *name = new->p_base->pb_name.name;
985 int namelen = new->p_base->pb_name.len;
986 struct ptlrpc_request *request = NULL;
987 struct mdc_op_data op_data;
994 liblustre_wait_event(0);
995 llu_prepare_mdc_data(&op_data, src, dir, name, namelen, 0);
996 rc = mdc_link(llu_i2sbi(src)->ll_md_exp, &op_data, &request);
997 ptlrpc_req_finished(request);
998 liblustre_wait_event(0);
1004 * libsysio will clear the inode immediately after return
1006 static int llu_iop_unlink_raw(struct pnode *pno)
1008 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1009 struct qstr *qstr = &pno->p_base->pb_name;
1010 const char *name = qstr->name;
1011 int len = qstr->len;
1012 struct inode *target = pno->p_base->pb_ino;
1013 struct ptlrpc_request *request = NULL;
1014 struct mdc_op_data op_data;
1020 liblustre_wait_event(0);
1021 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, 0);
1022 rc = mdc_unlink(llu_i2sbi(dir)->ll_md_exp, &op_data, &request);
1024 rc = llu_objects_destroy(request, dir);
1025 ptlrpc_req_finished(request);
1026 liblustre_wait_event(0);
1030 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
1032 struct inode *src = old->p_parent->p_base->pb_ino;
1033 struct inode *tgt = new->p_parent->p_base->pb_ino;
1034 const char *oldname = old->p_base->pb_name.name;
1035 int oldnamelen = old->p_base->pb_name.len;
1036 const char *newname = new->p_base->pb_name.name;
1037 int newnamelen = new->p_base->pb_name.len;
1038 struct ptlrpc_request *request = NULL;
1039 struct mdc_op_data op_data;
1046 llu_prepare_mdc_data(&op_data, src, tgt, NULL, 0, 0);
1047 rc = mdc_rename(llu_i2sbi(src)->ll_md_exp, &op_data,
1048 oldname, oldnamelen, newname, newnamelen,
1051 rc = llu_objects_destroy(request, src);
1054 ptlrpc_req_finished(request);
1059 #ifdef _HAVE_STATVFS
1060 static int llu_statfs_internal(struct llu_sb_info *sbi,
1061 struct obd_statfs *osfs,
1062 unsigned long max_age)
1064 struct obd_statfs obd_osfs;
1068 rc = obd_statfs(class_exp2obd(sbi->ll_md_exp), osfs, max_age);
1070 CERROR("mdc_statfs fails: rc = %d\n", rc);
1074 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1075 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1077 rc = obd_statfs(class_exp2obd(sbi->ll_dt_exp), &obd_osfs, max_age);
1079 CERROR("obd_statfs fails: rc = %d\n", rc);
1083 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1084 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1087 osfs->os_blocks = obd_osfs.os_blocks;
1088 osfs->os_bfree = obd_osfs.os_bfree;
1089 osfs->os_bavail = obd_osfs.os_bavail;
1091 /* If we don't have as many objects free on the OST as inodes
1092 * on the MDS, we reduce the total number of inodes to
1093 * compensate, so that the "inodes in use" number is correct.
1095 if (obd_osfs.os_ffree < osfs->os_ffree) {
1096 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1098 osfs->os_ffree = obd_osfs.os_ffree;
1104 static int llu_statfs(struct llu_sb_info *sbi, struct statfs *sfs)
1106 struct obd_statfs osfs;
1109 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1111 /* For now we will always get up-to-date statfs values, but in the
1112 * future we may allow some amount of caching on the client (e.g.
1113 * from QOS or lprocfs updates). */
1114 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1118 statfs_unpack(sfs, &osfs);
1120 if (sizeof(sfs->f_blocks) == 4) {
1121 while (osfs.os_blocks > ~0UL) {
1124 osfs.os_blocks >>= 1;
1125 osfs.os_bfree >>= 1;
1126 osfs.os_bavail >>= 1;
1130 sfs->f_blocks = osfs.os_blocks;
1131 sfs->f_bfree = osfs.os_bfree;
1132 sfs->f_bavail = osfs.os_bavail;
1137 static int llu_iop_statvfs(struct pnode *pno,
1139 struct intnl_statvfs *buf)
1145 liblustre_wait_event(0);
1148 LASSERT(pno->p_base->pb_ino);
1149 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1153 /* from native driver */
1154 buf->f_bsize = fs.f_bsize; /* file system block size */
1155 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1156 buf->f_blocks = fs.f_blocks;
1157 buf->f_bfree = fs.f_bfree;
1158 buf->f_bavail = fs.f_bavail;
1159 buf->f_files = fs.f_files; /* Total number serial numbers */
1160 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1161 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1162 buf->f_fsid = fs.f_fstc.__val[1];
1163 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1164 buf->f_namemax = fs.f_namelen;
1169 #endif /* _HAVE_STATVFS */
1171 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1173 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1174 struct qstr *qstr = &pno->p_base->pb_name;
1175 const char *name = qstr->name;
1176 int len = qstr->len;
1177 struct ptlrpc_request *request = NULL;
1178 struct llu_inode_info *lli = llu_i2info(dir);
1179 struct mdc_op_data op_data;
1182 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1183 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1185 if (lli->lli_st_nlink >= EXT2_LINK_MAX)
1188 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
1189 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, 0);
1190 err = mdc_create(llu_i2sbi(dir)->ll_md_exp, &op_data, NULL, 0, mode,
1191 current->fsuid, current->fsgid, 0, &request);
1192 ptlrpc_req_finished(request);
1196 static int llu_iop_rmdir_raw(struct pnode *pno)
1198 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1199 struct qstr *qstr = &pno->p_base->pb_name;
1200 const char *name = qstr->name;
1201 int len = qstr->len;
1202 struct ptlrpc_request *request = NULL;
1203 struct mdc_op_data op_data;
1204 struct llu_inode_info *lli = llu_i2info(dir);
1207 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1208 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1210 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, S_IFDIR);
1211 rc = mdc_unlink(llu_i2sbi(dir)->ll_md_exp, &op_data, &request);
1212 ptlrpc_req_finished(request);
1218 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC|O_DIRECT)
1220 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC)
1222 #define FCNTL_FLMASK_INVALID (O_NONBLOCK|O_ASYNC)
1224 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn)
1226 struct llu_inode_info *lli = llu_i2info(ino);
1231 *rtn = lli->lli_open_flags;
1234 flags = va_arg(ap, long);
1235 flags &= FCNTL_FLMASK;
1236 if (flags & FCNTL_FLMASK_INVALID) {
1237 CERROR("liblustre does not support O_NONBLOCK, O_ASYNC, "
1238 "and O_DIRECT on file descriptor\n");
1242 lli->lli_open_flags = (int) flags;
1247 CERROR("unsupported fcntl cmd %x\n", cmd);
1252 static int llu_get_grouplock(struct inode *inode, unsigned long arg)
1254 struct llu_inode_info *lli = llu_i2info(inode);
1255 struct ll_file_data *fd = lli->lli_file_data;
1256 ldlm_policy_data_t policy = { .l_extent = { .start = 0,
1257 .end = OBD_OBJECT_EOF}};
1258 struct lustre_handle lockh = { 0 };
1259 struct lov_stripe_md *lsm = lli->lli_smd;
1264 if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
1268 policy.l_extent.gid = arg;
1269 if (lli->lli_open_flags & O_NONBLOCK)
1270 flags = LDLM_FL_BLOCK_NOWAIT;
1272 err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
1277 fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
1279 memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
1284 static int llu_put_grouplock(struct inode *inode, unsigned long arg)
1286 struct llu_inode_info *lli = llu_i2info(inode);
1287 struct ll_file_data *fd = lli->lli_file_data;
1288 struct lov_stripe_md *lsm = lli->lli_smd;
1292 if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
1295 if (fd->fd_gid != arg)
1298 fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
1300 err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
1305 memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
1310 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1315 liblustre_wait_event(0);
1318 case LL_IOC_GROUP_LOCK:
1319 arg = va_arg(ap, unsigned long);
1320 return llu_get_grouplock(ino, arg);
1321 case LL_IOC_GROUP_UNLOCK:
1322 arg = va_arg(ap, unsigned long);
1323 return llu_put_grouplock(ino, arg);
1326 CERROR("did not support ioctl cmd %lx\n", request);
1331 * we already do syncronous read/write
1333 static int llu_iop_sync(struct inode *inode)
1335 liblustre_wait_event(0);
1339 static int llu_iop_datasync(struct inode *inode)
1341 liblustre_wait_event(0);
1345 struct filesys_ops llu_filesys_ops =
1347 fsop_gone: llu_fsop_gone,
1350 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1352 struct inode *inode;
1353 struct lustre_id id;
1354 struct file_identifier fileid = {&id, sizeof(id)};
1356 if ((md->body->valid &
1357 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1358 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) {
1359 CERROR("bad md body valid mask 0x%llx\n",
1360 (unsigned long long)md->body->valid);
1362 return ERR_PTR(-EPERM);
1367 /* try to find existing inode */
1368 inode = _sysio_i_find(fs, &fileid);
1370 struct llu_inode_info *lli = llu_i2info(inode);
1372 if (inode->i_zombie ||
1373 lli->lli_st_generation != id_gen(&md->body->id1)) {
1377 llu_update_inode(inode, md->body, md->lsm);
1382 inode = llu_new_inode(fs, &id);
1384 llu_update_inode(inode, md->body, md->lsm);
1390 llu_fsswop_mount(const char *source,
1392 const void *data __IS_UNUSED,
1393 struct pnode *tocover,
1394 struct mount **mntp)
1398 struct pnode_base *rootpb;
1399 struct obd_device *obd;
1400 struct lustre_id rootid;
1401 struct llu_sb_info *sbi;
1402 struct obd_statfs osfs;
1403 static struct qstr noname = { NULL, 0, 0 };
1404 struct ptlrpc_request *request = NULL;
1405 struct lustre_handle lmv_conn = {0, };
1406 struct lustre_handle lov_conn = {0, };
1407 struct lustre_md md;
1409 struct config_llog_instance cfg;
1410 struct lustre_profile *lprof;
1411 char *lov = NULL, *lmv = NULL;
1412 int async = 1, err = -EINVAL;
1416 /* allocate & initialize sbi */
1417 OBD_ALLOC(sbi, sizeof(*sbi));
1421 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1422 generate_random_uuid(uuid);
1423 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1425 /* generate a string unique to this super, let's try
1426 the address of the super itself.*/
1427 OBD_ALLOC(sbi->ll_instance, sizeof(sbi) * 2 + 1);
1428 if (sbi->ll_instance == NULL)
1429 GOTO(out_free, err = -ENOMEM);
1430 sprintf(sbi->ll_instance, "%p", sbi);
1432 /* retrive & parse config log */
1433 cfg.cfg_instance = sbi->ll_instance;
1434 cfg.cfg_uuid = sbi->ll_sb_uuid;
1435 err = liblustre_process_log(&cfg, 1);
1437 CERROR("Unable to process log: %s\n", g_zconf_profile);
1438 GOTO(out_free, err);
1441 lprof = class_get_profile(g_zconf_profile);
1442 if (lprof == NULL) {
1443 CERROR("No profile found: %s\n", g_zconf_profile);
1444 GOTO(out_free, err = -EINVAL);
1447 OBD_FREE(lov, strlen(lov) + 1);
1448 OBD_ALLOC(lov, strlen(lprof->lp_lov) +
1449 strlen(sbi->ll_instance) + 2);
1450 sprintf(lov, "%s-%s", lprof->lp_lov, sbi->ll_instance);
1453 OBD_FREE(lmv, strlen(lmv) + 1);
1454 OBD_ALLOC(lmv, strlen(lprof->lp_lmv) +
1455 strlen(sbi->ll_instance) + 2);
1456 sprintf(lmv, "%s-%s", lprof->lp_lmv, sbi->ll_instance);
1460 GOTO(out_free, err = -EINVAL);
1464 GOTO(out_free, err = -EINVAL);
1467 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1473 obd = class_name2obd(lmv);
1475 CERROR("MDC %s: not setup or attached\n", lmv);
1476 GOTO(out_free, err = -EINVAL);
1478 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1479 sizeof(async), &async);
1480 #warning "FIXME ASAP!"
1482 if (mdc_init_ea_size(obd, lov))
1483 GOTO(out_free, err = -EINVAL);
1486 err = obd_connect(&lmv_conn, obd, &sbi->ll_sb_uuid, 0);
1488 CERROR("cannot connect to %s: rc = %d\n", lmv, err);
1489 GOTO(out_free, err);
1491 sbi->ll_md_exp = class_conn2export(&lmv_conn);
1493 err = obd_statfs(obd, &osfs, 100000000);
1498 * FIXME fill fs stat data into sbi here!!! FIXME
1502 obd = class_name2obd(lov);
1504 CERROR("OSC %s: not setup or attached\n", lov);
1505 GOTO(out_lmv, err = -EINVAL);
1507 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1508 sizeof(async), &async);
1510 err = obd_connect(&lov_conn, obd, &sbi->ll_sb_uuid, 0);
1512 CERROR("cannot connect to %s: rc = %d\n", lov, err);
1515 sbi->ll_dt_exp = class_conn2export(&lov_conn);
1517 err = mdc_getstatus(sbi->ll_md_exp, &rootid);
1519 CERROR("cannot mds_connect: rc = %d\n", err);
1522 CDEBUG(D_SUPER, "rootid "LPU64"\n", rootid.li_stc.u.e3s.l3s_ino);
1523 sbi->ll_rootino = rootid.li_stc.u.e3s.l3s_ino;
1525 /* fetch attr of root inode */
1526 err = mdc_getattr(sbi->ll_md_exp, &rootid,
1527 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, NULL, 0,
1530 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1534 err = mdc_req2lustre_md(sbi->ll_md_exp, request, 0,
1535 sbi->ll_dt_exp, &md);
1537 CERROR("failed to understand root inode md: rc = %d\n",err);
1538 GOTO(out_request, err);
1541 LASSERT(sbi->ll_rootino != 0);
1543 root = llu_iget(fs, &md);
1544 if (!root || IS_ERR(root)) {
1545 CERROR("fail to generate root inode\n");
1546 GOTO(out_request, err = -EBADF);
1550 * Generate base path-node for root.
1552 rootpb = _sysio_pb_new(&noname, NULL, root);
1558 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1560 _sysio_pb_gone(rootpb);
1564 ptlrpc_req_finished(request);
1566 printf("LibLustre: namespace mounted successfully!\n");
1571 _sysio_i_gone(root);
1573 ptlrpc_req_finished(request);
1575 obd_disconnect(sbi->ll_dt_exp, 0);
1577 obd_disconnect(sbi->ll_md_exp, 0);
1579 OBD_FREE(sbi, sizeof(*sbi));
1583 struct fssw_ops llu_fssw_ops = {
1587 struct inode_ops llu_inode_ops = {
1588 .inop_lookup = llu_iop_lookup,
1589 .inop_getattr = llu_iop_getattr,
1590 .inop_setattr = llu_iop_setattr,
1591 .inop_getdirentries = llu_iop_getdirentries,
1592 .inop_mkdir = llu_iop_mkdir_raw,
1593 .inop_rmdir = llu_iop_rmdir_raw,
1594 .inop_symlink = llu_iop_symlink_raw,
1595 .inop_readlink = llu_iop_readlink,
1596 .inop_open = llu_iop_open,
1597 .inop_close = llu_iop_close,
1598 .inop_link = llu_iop_link_raw,
1599 .inop_unlink = llu_iop_unlink_raw,
1600 .inop_rename = llu_iop_rename_raw,
1601 .inop_iodone = llu_iop_iodone,
1602 .inop_fcntl = llu_iop_fcntl,
1603 .inop_sync = llu_iop_sync,
1604 .inop_read = llu_iop_read,
1605 .inop_write = llu_iop_write,
1606 .inop_datasync = llu_iop_datasync,
1607 .inop_ioctl = llu_iop_ioctl,
1608 .inop_mknod = llu_iop_mknod_raw,
1609 #ifdef _HAVE_STATVFS
1610 .inop_statvfs = llu_iop_statvfs,
1612 .inop_gone = llu_iop_gone,