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 %x, cur time %lu/%lu, new %lu/%lu\n",
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 %x, new time %lu/%lu\n",
225 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, ealen, &req);
443 CERROR("failure %d inode %lu\n", rc, lli->lli_st_ino);
446 rc = mdc_req2lustre_md(sbi->ll_md_exp, req, 0,
447 sbi->ll_dt_exp, &md);
449 /* XXX Too paranoid? */
450 if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) &&
451 !((md.body->valid & OBD_MD_FLNLINK) &&
452 (md.body->nlink == 0))) {
453 CERROR("Asked for %s eadata but got %s (%d)\n",
454 (valid & OBD_MD_FLEASIZE) ? "some" : "no",
455 (md.body->valid & OBD_MD_FLEASIZE) ? "some":"none",
456 md.body->eadatasize);
459 ptlrpc_req_finished(req);
464 llu_update_inode(inode, md.body, md.lsm);
465 if (md.lsm != NULL && llu_i2info(inode)->lli_smd != md.lsm)
466 obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
468 if (md.body->valid & OBD_MD_FLSIZE)
469 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
470 &llu_i2info(inode)->lli_flags);
471 ptlrpc_req_finished(req);
474 lsm = llu_i2info(inode)->lli_smd;
475 if (!lsm) /* object not yet allocated, don't validate size */
478 /* ll_glimpse_size will prefer locally cached writes if they extend
480 RETURN(llu_glimpse_size(inode));
483 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
485 struct llu_inode_info *lli = llu_i2info(ino);
487 b->st_dev = lli->lli_st_dev;
488 b->st_ino = lli->lli_st_ino;
489 b->st_mode = lli->lli_st_mode;
490 b->st_nlink = lli->lli_st_nlink;
491 b->st_uid = lli->lli_st_uid;
492 b->st_gid = lli->lli_st_gid;
493 b->st_rdev = lli->lli_st_rdev;
494 b->st_size = lli->lli_st_size;
495 b->st_blksize = lli->lli_st_blksize;
496 b->st_blocks = lli->lli_st_blocks;
497 b->st_atime = lli->lli_st_atime;
498 b->st_mtime = lli->lli_st_mtime;
499 b->st_ctime = lli->lli_st_ctime;
502 static int llu_iop_getattr(struct pnode *pno,
504 struct intnl_stat *b)
509 liblustre_wait_event(0);
513 LASSERT(pno->p_base->pb_ino);
514 ino = pno->p_base->pb_ino;
516 LASSERT(!pno || pno->p_base->pb_ino == ino);
519 /* libsysio might call us directly without intent lock,
520 * we must re-fetch the attrs here
522 rc = llu_inode_revalidate(ino);
524 copy_stat_buf(ino, b);
525 LASSERT(!llu_i2info(ino)->lli_it);
531 static int null_if_equal(struct ldlm_lock *lock, void *data)
533 if (data == lock->l_ast_data) {
534 lock->l_ast_data = NULL;
536 if (lock->l_req_mode != lock->l_granted_mode)
537 LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
540 return LDLM_ITER_CONTINUE;
543 void llu_clear_inode(struct inode *inode)
546 struct llu_inode_info *lli = llu_i2info(inode);
547 struct llu_sb_info *sbi = llu_i2sbi(inode);
550 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu(%p)\n", lli->lli_st_ino,
551 lli->lli_st_generation, inode);
553 ll_inode2id(&id, inode);
554 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
555 mdc_change_cbdata(sbi->ll_md_exp, &id, null_if_equal, inode);
558 obd_change_cbdata(sbi->ll_dt_exp, lli->lli_smd,
559 null_if_equal, inode);
562 obd_free_memmd(sbi->ll_dt_exp, &lli->lli_smd);
566 if (lli->lli_symlink_name) {
567 OBD_FREE(lli->lli_symlink_name,
568 strlen(lli->lli_symlink_name) + 1);
569 lli->lli_symlink_name = NULL;
575 void llu_iop_gone(struct inode *inode)
577 struct llu_inode_info *lli = llu_i2info(inode);
580 liblustre_wait_event(0);
581 llu_clear_inode(inode);
583 OBD_FREE(lli, sizeof(*lli));
587 static int inode_setattr(struct inode * inode, struct iattr * attr)
589 unsigned int ia_valid = attr->ia_valid;
590 struct llu_inode_info *lli = llu_i2info(inode);
593 if (ia_valid & ATTR_SIZE) {
594 error = llu_vmtruncate(inode, attr->ia_size);
599 if (ia_valid & ATTR_UID)
600 lli->lli_st_uid = attr->ia_uid;
601 if (ia_valid & ATTR_GID)
602 lli->lli_st_gid = attr->ia_gid;
603 if (ia_valid & ATTR_ATIME)
604 lli->lli_st_atime = attr->ia_atime;
605 if (ia_valid & ATTR_MTIME)
606 lli->lli_st_mtime = attr->ia_mtime;
607 if (ia_valid & ATTR_CTIME)
608 lli->lli_st_ctime = attr->ia_ctime;
609 if (ia_valid & ATTR_MODE) {
610 lli->lli_st_mode = attr->ia_mode;
611 if (!in_group_p(lli->lli_st_gid) && !capable(CAP_FSETID))
612 lli->lli_st_mode &= ~S_ISGID;
614 /* mark_inode_dirty(inode); */
619 /* If this inode has objects allocated to it (lsm != NULL), then the OST
620 * object(s) determine the file size and mtime. Otherwise, the MDS will
621 * keep these values until such a time that objects are allocated for it.
622 * We do the MDS operations first, as it is checking permissions for us.
623 * We don't to the MDS RPC if there is nothing that we want to store there,
624 * otherwise there is no harm in updating mtime/atime on the MDS if we are
625 * going to do an RPC anyways.
627 * If we are doing a truncate, we will send the mtime and ctime updates
628 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
629 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
632 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
634 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
635 struct llu_sb_info *sbi = llu_i2sbi(inode);
636 struct llu_inode_info *lli = llu_i2info(inode);
637 struct ptlrpc_request *request = NULL;
638 struct mdc_op_data op_data;
639 int ia_valid = attr->ia_valid;
643 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
645 if (ia_valid & ATTR_SIZE) {
646 if (attr->ia_size > ll_file_maxbytes(inode)) {
647 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
648 attr->ia_size, ll_file_maxbytes(inode));
652 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
655 /* We mark all of the fields "set" so MDS/OST does not re-set them */
656 if (attr->ia_valid & ATTR_CTIME) {
657 attr->ia_ctime = CURRENT_TIME;
658 attr->ia_valid |= ATTR_CTIME_SET;
660 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
661 attr->ia_atime = CURRENT_TIME;
662 attr->ia_valid |= ATTR_ATIME_SET;
664 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
665 attr->ia_mtime = CURRENT_TIME;
666 attr->ia_valid |= ATTR_MTIME_SET;
669 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
670 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
671 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
672 LTIME_S(CURRENT_TIME));
674 attr->ia_valid &= ~ATTR_SIZE;
676 /* If only OST attributes being set on objects, don't do MDS RPC.
677 * In that case, we need to check permissions and update the local
678 * inode ourselves so we can call obdo_from_inode() always. */
679 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
681 llu_prepare_mdc_data(&op_data, inode, NULL, NULL, 0, 0);
683 rc = mdc_setattr(sbi->ll_md_exp, &op_data,
684 attr, NULL, 0, NULL, 0, &request);
687 ptlrpc_req_finished(request);
688 if (rc != -EPERM && rc != -EACCES)
689 CERROR("mdc_setattr fails: rc = %d\n", rc);
693 rc = mdc_req2lustre_md(sbi->ll_md_exp, request, 0,
694 sbi->ll_dt_exp, &md);
696 ptlrpc_req_finished(request);
700 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
701 * but needed to set timestamps backwards on utime. */
702 inode_setattr(inode, attr);
703 llu_update_inode(inode, md.body, md.lsm);
704 ptlrpc_req_finished(request);
706 if (!md.lsm || !S_ISREG(lli->lli_st_mode)) {
707 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
711 /* The OST doesn't check permissions, but the alternative is
712 * a gratuitous RPC to the MDS. We already rely on the client
713 * to do read/write/truncate permission checks, so is mtime OK?
715 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
716 /* from sys_utime() */
717 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
718 if (current->fsuid != lli->lli_st_uid &&
719 (rc = ll_permission(inode, MAY_WRITE)) != 0)
722 /* from inode_change_ok() */
723 if (current->fsuid != lli->lli_st_uid &&
724 !capable(CAP_FOWNER))
729 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
730 inode_setattr(inode, attr);
733 if (ia_valid & ATTR_SIZE) {
734 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
736 struct lustre_handle lockh = { 0 };
737 int err, ast_flags = 0;
738 /* XXX when we fix the AST intents to pass the discard-range
739 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
741 if (attr->ia_size == 0)
742 ast_flags = LDLM_AST_DISCARD_DATA;
744 rc = llu_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
746 if (rc != ELDLM_OK) {
752 rc = llu_vmtruncate(inode, attr->ia_size);
754 /* unlock now as we don't mind others file lockers racing with
755 * the mds updates below? */
756 err = llu_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
758 CERROR("llu_extent_unlock failed: %d\n", err);
762 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
765 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
766 lli->lli_st_ino, LTIME_S(attr->ia_mtime));
767 oa.o_id = lsm->lsm_object_id;
768 oa.o_valid = OBD_MD_FLID;
769 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
770 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
771 rc = obd_setattr(sbi->ll_dt_exp, &oa, lsm, NULL);
773 CERROR("obd_setattr fails: rc=%d\n", rc);
778 /* here we simply act as a thin layer to glue it with
779 * llu_setattr_raw(), which is copy from kernel
781 static int llu_iop_setattr(struct pnode *pno,
784 struct intnl_stat *stbuf)
789 liblustre_wait_event(0);
791 LASSERT(!(mask & ~(SETATTR_MTIME | SETATTR_ATIME |
792 SETATTR_UID | SETATTR_GID |
793 SETATTR_LEN | SETATTR_MODE)));
794 memset(&iattr, 0, sizeof(iattr));
796 if (mask & SETATTR_MODE) {
797 iattr.ia_mode = stbuf->st_mode;
798 iattr.ia_valid |= ATTR_MODE;
800 if (mask & SETATTR_MTIME) {
801 iattr.ia_mtime = stbuf->st_mtime;
802 iattr.ia_valid |= ATTR_MTIME;
804 if (mask & SETATTR_ATIME) {
805 iattr.ia_atime = stbuf->st_atime;
806 iattr.ia_valid |= ATTR_ATIME;
808 if (mask & SETATTR_UID) {
809 iattr.ia_uid = stbuf->st_uid;
810 iattr.ia_valid |= ATTR_UID;
812 if (mask & SETATTR_GID) {
813 iattr.ia_gid = stbuf->st_gid;
814 iattr.ia_valid |= ATTR_GID;
816 if (mask & SETATTR_LEN) {
817 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
818 iattr.ia_valid |= ATTR_SIZE;
821 iattr.ia_valid |= ATTR_RAW;
823 RETURN(llu_setattr_raw(ino, &iattr));
826 #define EXT2_LINK_MAX 32000
828 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
830 struct inode *dir = pno->p_base->pb_parent->pb_ino;
831 struct qstr *qstr = &pno->p_base->pb_name;
832 const char *name = qstr->name;
834 struct ptlrpc_request *request = NULL;
835 struct llu_sb_info *sbi = llu_i2sbi(dir);
836 struct mdc_op_data op_data;
840 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
843 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, 0);
844 err = mdc_create(sbi->ll_md_exp, &op_data,
845 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
846 current->fsuid, current->fsgid, 0, &request);
847 ptlrpc_req_finished(request);
851 static int llu_readlink_internal(struct inode *inode,
852 struct ptlrpc_request **request,
855 struct llu_inode_info *lli = llu_i2info(inode);
856 struct llu_sb_info *sbi = llu_i2sbi(inode);
858 struct mds_body *body;
859 int rc, symlen = lli->lli_st_size + 1;
864 if (lli->lli_symlink_name) {
865 *symname = lli->lli_symlink_name;
866 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
870 ll_inode2id(&id, inode);
871 rc = mdc_getattr(sbi->ll_md_exp, &id,
872 OBD_MD_LINKNAME, symlen, request);
874 CERROR("inode %lu: rc = %d\n", lli->lli_st_ino, rc);
878 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
879 LASSERT (body != NULL);
880 LASSERT_REPSWABBED (*request, 0);
882 if ((body->valid & OBD_MD_LINKNAME) == 0) {
883 CERROR ("OBD_MD_LINKNAME not set on reply\n");
884 GOTO (failed, rc = -EPROTO);
887 LASSERT (symlen != 0);
888 if (body->eadatasize != symlen) {
889 CERROR ("inode %lu: symlink length %d not expected %d\n",
890 lli->lli_st_ino, body->eadatasize - 1, symlen - 1);
891 GOTO (failed, rc = -EPROTO);
894 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
895 if (*symname == NULL ||
896 strnlen (*symname, symlen) != symlen - 1) {
897 /* not full/NULL terminated */
898 CERROR ("inode %lu: symlink not NULL terminated string"
899 "of length %d\n", lli->lli_st_ino, symlen - 1);
900 GOTO (failed, rc = -EPROTO);
903 OBD_ALLOC(lli->lli_symlink_name, symlen);
904 /* do not return an error if we cannot cache the symlink locally */
905 if (lli->lli_symlink_name)
906 memcpy(lli->lli_symlink_name, *symname, symlen);
911 ptlrpc_req_finished (*request);
915 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
917 struct inode *inode = pno->p_base->pb_ino;
918 struct ptlrpc_request *request;
923 rc = llu_readlink_internal(inode, &request, &symname);
928 strncpy(data, symname, bufsize);
930 ptlrpc_req_finished(request);
935 static int llu_iop_mknod_raw(struct pnode *pno,
939 struct ptlrpc_request *request = NULL;
940 struct inode *dir = pno->p_parent->p_base->pb_ino;
941 struct llu_sb_info *sbi = llu_i2sbi(dir);
942 struct mdc_op_data op_data;
946 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu\n",
947 pno->p_base->pb_name.name, llu_i2info(dir)->lli_st_ino);
949 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
952 mode &= ~current->fs->umask;
954 switch (mode & S_IFMT) {
957 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
962 llu_prepare_mdc_data(&op_data, dir, NULL,
963 pno->p_base->pb_name.name,
964 pno->p_base->pb_name.len,
966 err = mdc_create(sbi->ll_md_exp, &op_data, NULL, 0, mode,
967 current->fsuid, current->fsgid, dev, &request);
968 ptlrpc_req_finished(request);
979 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
981 struct inode *src = old->p_base->pb_ino;
982 struct inode *dir = new->p_parent->p_base->pb_ino;
983 const char *name = new->p_base->pb_name.name;
984 int namelen = new->p_base->pb_name.len;
985 struct ptlrpc_request *request = NULL;
986 struct mdc_op_data op_data;
993 liblustre_wait_event(0);
994 llu_prepare_mdc_data(&op_data, src, dir, name, namelen, 0);
995 rc = mdc_link(llu_i2sbi(src)->ll_md_exp, &op_data, &request);
996 ptlrpc_req_finished(request);
997 liblustre_wait_event(0);
1003 * libsysio will clear the inode immediately after return
1005 static int llu_iop_unlink_raw(struct pnode *pno)
1007 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1008 struct qstr *qstr = &pno->p_base->pb_name;
1009 const char *name = qstr->name;
1010 int len = qstr->len;
1011 struct inode *target = pno->p_base->pb_ino;
1012 struct ptlrpc_request *request = NULL;
1013 struct mdc_op_data op_data;
1019 liblustre_wait_event(0);
1020 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, 0);
1021 rc = mdc_unlink(llu_i2sbi(dir)->ll_md_exp, &op_data, &request);
1023 rc = llu_objects_destroy(request, dir);
1024 ptlrpc_req_finished(request);
1025 liblustre_wait_event(0);
1029 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
1031 struct inode *src = old->p_parent->p_base->pb_ino;
1032 struct inode *tgt = new->p_parent->p_base->pb_ino;
1033 const char *oldname = old->p_base->pb_name.name;
1034 int oldnamelen = old->p_base->pb_name.len;
1035 const char *newname = new->p_base->pb_name.name;
1036 int newnamelen = new->p_base->pb_name.len;
1037 struct ptlrpc_request *request = NULL;
1038 struct mdc_op_data op_data;
1045 llu_prepare_mdc_data(&op_data, src, tgt, NULL, 0, 0);
1046 rc = mdc_rename(llu_i2sbi(src)->ll_md_exp, &op_data,
1047 oldname, oldnamelen, newname, newnamelen,
1050 rc = llu_objects_destroy(request, src);
1053 ptlrpc_req_finished(request);
1058 #ifdef _HAVE_STATVFS
1059 static int llu_statfs_internal(struct llu_sb_info *sbi,
1060 struct obd_statfs *osfs,
1061 unsigned long max_age)
1063 struct obd_statfs obd_osfs;
1067 rc = obd_statfs(class_exp2obd(sbi->ll_md_exp), osfs, max_age);
1069 CERROR("mdc_statfs fails: rc = %d\n", rc);
1073 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1074 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1076 rc = obd_statfs(class_exp2obd(sbi->ll_dt_exp), &obd_osfs, max_age);
1078 CERROR("obd_statfs fails: rc = %d\n", rc);
1082 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1083 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1086 osfs->os_blocks = obd_osfs.os_blocks;
1087 osfs->os_bfree = obd_osfs.os_bfree;
1088 osfs->os_bavail = obd_osfs.os_bavail;
1090 /* If we don't have as many objects free on the OST as inodes
1091 * on the MDS, we reduce the total number of inodes to
1092 * compensate, so that the "inodes in use" number is correct.
1094 if (obd_osfs.os_ffree < osfs->os_ffree) {
1095 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1097 osfs->os_ffree = obd_osfs.os_ffree;
1103 static int llu_statfs(struct llu_sb_info *sbi, struct statfs *sfs)
1105 struct obd_statfs osfs;
1108 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1110 /* For now we will always get up-to-date statfs values, but in the
1111 * future we may allow some amount of caching on the client (e.g.
1112 * from QOS or lprocfs updates). */
1113 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1117 statfs_unpack(sfs, &osfs);
1119 if (sizeof(sfs->f_blocks) == 4) {
1120 while (osfs.os_blocks > ~0UL) {
1123 osfs.os_blocks >>= 1;
1124 osfs.os_bfree >>= 1;
1125 osfs.os_bavail >>= 1;
1129 sfs->f_blocks = osfs.os_blocks;
1130 sfs->f_bfree = osfs.os_bfree;
1131 sfs->f_bavail = osfs.os_bavail;
1136 static int llu_iop_statvfs(struct pnode *pno,
1138 struct intnl_statvfs *buf)
1144 liblustre_wait_event(0);
1147 LASSERT(pno->p_base->pb_ino);
1148 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1152 /* from native driver */
1153 buf->f_bsize = fs.f_bsize; /* file system block size */
1154 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1155 buf->f_blocks = fs.f_blocks;
1156 buf->f_bfree = fs.f_bfree;
1157 buf->f_bavail = fs.f_bavail;
1158 buf->f_files = fs.f_files; /* Total number serial numbers */
1159 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1160 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1161 buf->f_fsid = fs.f_fstc.__val[1];
1162 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1163 buf->f_namemax = fs.f_namelen;
1168 #endif /* _HAVE_STATVFS */
1170 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1172 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1173 struct qstr *qstr = &pno->p_base->pb_name;
1174 const char *name = qstr->name;
1175 int len = qstr->len;
1176 struct ptlrpc_request *request = NULL;
1177 struct llu_inode_info *lli = llu_i2info(dir);
1178 struct mdc_op_data op_data;
1181 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1182 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1184 if (lli->lli_st_nlink >= EXT2_LINK_MAX)
1187 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
1188 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, 0);
1189 err = mdc_create(llu_i2sbi(dir)->ll_md_exp, &op_data, NULL, 0, mode,
1190 current->fsuid, current->fsgid, 0, &request);
1191 ptlrpc_req_finished(request);
1195 static int llu_iop_rmdir_raw(struct pnode *pno)
1197 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1198 struct qstr *qstr = &pno->p_base->pb_name;
1199 const char *name = qstr->name;
1200 int len = qstr->len;
1201 struct ptlrpc_request *request = NULL;
1202 struct mdc_op_data op_data;
1203 struct llu_inode_info *lli = llu_i2info(dir);
1206 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1207 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1209 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, S_IFDIR);
1210 rc = mdc_unlink(llu_i2sbi(dir)->ll_md_exp, &op_data, &request);
1211 ptlrpc_req_finished(request);
1217 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC|O_DIRECT)
1219 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC)
1221 #define FCNTL_FLMASK_INVALID (O_NONBLOCK|O_ASYNC)
1223 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn)
1225 struct llu_inode_info *lli = llu_i2info(ino);
1230 *rtn = lli->lli_open_flags;
1233 flags = va_arg(ap, long);
1234 flags &= FCNTL_FLMASK;
1235 if (flags & FCNTL_FLMASK_INVALID) {
1236 CERROR("liblustre does not support O_NONBLOCK, O_ASYNC, "
1237 "and O_DIRECT on file descriptor\n");
1241 lli->lli_open_flags = (int) flags;
1246 CERROR("unsupported fcntl cmd %x\n", cmd);
1251 static int llu_get_grouplock(struct inode *inode, unsigned long arg)
1253 struct llu_inode_info *lli = llu_i2info(inode);
1254 struct ll_file_data *fd = lli->lli_file_data;
1255 ldlm_policy_data_t policy = { .l_extent = { .start = 0,
1256 .end = OBD_OBJECT_EOF}};
1257 struct lustre_handle lockh = { 0 };
1258 struct lov_stripe_md *lsm = lli->lli_smd;
1263 if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
1267 policy.l_extent.gid = arg;
1268 if (lli->lli_open_flags & O_NONBLOCK)
1269 flags = LDLM_FL_BLOCK_NOWAIT;
1271 err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
1276 fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
1278 memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
1283 static int llu_put_grouplock(struct inode *inode, unsigned long arg)
1285 struct llu_inode_info *lli = llu_i2info(inode);
1286 struct ll_file_data *fd = lli->lli_file_data;
1287 struct lov_stripe_md *lsm = lli->lli_smd;
1291 if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
1294 if (fd->fd_gid != arg)
1297 fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
1299 err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
1304 memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
1309 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1314 liblustre_wait_event(0);
1317 case LL_IOC_GROUP_LOCK:
1318 arg = va_arg(ap, unsigned long);
1319 return llu_get_grouplock(ino, arg);
1320 case LL_IOC_GROUP_UNLOCK:
1321 arg = va_arg(ap, unsigned long);
1322 return llu_put_grouplock(ino, arg);
1325 CERROR("did not support ioctl cmd %lx\n", request);
1330 * we already do syncronous read/write
1332 static int llu_iop_sync(struct inode *inode)
1334 liblustre_wait_event(0);
1338 static int llu_iop_datasync(struct inode *inode)
1340 liblustre_wait_event(0);
1344 struct filesys_ops llu_filesys_ops =
1346 fsop_gone: llu_fsop_gone,
1349 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1351 struct inode *inode;
1352 struct lustre_id id;
1353 struct file_identifier fileid = {&id, sizeof(id)};
1355 if ((md->body->valid &
1356 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1357 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) {
1358 CERROR("bad md body valid mask 0x%x\n", md->body->valid);
1360 return ERR_PTR(-EPERM);
1365 /* try to find existing inode */
1366 inode = _sysio_i_find(fs, &fileid);
1368 struct llu_inode_info *lli = llu_i2info(inode);
1370 if (inode->i_zombie ||
1371 lli->lli_st_generation != id_gen(&md->body->id1)) {
1375 llu_update_inode(inode, md->body, md->lsm);
1380 inode = llu_new_inode(fs, &id);
1382 llu_update_inode(inode, md->body, md->lsm);
1388 llu_fsswop_mount(const char *source,
1390 const void *data __IS_UNUSED,
1391 struct pnode *tocover,
1392 struct mount **mntp)
1396 struct pnode_base *rootpb;
1397 struct obd_device *obd;
1398 struct lustre_id rootid;
1399 struct llu_sb_info *sbi;
1400 struct obd_statfs osfs;
1401 static struct qstr noname = { NULL, 0, 0 };
1402 struct ptlrpc_request *request = NULL;
1403 struct lustre_handle lmv_conn = {0, };
1404 struct lustre_handle lov_conn = {0, };
1405 struct lustre_md md;
1407 struct config_llog_instance cfg;
1408 struct lustre_profile *lprof;
1409 char *lov = NULL, *lmv = NULL;
1410 int async = 1, err = -EINVAL;
1414 /* allocate & initialize sbi */
1415 OBD_ALLOC(sbi, sizeof(*sbi));
1419 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1420 generate_random_uuid(uuid);
1421 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1423 /* generate a string unique to this super, let's try
1424 the address of the super itself.*/
1425 OBD_ALLOC(sbi->ll_instance, sizeof(sbi) * 2 + 1);
1426 if (sbi->ll_instance == NULL)
1427 GOTO(out_free, err = -ENOMEM);
1428 sprintf(sbi->ll_instance, "%p", sbi);
1430 /* retrive & parse config log */
1431 cfg.cfg_instance = sbi->ll_instance;
1432 cfg.cfg_uuid = sbi->ll_sb_uuid;
1433 err = liblustre_process_log(&cfg, 1);
1435 CERROR("Unable to process log: %s\n", g_zconf_profile);
1436 GOTO(out_free, err);
1439 lprof = class_get_profile(g_zconf_profile);
1440 if (lprof == NULL) {
1441 CERROR("No profile found: %s\n", g_zconf_profile);
1442 GOTO(out_free, err = -EINVAL);
1445 OBD_FREE(lov, strlen(lov) + 1);
1446 OBD_ALLOC(lov, strlen(lprof->lp_lov) +
1447 strlen(sbi->ll_instance) + 2);
1448 sprintf(lov, "%s-%s", lprof->lp_lov, sbi->ll_instance);
1451 OBD_FREE(lmv, strlen(lmv) + 1);
1452 OBD_ALLOC(lmv, strlen(lprof->lp_lmv) +
1453 strlen(sbi->ll_instance) + 2);
1454 sprintf(lmv, "%s-%s", lprof->lp_lmv, sbi->ll_instance);
1458 GOTO(out_free, err = -EINVAL);
1462 GOTO(out_free, err = -EINVAL);
1465 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1471 obd = class_name2obd(lmv);
1473 CERROR("MDC %s: not setup or attached\n", lmv);
1474 GOTO(out_free, err = -EINVAL);
1476 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1477 sizeof(async), &async);
1478 #warning "FIXME ASAP!"
1480 if (mdc_init_ea_size(obd, lov))
1481 GOTO(out_free, err = -EINVAL);
1484 err = obd_connect(&lmv_conn, obd, &sbi->ll_sb_uuid, 0);
1486 CERROR("cannot connect to %s: rc = %d\n", lmv, err);
1487 GOTO(out_free, err);
1489 sbi->ll_md_exp = class_conn2export(&lmv_conn);
1491 err = obd_statfs(obd, &osfs, 100000000);
1496 * FIXME fill fs stat data into sbi here!!! FIXME
1500 obd = class_name2obd(lov);
1502 CERROR("OSC %s: not setup or attached\n", lov);
1503 GOTO(out_lmv, err = -EINVAL);
1505 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1506 sizeof(async), &async);
1508 err = obd_connect(&lov_conn, obd, &sbi->ll_sb_uuid, 0);
1510 CERROR("cannot connect to %s: rc = %d\n", lov, err);
1513 sbi->ll_dt_exp = class_conn2export(&lov_conn);
1515 err = mdc_getstatus(sbi->ll_md_exp, &rootid);
1517 CERROR("cannot mds_connect: rc = %d\n", err);
1520 CDEBUG(D_SUPER, "rootid "LPU64"\n", rootid.li_stc.u.e3s.l3s_ino);
1521 sbi->ll_rootino = rootid.li_stc.u.e3s.l3s_ino;
1523 /* fetch attr of root inode */
1524 err = mdc_getattr(sbi->ll_md_exp, &rootid,
1525 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
1527 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1531 err = mdc_req2lustre_md(sbi->ll_md_exp, request, 0,
1532 sbi->ll_dt_exp, &md);
1534 CERROR("failed to understand root inode md: rc = %d\n",err);
1535 GOTO(out_request, err);
1538 LASSERT(sbi->ll_rootino != 0);
1540 root = llu_iget(fs, &md);
1541 if (!root || IS_ERR(root)) {
1542 CERROR("fail to generate root inode\n");
1543 GOTO(out_request, err = -EBADF);
1547 * Generate base path-node for root.
1549 rootpb = _sysio_pb_new(&noname, NULL, root);
1555 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1557 _sysio_pb_gone(rootpb);
1561 ptlrpc_req_finished(request);
1563 printf("LibLustre: namespace mounted successfully!\n");
1568 _sysio_i_gone(root);
1570 ptlrpc_req_finished(request);
1572 obd_disconnect(sbi->ll_dt_exp, 0);
1574 obd_disconnect(sbi->ll_md_exp, 0);
1576 OBD_FREE(sbi, sizeof(*sbi));
1580 struct fssw_ops llu_fssw_ops = {
1584 struct inode_ops llu_inode_ops = {
1585 .inop_lookup = llu_iop_lookup,
1586 .inop_getattr = llu_iop_getattr,
1587 .inop_setattr = llu_iop_setattr,
1588 .inop_getdirentries = llu_iop_getdirentries,
1589 .inop_mkdir = llu_iop_mkdir_raw,
1590 .inop_rmdir = llu_iop_rmdir_raw,
1591 .inop_symlink = llu_iop_symlink_raw,
1592 .inop_readlink = llu_iop_readlink,
1593 .inop_open = llu_iop_open,
1594 .inop_close = llu_iop_close,
1595 .inop_link = llu_iop_link_raw,
1596 .inop_unlink = llu_iop_unlink_raw,
1597 .inop_rename = llu_iop_rename_raw,
1598 .inop_iodone = llu_iop_iodone,
1599 .inop_fcntl = llu_iop_fcntl,
1600 .inop_sync = llu_iop_sync,
1601 .inop_read = llu_iop_read,
1602 .inop_write = llu_iop_write,
1603 .inop_datasync = llu_iop_datasync,
1604 .inop_ioctl = llu_iop_ioctl,
1605 .inop_mknod = llu_iop_mknod_raw,
1606 #ifdef _HAVE_STATVFS
1607 .inop_statvfs = llu_iop_statvfs,
1609 .inop_gone = llu_iop_gone,