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>
35 # include <sys/statvfs.h>
37 # 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_mdc_exp);
89 struct lustre_cfg lcfg;
93 list_del(&sbi->ll_conn_chain);
94 obd_disconnect(sbi->ll_osc_exp, 0);
95 obd_disconnect(sbi->ll_mdc_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_FREE(sbi, sizeof(*sbi));
119 static 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 if (body->valid & OBD_MD_FLID)
143 lli->lli_st_ino = body->ino;
144 if (body->valid & OBD_MD_FLATIME)
145 LTIME_S(lli->lli_st_atime) = body->atime;
146 if (body->valid & OBD_MD_FLMTIME)
147 LTIME_S(lli->lli_st_mtime) = body->mtime;
148 if (body->valid & OBD_MD_FLCTIME)
149 LTIME_S(lli->lli_st_ctime) = body->ctime;
150 if (body->valid & OBD_MD_FLMODE)
151 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT)|(body->mode & ~S_IFMT);
152 if (body->valid & OBD_MD_FLTYPE)
153 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT)|(body->mode & S_IFMT);
154 if (body->valid & OBD_MD_FLUID)
155 lli->lli_st_uid = body->uid;
156 if (body->valid & OBD_MD_FLGID)
157 lli->lli_st_gid = body->gid;
158 if (body->valid & OBD_MD_FLFLAGS)
159 lli->lli_st_flags = body->flags;
160 if (body->valid & OBD_MD_FLNLINK)
161 lli->lli_st_nlink = body->nlink;
162 if (body->valid & OBD_MD_FLGENER)
163 lli->lli_st_generation = body->generation;
164 if (body->valid & OBD_MD_FLRDEV)
165 lli->lli_st_rdev = body->rdev;
166 if (body->valid & OBD_MD_FLSIZE)
167 lli->lli_st_size = body->size;
168 if (body->valid & OBD_MD_FLBLOCKS)
169 lli->lli_st_blocks = body->blocks;
172 if (body->valid & OBD_MD_FLID)
173 lli->lli_fid.id = body->ino;
174 if (body->valid & OBD_MD_FLGENER)
175 lli->lli_fid.generation = body->generation;
176 if (body->valid & OBD_MD_FLTYPE)
177 lli->lli_fid.f_type = body->mode & S_IFMT;
180 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
182 struct llu_inode_info *lli = llu_i2info(dst);
184 valid &= src->o_valid;
186 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
187 CDEBUG(D_INODE, "valid %x, cur time %lu/%lu, new %lu/%lu\n",
189 LTIME_S(lli->lli_st_mtime), LTIME_S(lli->lli_st_ctime),
190 (long)src->o_mtime, (long)src->o_ctime);
192 if (valid & OBD_MD_FLATIME)
193 LTIME_S(lli->lli_st_atime) = src->o_atime;
194 if (valid & OBD_MD_FLMTIME)
195 LTIME_S(lli->lli_st_mtime) = src->o_mtime;
196 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(lli->lli_st_ctime))
197 LTIME_S(lli->lli_st_ctime) = src->o_ctime;
198 if (valid & OBD_MD_FLSIZE)
199 lli->lli_st_size = src->o_size;
200 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
201 lli->lli_st_blocks = src->o_blocks;
202 if (valid & OBD_MD_FLBLKSZ)
203 lli->lli_st_blksize = src->o_blksize;
204 if (valid & OBD_MD_FLTYPE)
205 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
206 if (valid & OBD_MD_FLMODE)
207 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
208 if (valid & OBD_MD_FLUID)
209 lli->lli_st_uid = src->o_uid;
210 if (valid & OBD_MD_FLGID)
211 lli->lli_st_gid = src->o_gid;
212 if (valid & OBD_MD_FLFLAGS)
213 lli->lli_st_flags = src->o_flags;
214 if (valid & OBD_MD_FLGENER)
215 lli->lli_st_generation = src->o_generation;
218 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
219 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
221 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
223 struct llu_inode_info *lli = llu_i2info(src);
224 obd_flag newvalid = 0;
226 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
227 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
228 valid, LTIME_S(lli->lli_st_mtime),
229 LTIME_S(lli->lli_st_ctime));
231 if (valid & OBD_MD_FLATIME) {
232 dst->o_atime = LTIME_S(lli->lli_st_atime);
233 newvalid |= OBD_MD_FLATIME;
235 if (valid & OBD_MD_FLMTIME) {
236 dst->o_mtime = LTIME_S(lli->lli_st_mtime);
237 newvalid |= OBD_MD_FLMTIME;
239 if (valid & OBD_MD_FLCTIME) {
240 dst->o_ctime = LTIME_S(lli->lli_st_ctime);
241 newvalid |= OBD_MD_FLCTIME;
243 if (valid & OBD_MD_FLSIZE) {
244 dst->o_size = lli->lli_st_size;
245 newvalid |= OBD_MD_FLSIZE;
247 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
248 dst->o_blocks = lli->lli_st_blocks;
249 newvalid |= OBD_MD_FLBLOCKS;
251 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
252 dst->o_blksize = lli->lli_st_blksize;
253 newvalid |= OBD_MD_FLBLKSZ;
255 if (valid & OBD_MD_FLTYPE) {
256 dst->o_mode = (dst->o_mode & S_IALLUGO)|(lli->lli_st_mode & S_IFMT);
257 newvalid |= OBD_MD_FLTYPE;
259 if (valid & OBD_MD_FLMODE) {
260 dst->o_mode = (dst->o_mode & S_IFMT)|(lli->lli_st_mode & S_IALLUGO);
261 newvalid |= OBD_MD_FLMODE;
263 if (valid & OBD_MD_FLUID) {
264 dst->o_uid = lli->lli_st_uid;
265 newvalid |= OBD_MD_FLUID;
267 if (valid & OBD_MD_FLGID) {
268 dst->o_gid = lli->lli_st_gid;
269 newvalid |= OBD_MD_FLGID;
271 if (valid & OBD_MD_FLFLAGS) {
272 dst->o_flags = lli->lli_st_flags;
273 newvalid |= OBD_MD_FLFLAGS;
275 if (valid & OBD_MD_FLGENER) {
276 dst->o_generation = lli->lli_st_generation;
277 newvalid |= OBD_MD_FLGENER;
280 dst->o_valid |= newvalid;
284 * really does the getattr on the inode and updates its fields
286 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
288 struct llu_inode_info *lli = llu_i2info(inode);
289 struct obd_export *exp = llu_i2obdexp(inode);
290 struct ptlrpc_request_set *set;
292 obd_flag refresh_valid;
299 memset(&oa, 0, sizeof oa);
300 oa.o_id = lsm->lsm_object_id;
302 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
303 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
306 set = ptlrpc_prep_set();
308 CERROR ("ENOMEM allocing request set\n");
311 rc = obd_getattr_async(exp, &oa, lsm, set);
313 rc = ptlrpc_set_wait(set);
314 ptlrpc_set_destroy(set);
319 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
320 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
322 /* We set this flag in commit write as we extend the file size. When
323 * the bit is set and the lock is canceled that covers the file size,
324 * we clear the bit. This is enough to protect the window where our
325 * local size extension is needed for writeback. However, it relies on
326 * behaviour that won't be true in the near future. This assumes that
327 * all getattr callers get extent locks, which they currnetly do. It
328 * also assumes that we only send discarding asts for {0,eof} truncates
329 * as is currently the case. This will have to be replaced by the
330 * proper eoc communication between clients and the ost, which is on
332 if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
333 if (oa.o_size < lli->lli_st_size)
334 refresh_valid &= ~OBD_MD_FLSIZE;
336 clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
339 obdo_refresh_inode(inode, &oa, refresh_valid);
344 static struct inode* llu_new_inode(struct filesys *fs,
348 struct llu_inode_info *lli;
350 OBD_ALLOC(lli, sizeof(*lli));
354 /* initialize lli here */
355 lli->lli_sbi = llu_fs2sbi(fs);
357 lli->lli_symlink_name = NULL;
359 lli->lli_maxbytes = (__u64)(~0UL);
360 lli->lli_file_data = NULL;
362 lli->lli_sysio_fid.fid_data = &lli->lli_fid;
363 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_fid);
365 memcpy(&lli->lli_fid, fid, sizeof(*fid));
367 /* file identifier is needed by functions like _sysio_i_find() */
368 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
369 #ifndef AUTOMOUNT_FILE_NAME
370 fid->f_type & S_IFMT,
372 fid->f_type, /* all of the bits! */
375 &llu_inode_ops, lli);
378 OBD_FREE(lli, sizeof(*lli));
383 static int llu_have_md_lock(struct inode *inode, __u64 lockpart)
385 struct llu_sb_info *sbi = llu_i2sbi(inode);
386 struct llu_inode_info *lli = llu_i2info(inode);
387 struct lustre_handle lockh;
388 struct ldlm_res_id res_id = { .name = {0} };
389 struct obd_device *obddev;
390 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
396 obddev = sbi->ll_mdc_exp->exp_obd;
397 res_id.name[0] = lli->lli_st_ino;
398 res_id.name[1] = lli->lli_st_generation;
400 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
402 /* FIXME use LDLM_FL_TEST_LOCK instead */
403 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
404 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
405 &policy, LCK_PR, &lockh)) {
406 ldlm_lock_decref(&lockh, LCK_PR);
410 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
411 &policy, LCK_PW, &lockh)) {
412 ldlm_lock_decref(&lockh, LCK_PW);
418 static int llu_inode_revalidate(struct inode *inode)
420 struct llu_inode_info *lli = llu_i2info(inode);
421 struct lov_stripe_md *lsm = NULL;
425 CERROR("REPORT THIS LINE TO PETER\n");
429 if (!llu_have_md_lock(inode, MDS_INODELOCK_UPDATE)) {
431 struct ptlrpc_request *req = NULL;
432 struct llu_sb_info *sbi = llu_i2sbi(inode);
434 unsigned long valid = 0;
437 /* Why don't we update all valid MDS fields here, if we're
438 * doing an RPC anyways? -phil */
439 if (S_ISREG(lli->lli_st_mode)) {
440 ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
441 valid |= OBD_MD_FLEASIZE;
443 ll_inode2fid(&fid, inode);
444 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
446 CERROR("failure %d inode %lu\n", rc, lli->lli_st_ino);
449 rc = mdc_req2lustre_md(sbi->ll_mdc_exp, req, 0, sbi->ll_osc_exp,
452 /* XXX Too paranoid? */
453 if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) &&
454 !((md.body->valid & OBD_MD_FLNLINK) &&
455 (md.body->nlink == 0))) {
456 CERROR("Asked for %s eadata but got %s (%d)\n",
457 (valid & OBD_MD_FLEASIZE) ? "some" : "no",
458 (md.body->valid & OBD_MD_FLEASIZE) ? "some":"none",
459 md.body->eadatasize);
462 ptlrpc_req_finished(req);
467 llu_update_inode(inode, md.body, md.lsm);
468 if (md.lsm != NULL && llu_i2info(inode)->lli_smd != md.lsm)
469 obd_free_memmd(sbi->ll_osc_exp, &md.lsm);
471 if (md.body->valid & OBD_MD_FLSIZE)
472 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
473 &llu_i2info(inode)->lli_flags);
474 ptlrpc_req_finished(req);
477 lsm = llu_i2info(inode)->lli_smd;
478 if (!lsm) /* object not yet allocated, don't validate size */
481 /* ll_glimpse_size will prefer locally cached writes if they extend
483 RETURN(llu_glimpse_size(inode));
486 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
488 struct llu_inode_info *lli = llu_i2info(ino);
490 b->st_dev = lli->lli_st_dev;
491 b->st_ino = lli->lli_st_ino;
492 b->st_mode = lli->lli_st_mode;
493 b->st_nlink = lli->lli_st_nlink;
494 b->st_uid = lli->lli_st_uid;
495 b->st_gid = lli->lli_st_gid;
496 b->st_rdev = lli->lli_st_rdev;
497 b->st_size = lli->lli_st_size;
498 b->st_blksize = lli->lli_st_blksize;
499 b->st_blocks = lli->lli_st_blocks;
500 b->st_atime = lli->lli_st_atime;
501 b->st_mtime = lli->lli_st_mtime;
502 b->st_ctime = lli->lli_st_ctime;
505 static int llu_iop_getattr(struct pnode *pno,
507 struct intnl_stat *b)
512 liblustre_wait_event(0);
516 LASSERT(pno->p_base->pb_ino);
517 ino = pno->p_base->pb_ino;
519 LASSERT(!pno || pno->p_base->pb_ino == ino);
522 /* libsysio might call us directly without intent lock,
523 * we must re-fetch the attrs here
525 rc = llu_inode_revalidate(ino);
527 copy_stat_buf(ino, b);
528 LASSERT(!llu_i2info(ino)->lli_it);
534 static int null_if_equal(struct ldlm_lock *lock, void *data)
536 if (data == lock->l_ast_data) {
537 lock->l_ast_data = NULL;
539 if (lock->l_req_mode != lock->l_granted_mode)
540 LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
543 return LDLM_ITER_CONTINUE;
546 void llu_clear_inode(struct inode *inode)
549 struct llu_inode_info *lli = llu_i2info(inode);
550 struct llu_sb_info *sbi = llu_i2sbi(inode);
553 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu(%p)\n", lli->lli_st_ino,
554 lli->lli_st_generation, inode);
556 ll_inode2fid(&fid, inode);
557 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
558 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
561 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
562 null_if_equal, inode);
565 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
569 if (lli->lli_symlink_name) {
570 OBD_FREE(lli->lli_symlink_name,
571 strlen(lli->lli_symlink_name) + 1);
572 lli->lli_symlink_name = NULL;
578 void llu_iop_gone(struct inode *inode)
580 struct llu_inode_info *lli = llu_i2info(inode);
583 liblustre_wait_event(0);
584 llu_clear_inode(inode);
586 OBD_FREE(lli, sizeof(*lli));
590 static int inode_setattr(struct inode * inode, struct iattr * attr)
592 unsigned int ia_valid = attr->ia_valid;
593 struct llu_inode_info *lli = llu_i2info(inode);
596 if (ia_valid & ATTR_SIZE) {
597 error = llu_vmtruncate(inode, attr->ia_size);
602 if (ia_valid & ATTR_UID)
603 lli->lli_st_uid = attr->ia_uid;
604 if (ia_valid & ATTR_GID)
605 lli->lli_st_gid = attr->ia_gid;
606 if (ia_valid & ATTR_ATIME)
607 lli->lli_st_atime = attr->ia_atime;
608 if (ia_valid & ATTR_MTIME)
609 lli->lli_st_mtime = attr->ia_mtime;
610 if (ia_valid & ATTR_CTIME)
611 lli->lli_st_ctime = attr->ia_ctime;
612 if (ia_valid & ATTR_MODE) {
613 lli->lli_st_mode = attr->ia_mode;
614 if (!in_group_p(lli->lli_st_gid) && !capable(CAP_FSETID))
615 lli->lli_st_mode &= ~S_ISGID;
617 /* mark_inode_dirty(inode); */
622 /* If this inode has objects allocated to it (lsm != NULL), then the OST
623 * object(s) determine the file size and mtime. Otherwise, the MDS will
624 * keep these values until such a time that objects are allocated for it.
625 * We do the MDS operations first, as it is checking permissions for us.
626 * We don't to the MDS RPC if there is nothing that we want to store there,
627 * otherwise there is no harm in updating mtime/atime on the MDS if we are
628 * going to do an RPC anyways.
630 * If we are doing a truncate, we will send the mtime and ctime updates
631 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
632 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
635 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
637 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
638 struct llu_sb_info *sbi = llu_i2sbi(inode);
639 struct llu_inode_info *lli = llu_i2info(inode);
640 struct ptlrpc_request *request = NULL;
641 struct mdc_op_data op_data;
642 int ia_valid = attr->ia_valid;
646 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
648 if (ia_valid & ATTR_SIZE) {
649 if (attr->ia_size > ll_file_maxbytes(inode)) {
650 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
651 attr->ia_size, ll_file_maxbytes(inode));
655 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
658 /* We mark all of the fields "set" so MDS/OST does not re-set them */
659 if (attr->ia_valid & ATTR_CTIME) {
660 attr->ia_ctime = CURRENT_TIME;
661 attr->ia_valid |= ATTR_CTIME_SET;
663 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
664 attr->ia_atime = CURRENT_TIME;
665 attr->ia_valid |= ATTR_ATIME_SET;
667 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
668 attr->ia_mtime = CURRENT_TIME;
669 attr->ia_valid |= ATTR_MTIME_SET;
672 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
673 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
674 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
675 LTIME_S(CURRENT_TIME));
677 attr->ia_valid &= ~ATTR_SIZE;
679 /* If only OST attributes being set on objects, don't do MDS RPC.
680 * In that case, we need to check permissions and update the local
681 * inode ourselves so we can call obdo_from_inode() always. */
682 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
684 llu_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
686 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
687 attr, NULL, 0, NULL, 0, &request);
690 ptlrpc_req_finished(request);
691 if (rc != -EPERM && rc != -EACCES)
692 CERROR("mdc_setattr fails: rc = %d\n", rc);
696 rc = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0,
697 sbi->ll_osc_exp, &md);
699 ptlrpc_req_finished(request);
703 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
704 * but needed to set timestamps backwards on utime. */
705 inode_setattr(inode, attr);
706 llu_update_inode(inode, md.body, md.lsm);
707 ptlrpc_req_finished(request);
709 if (!md.lsm || !S_ISREG(lli->lli_st_mode)) {
710 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
714 /* The OST doesn't check permissions, but the alternative is
715 * a gratuitous RPC to the MDS. We already rely on the client
716 * to do read/write/truncate permission checks, so is mtime OK?
718 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
719 /* from sys_utime() */
720 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
721 if (current->fsuid != lli->lli_st_uid &&
722 (rc = ll_permission(inode, MAY_WRITE)) != 0)
725 /* from inode_change_ok() */
726 if (current->fsuid != lli->lli_st_uid &&
727 !capable(CAP_FOWNER))
732 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
733 inode_setattr(inode, attr);
736 if (ia_valid & ATTR_SIZE) {
737 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
739 struct lustre_handle lockh = { 0 };
740 int err, ast_flags = 0;
741 /* XXX when we fix the AST intents to pass the discard-range
742 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
744 if (attr->ia_size == 0)
745 ast_flags = LDLM_AST_DISCARD_DATA;
747 rc = llu_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
749 if (rc != ELDLM_OK) {
755 rc = llu_vmtruncate(inode, attr->ia_size);
757 /* unlock now as we don't mind others file lockers racing with
758 * the mds updates below? */
759 err = llu_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
761 CERROR("llu_extent_unlock failed: %d\n", err);
765 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
768 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
769 lli->lli_st_ino, LTIME_S(attr->ia_mtime));
770 oa.o_id = lsm->lsm_object_id;
771 oa.o_valid = OBD_MD_FLID;
772 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
773 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
774 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
776 CERROR("obd_setattr fails: rc=%d\n", rc);
781 /* here we simply act as a thin layer to glue it with
782 * llu_setattr_raw(), which is copy from kernel
784 static int llu_iop_setattr(struct pnode *pno,
787 struct intnl_stat *stbuf)
792 liblustre_wait_event(0);
794 LASSERT(!(mask & ~(SETATTR_MTIME | SETATTR_ATIME |
795 SETATTR_UID | SETATTR_GID |
796 SETATTR_LEN | SETATTR_MODE)));
797 memset(&iattr, 0, sizeof(iattr));
799 if (mask & SETATTR_MODE) {
800 iattr.ia_mode = stbuf->st_mode;
801 iattr.ia_valid |= ATTR_MODE;
803 if (mask & SETATTR_MTIME) {
804 iattr.ia_mtime = stbuf->st_mtime;
805 iattr.ia_valid |= ATTR_MTIME;
807 if (mask & SETATTR_ATIME) {
808 iattr.ia_atime = stbuf->st_atime;
809 iattr.ia_valid |= ATTR_ATIME;
811 if (mask & SETATTR_UID) {
812 iattr.ia_uid = stbuf->st_uid;
813 iattr.ia_valid |= ATTR_UID;
815 if (mask & SETATTR_GID) {
816 iattr.ia_gid = stbuf->st_gid;
817 iattr.ia_valid |= ATTR_GID;
819 if (mask & SETATTR_LEN) {
820 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
821 iattr.ia_valid |= ATTR_SIZE;
824 iattr.ia_valid |= ATTR_RAW;
826 RETURN(llu_setattr_raw(ino, &iattr));
829 #define EXT2_LINK_MAX 32000
831 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
833 struct inode *dir = pno->p_base->pb_parent->pb_ino;
834 struct qstr *qstr = &pno->p_base->pb_name;
835 const char *name = qstr->name;
837 struct ptlrpc_request *request = NULL;
838 struct llu_sb_info *sbi = llu_i2sbi(dir);
839 struct mdc_op_data op_data;
843 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
846 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
847 err = mdc_create(sbi->ll_mdc_exp, &op_data,
848 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
849 current->fsuid, current->fsgid, 0, &request);
850 ptlrpc_req_finished(request);
854 static int llu_readlink_internal(struct inode *inode,
855 struct ptlrpc_request **request,
858 struct llu_inode_info *lli = llu_i2info(inode);
859 struct llu_sb_info *sbi = llu_i2sbi(inode);
861 struct mds_body *body;
862 int rc, symlen = lli->lli_st_size + 1;
867 if (lli->lli_symlink_name) {
868 *symname = lli->lli_symlink_name;
869 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
873 ll_inode2fid(&fid, inode);
874 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
875 OBD_MD_LINKNAME, symlen, request);
877 CERROR("inode %lu: rc = %d\n", lli->lli_st_ino, rc);
881 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
882 LASSERT (body != NULL);
883 LASSERT_REPSWABBED (*request, 0);
885 if ((body->valid & OBD_MD_LINKNAME) == 0) {
886 CERROR ("OBD_MD_LINKNAME not set on reply\n");
887 GOTO (failed, rc = -EPROTO);
890 LASSERT (symlen != 0);
891 if (body->eadatasize != symlen) {
892 CERROR ("inode %lu: symlink length %d not expected %d\n",
893 lli->lli_st_ino, body->eadatasize - 1, symlen - 1);
894 GOTO (failed, rc = -EPROTO);
897 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
898 if (*symname == NULL ||
899 strnlen (*symname, symlen) != symlen - 1) {
900 /* not full/NULL terminated */
901 CERROR ("inode %lu: symlink not NULL terminated string"
902 "of length %d\n", lli->lli_st_ino, symlen - 1);
903 GOTO (failed, rc = -EPROTO);
906 OBD_ALLOC(lli->lli_symlink_name, symlen);
907 /* do not return an error if we cannot cache the symlink locally */
908 if (lli->lli_symlink_name)
909 memcpy(lli->lli_symlink_name, *symname, symlen);
914 ptlrpc_req_finished (*request);
918 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
920 struct inode *inode = pno->p_base->pb_ino;
921 struct ptlrpc_request *request;
926 rc = llu_readlink_internal(inode, &request, &symname);
931 strncpy(data, symname, bufsize);
933 ptlrpc_req_finished(request);
938 static int llu_iop_mknod_raw(struct pnode *pno,
942 struct ptlrpc_request *request = NULL;
943 struct inode *dir = pno->p_parent->p_base->pb_ino;
944 struct llu_sb_info *sbi = llu_i2sbi(dir);
945 struct mdc_op_data op_data;
949 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu\n",
950 pno->p_base->pb_name.name, llu_i2info(dir)->lli_st_ino);
952 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
955 mode &= ~current->fs->umask;
957 switch (mode & S_IFMT) {
960 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
965 llu_prepare_mdc_op_data(&op_data, dir, NULL,
966 pno->p_base->pb_name.name,
967 pno->p_base->pb_name.len,
969 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
970 current->fsuid, current->fsgid, dev, &request);
971 ptlrpc_req_finished(request);
982 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
984 struct inode *src = old->p_base->pb_ino;
985 struct inode *dir = new->p_parent->p_base->pb_ino;
986 const char *name = new->p_base->pb_name.name;
987 int namelen = new->p_base->pb_name.len;
988 struct ptlrpc_request *request = NULL;
989 struct mdc_op_data op_data;
996 liblustre_wait_event(0);
997 llu_prepare_mdc_op_data(&op_data, src, dir, name, namelen, 0);
998 rc = mdc_link(llu_i2sbi(src)->ll_mdc_exp, &op_data, &request);
999 ptlrpc_req_finished(request);
1000 liblustre_wait_event(0);
1006 * libsysio will clear the inode immediately after return
1008 static int llu_iop_unlink_raw(struct pnode *pno)
1010 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1011 struct qstr *qstr = &pno->p_base->pb_name;
1012 const char *name = qstr->name;
1013 int len = qstr->len;
1014 struct inode *target = pno->p_base->pb_ino;
1015 struct ptlrpc_request *request = NULL;
1016 struct mdc_op_data op_data;
1022 liblustre_wait_event(0);
1023 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1024 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1026 rc = llu_objects_destroy(request, dir);
1027 ptlrpc_req_finished(request);
1028 liblustre_wait_event(0);
1033 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
1035 struct inode *src = old->p_parent->p_base->pb_ino;
1036 struct inode *tgt = new->p_parent->p_base->pb_ino;
1037 const char *oldname = old->p_base->pb_name.name;
1038 int oldnamelen = old->p_base->pb_name.len;
1039 const char *newname = new->p_base->pb_name.name;
1040 int newnamelen = new->p_base->pb_name.len;
1041 struct ptlrpc_request *request = NULL;
1042 struct mdc_op_data op_data;
1049 llu_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0);
1050 rc = mdc_rename(llu_i2sbi(src)->ll_mdc_exp, &op_data,
1051 oldname, oldnamelen, newname, newnamelen,
1054 rc = llu_objects_destroy(request, src);
1057 ptlrpc_req_finished(request);
1062 #ifdef _HAVE_STATVFS
1063 static int llu_statfs_internal(struct llu_sb_info *sbi,
1064 struct obd_statfs *osfs,
1065 unsigned long max_age)
1067 struct obd_statfs obd_osfs;
1071 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1073 CERROR("mdc_statfs fails: rc = %d\n", rc);
1077 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1078 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1080 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1082 CERROR("obd_statfs fails: rc = %d\n", rc);
1086 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1087 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1090 osfs->os_blocks = obd_osfs.os_blocks;
1091 osfs->os_bfree = obd_osfs.os_bfree;
1092 osfs->os_bavail = obd_osfs.os_bavail;
1094 /* If we don't have as many objects free on the OST as inodes
1095 * on the MDS, we reduce the total number of inodes to
1096 * compensate, so that the "inodes in use" number is correct.
1098 if (obd_osfs.os_ffree < osfs->os_ffree) {
1099 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1101 osfs->os_ffree = obd_osfs.os_ffree;
1107 static int llu_statfs(struct llu_sb_info *sbi, struct statfs *sfs)
1109 struct obd_statfs osfs;
1112 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1114 /* For now we will always get up-to-date statfs values, but in the
1115 * future we may allow some amount of caching on the client (e.g.
1116 * from QOS or lprocfs updates). */
1117 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1121 statfs_unpack(sfs, &osfs);
1123 if (sizeof(sfs->f_blocks) == 4) {
1124 while (osfs.os_blocks > ~0UL) {
1127 osfs.os_blocks >>= 1;
1128 osfs.os_bfree >>= 1;
1129 osfs.os_bavail >>= 1;
1133 sfs->f_blocks = osfs.os_blocks;
1134 sfs->f_bfree = osfs.os_bfree;
1135 sfs->f_bavail = osfs.os_bavail;
1140 static int llu_iop_statvfs(struct pnode *pno,
1142 struct intnl_statvfs *buf)
1148 liblustre_wait_event(0);
1151 LASSERT(pno->p_base->pb_ino);
1152 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1156 /* from native driver */
1157 buf->f_bsize = fs.f_bsize; /* file system block size */
1158 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1159 buf->f_blocks = fs.f_blocks;
1160 buf->f_bfree = fs.f_bfree;
1161 buf->f_bavail = fs.f_bavail;
1162 buf->f_files = fs.f_files; /* Total number serial numbers */
1163 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1164 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1165 buf->f_fsid = fs.f_fsid.__val[1];
1166 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1167 buf->f_namemax = fs.f_namelen;
1172 #endif /* _HAVE_STATVFS */
1174 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1176 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1177 struct qstr *qstr = &pno->p_base->pb_name;
1178 const char *name = qstr->name;
1179 int len = qstr->len;
1180 struct ptlrpc_request *request = NULL;
1181 struct llu_inode_info *lli = llu_i2info(dir);
1182 struct mdc_op_data op_data;
1185 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1186 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1188 if (lli->lli_st_nlink >= EXT2_LINK_MAX)
1191 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
1192 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1193 err = mdc_create(llu_i2sbi(dir)->ll_mdc_exp, &op_data, NULL, 0, mode,
1194 current->fsuid, current->fsgid, 0, &request);
1195 ptlrpc_req_finished(request);
1199 static int llu_iop_rmdir_raw(struct pnode *pno)
1201 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1202 struct qstr *qstr = &pno->p_base->pb_name;
1203 const char *name = qstr->name;
1204 int len = qstr->len;
1205 struct ptlrpc_request *request = NULL;
1206 struct mdc_op_data op_data;
1207 struct llu_inode_info *lli = llu_i2info(dir);
1210 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu/%lu(%p)\n",
1211 name, lli->lli_st_ino, lli->lli_st_generation, dir);
1213 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, S_IFDIR);
1214 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1215 ptlrpc_req_finished(request);
1221 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC|O_DIRECT)
1223 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC)
1225 #define FCNTL_FLMASK_INVALID (O_NONBLOCK|O_ASYNC)
1227 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn)
1229 struct llu_inode_info *lli = llu_i2info(ino);
1234 *rtn = lli->lli_open_flags;
1237 flags = va_arg(ap, long);
1238 flags &= FCNTL_FLMASK;
1239 if (flags & FCNTL_FLMASK_INVALID) {
1240 CERROR("liblustre don't support O_NONBLOCK, O_ASYNC, "
1241 "and O_DIRECT on file descriptor\n");
1245 lli->lli_open_flags = (int) flags;
1250 CERROR("unsupported fcntl cmd %x\n", cmd);
1255 static int llu_get_grouplock(struct inode *inode, unsigned long arg)
1257 struct llu_inode_info *lli = llu_i2info(inode);
1258 struct ll_file_data *fd = lli->lli_file_data;
1259 ldlm_policy_data_t policy = { .l_extent = { .start = 0,
1260 .end = OBD_OBJECT_EOF}};
1261 struct lustre_handle lockh = { 0 };
1262 struct lov_stripe_md *lsm = lli->lli_smd;
1267 if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
1271 policy.l_extent.gid = arg;
1272 if (lli->lli_open_flags & O_NONBLOCK)
1273 flags = LDLM_FL_BLOCK_NOWAIT;
1275 err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
1280 fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
1282 memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
1287 static int llu_put_grouplock(struct inode *inode, unsigned long arg)
1289 struct llu_inode_info *lli = llu_i2info(inode);
1290 struct ll_file_data *fd = lli->lli_file_data;
1291 struct lov_stripe_md *lsm = lli->lli_smd;
1295 if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
1298 if (fd->fd_gid != arg)
1301 fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
1303 err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
1308 memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
1313 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1318 liblustre_wait_event(0);
1321 case LL_IOC_GROUP_LOCK:
1322 arg = va_arg(ap, unsigned long);
1323 return llu_get_grouplock(ino, arg);
1324 case LL_IOC_GROUP_UNLOCK:
1325 arg = va_arg(ap, unsigned long);
1326 return llu_put_grouplock(ino, arg);
1329 CERROR("did not support ioctl cmd %lx\n", request);
1334 * we already do syncronous read/write
1336 static int llu_iop_sync(struct inode *inode)
1338 liblustre_wait_event(0);
1342 static int llu_iop_datasync(struct inode *inode)
1344 liblustre_wait_event(0);
1348 struct filesys_ops llu_filesys_ops =
1350 fsop_gone: llu_fsop_gone,
1353 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1355 struct inode *inode;
1357 struct file_identifier fileid = {&fid, sizeof(fid)};
1359 if ((md->body->valid &
1360 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1361 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) {
1362 CERROR("bad md body valid mask 0x%x\n", md->body->valid);
1364 return ERR_PTR(-EPERM);
1367 /* try to find existing inode */
1368 fid.id = md->body->ino;
1369 fid.generation = md->body->generation;
1370 fid.f_type = md->body->mode & S_IFMT;
1372 inode = _sysio_i_find(fs, &fileid);
1374 struct llu_inode_info *lli = llu_i2info(inode);
1376 if (inode->i_zombie ||
1377 lli->lli_st_generation != md->body->generation) {
1381 llu_update_inode(inode, md->body, md->lsm);
1386 inode = llu_new_inode(fs, &fid);
1388 llu_update_inode(inode, md->body, md->lsm);
1393 extern struct list_head lustre_profile_list;
1396 llu_fsswop_mount(const char *source,
1398 const void *data __IS_UNUSED,
1399 struct pnode *tocover,
1400 struct mount **mntp)
1404 struct pnode_base *rootpb;
1405 struct obd_device *obd;
1406 struct ll_fid rootfid;
1407 struct llu_sb_info *sbi;
1408 struct obd_statfs osfs;
1409 static struct qstr noname = { NULL, 0, 0 };
1410 struct ptlrpc_request *request = NULL;
1411 struct lustre_handle mdc_conn = {0, };
1412 struct lustre_handle osc_conn = {0, };
1413 struct lustre_md md;
1415 struct config_llog_instance cfg;
1416 struct lustre_profile *lprof;
1417 char *osc = NULL, *mdc = NULL;
1418 int async = 1, err = -EINVAL;
1422 /* allocate & initialize sbi */
1423 OBD_ALLOC(sbi, sizeof(*sbi));
1427 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1428 generate_random_uuid(uuid);
1429 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1431 /* generate a string unique to this super, let's try
1432 the address of the super itself.*/
1433 OBD_ALLOC(sbi->ll_instance, sizeof(sbi) * 2 + 1);
1434 if (sbi->ll_instance == NULL)
1435 GOTO(out_free, err = -ENOMEM);
1436 sprintf(sbi->ll_instance, "%p", sbi);
1438 /* retrive & parse config log */
1439 cfg.cfg_instance = sbi->ll_instance;
1440 cfg.cfg_uuid = sbi->ll_sb_uuid;
1441 err = liblustre_process_log(&cfg, 1);
1443 CERROR("Unable to process log: %s\n", g_zconf_profile);
1444 GOTO(out_free, err);
1447 lprof = class_get_profile(g_zconf_profile);
1448 if (lprof == NULL) {
1449 CERROR("No profile found: %s\n", g_zconf_profile);
1450 GOTO(out_free, err = -EINVAL);
1453 OBD_FREE(osc, strlen(osc) + 1);
1454 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
1455 strlen(sbi->ll_instance) + 2);
1456 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
1459 OBD_FREE(mdc, strlen(mdc) + 1);
1460 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
1461 strlen(sbi->ll_instance) + 2);
1462 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
1466 GOTO(out_free, err = -EINVAL);
1470 GOTO(out_free, err = -EINVAL);
1473 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1479 obd = class_name2obd(mdc);
1481 CERROR("MDC %s: not setup or attached\n", mdc);
1482 GOTO(out_free, err = -EINVAL);
1484 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1485 sizeof(async), &async);
1486 #warning "FIXME ASAP!"
1488 if (mdc_init_ea_size(obd, osc))
1489 GOTO(out_free, err = -EINVAL);
1492 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, 0);
1494 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
1495 GOTO(out_free, err);
1497 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
1499 err = obd_statfs(obd, &osfs, 100000000);
1504 * FIXME fill fs stat data into sbi here!!! FIXME
1508 obd = class_name2obd(osc);
1510 CERROR("OSC %s: not setup or attached\n", osc);
1511 GOTO(out_mdc, err = -EINVAL);
1513 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1514 sizeof(async), &async);
1516 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, 0);
1518 CERROR("cannot connect to %s: rc = %d\n", osc, err);
1521 sbi->ll_osc_exp = class_conn2export(&osc_conn);
1523 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
1525 CERROR("cannot mds_connect: rc = %d\n", err);
1528 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
1529 sbi->ll_rootino = rootfid.id;
1531 /* fetch attr of root inode */
1532 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
1533 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
1535 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1539 err = mdc_req2lustre_md(sbi->ll_mdc_exp, request, 0, sbi->ll_osc_exp,
1542 CERROR("failed to understand root inode md: rc = %d\n",err);
1543 GOTO(out_request, err);
1546 LASSERT(sbi->ll_rootino != 0);
1548 root = llu_iget(fs, &md);
1549 if (!root || IS_ERR(root)) {
1550 CERROR("fail to generate root inode\n");
1551 GOTO(out_request, err = -EBADF);
1555 * Generate base path-node for root.
1557 rootpb = _sysio_pb_new(&noname, NULL, root);
1563 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1565 _sysio_pb_gone(rootpb);
1569 ptlrpc_req_finished(request);
1571 printf("LibLustre: namespace mounted successfully!\n");
1576 _sysio_i_gone(root);
1578 ptlrpc_req_finished(request);
1580 obd_disconnect(sbi->ll_osc_exp, 0);
1582 obd_disconnect(sbi->ll_mdc_exp, 0);
1584 OBD_FREE(sbi, sizeof(*sbi));
1588 struct fssw_ops llu_fssw_ops = {
1592 static struct inode_ops llu_inode_ops = {
1593 inop_lookup: llu_iop_lookup,
1594 inop_getattr: llu_iop_getattr,
1595 inop_setattr: llu_iop_setattr,
1596 inop_getdirentries: llu_iop_getdirentries,
1597 inop_mkdir: llu_iop_mkdir_raw,
1598 inop_rmdir: llu_iop_rmdir_raw,
1599 inop_symlink: llu_iop_symlink_raw,
1600 inop_readlink: llu_iop_readlink,
1601 inop_open: llu_iop_open,
1602 inop_close: llu_iop_close,
1603 inop_link: llu_iop_link_raw,
1604 inop_unlink: llu_iop_unlink_raw,
1605 inop_rename: llu_iop_rename_raw,
1606 inop_pos: llu_iop_pos,
1607 inop_read: llu_iop_read,
1608 inop_write: llu_iop_write,
1609 inop_iodone: llu_iop_iodone,
1610 inop_fcntl: llu_iop_fcntl,
1611 inop_sync: llu_iop_sync,
1612 inop_datasync: llu_iop_datasync,
1613 inop_ioctl: llu_iop_ioctl,
1614 inop_mknod: llu_iop_mknod_raw,
1615 #ifdef _HAVE_STATVFS
1616 inop_statvfs: llu_iop_statvfs,
1618 inop_gone: llu_iop_gone,