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_lmv_exp);
89 struct lustre_cfg lcfg;
93 list_del(&sbi->ll_conn_chain);
94 obd_disconnect(sbi->ll_lov_exp, 0);
95 obd_disconnect(sbi->ll_lmv_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_lmv_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",
143 * updating inode lustre id. We try optimize things a little bit here,
144 * thus do not do it all the time.
146 if (body->valid & OBD_MD_FID)
147 id_assign_fid(&lli->lli_id, &body->id1);
148 if ((body->valid & OBD_MD_FLID) || (body->valid & OBD_MD_FLGENER))
149 id_assign_stc(&lli->lli_id, &body->id1);
150 if (body->valid & OBD_MD_FLID)
151 lli->lli_st_ino = id_ino(&body->id1);
152 if (body->valid & OBD_MD_FLGENER)
153 lli->lli_st_generation = id_gen(&body->id1);
155 if (body->valid & OBD_MD_FLATIME)
156 LTIME_S(lli->lli_st_atime) = body->atime;
157 if (body->valid & OBD_MD_FLMTIME)
158 LTIME_S(lli->lli_st_mtime) = body->mtime;
159 if (body->valid & OBD_MD_FLCTIME)
160 LTIME_S(lli->lli_st_ctime) = body->ctime;
161 if (body->valid & OBD_MD_FLMODE)
162 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT)|(body->mode & ~S_IFMT);
163 if (body->valid & OBD_MD_FLTYPE)
164 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT)|(body->mode & S_IFMT);
165 if (body->valid & OBD_MD_FLUID)
166 lli->lli_st_uid = body->uid;
167 if (body->valid & OBD_MD_FLGID)
168 lli->lli_st_gid = body->gid;
169 if (body->valid & OBD_MD_FLFLAGS)
170 lli->lli_st_flags = body->flags;
171 if (body->valid & OBD_MD_FLNLINK)
172 lli->lli_st_nlink = body->nlink;
173 if (body->valid & OBD_MD_FLRDEV)
174 lli->lli_st_rdev = body->rdev;
175 if (body->valid & OBD_MD_FLSIZE)
176 lli->lli_st_size = body->size;
177 if (body->valid & OBD_MD_FLBLOCKS)
178 lli->lli_st_blocks = body->blocks;
181 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
183 struct llu_inode_info *lli = llu_i2info(dst);
185 valid &= src->o_valid;
187 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
188 CDEBUG(D_INODE, "valid %x, cur time %lu/%lu, new %lu/%lu\n",
190 LTIME_S(lli->lli_st_mtime), LTIME_S(lli->lli_st_ctime),
191 (long)src->o_mtime, (long)src->o_ctime);
193 if (valid & OBD_MD_FLATIME)
194 LTIME_S(lli->lli_st_atime) = src->o_atime;
195 if (valid & OBD_MD_FLMTIME)
196 LTIME_S(lli->lli_st_mtime) = src->o_mtime;
197 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(lli->lli_st_ctime))
198 LTIME_S(lli->lli_st_ctime) = src->o_ctime;
199 if (valid & OBD_MD_FLSIZE)
200 lli->lli_st_size = src->o_size;
201 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
202 lli->lli_st_blocks = src->o_blocks;
203 if (valid & OBD_MD_FLBLKSZ)
204 lli->lli_st_blksize = src->o_blksize;
205 if (valid & OBD_MD_FLTYPE)
206 lli->lli_st_mode = (lli->lli_st_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
207 if (valid & OBD_MD_FLMODE)
208 lli->lli_st_mode = (lli->lli_st_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
209 if (valid & OBD_MD_FLUID)
210 lli->lli_st_uid = src->o_uid;
211 if (valid & OBD_MD_FLGID)
212 lli->lli_st_gid = src->o_gid;
213 if (valid & OBD_MD_FLFLAGS)
214 lli->lli_st_flags = src->o_flags;
215 if (valid & OBD_MD_FLGENER)
216 lli->lli_st_generation = src->o_generation;
219 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
220 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
222 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
224 struct llu_inode_info *lli = llu_i2info(src);
225 obd_flag newvalid = 0;
227 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
228 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
229 valid, LTIME_S(lli->lli_st_mtime),
230 LTIME_S(lli->lli_st_ctime));
232 if (valid & OBD_MD_FLATIME) {
233 dst->o_atime = LTIME_S(lli->lli_st_atime);
234 newvalid |= OBD_MD_FLATIME;
236 if (valid & OBD_MD_FLMTIME) {
237 dst->o_mtime = LTIME_S(lli->lli_st_mtime);
238 newvalid |= OBD_MD_FLMTIME;
240 if (valid & OBD_MD_FLCTIME) {
241 dst->o_ctime = LTIME_S(lli->lli_st_ctime);
242 newvalid |= OBD_MD_FLCTIME;
244 if (valid & OBD_MD_FLSIZE) {
245 dst->o_size = lli->lli_st_size;
246 newvalid |= OBD_MD_FLSIZE;
248 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
249 dst->o_blocks = lli->lli_st_blocks;
250 newvalid |= OBD_MD_FLBLOCKS;
252 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
253 dst->o_blksize = lli->lli_st_blksize;
254 newvalid |= OBD_MD_FLBLKSZ;
256 if (valid & OBD_MD_FLTYPE) {
257 dst->o_mode = (dst->o_mode & S_IALLUGO)|(lli->lli_st_mode & S_IFMT);
258 newvalid |= OBD_MD_FLTYPE;
260 if (valid & OBD_MD_FLMODE) {
261 dst->o_mode = (dst->o_mode & S_IFMT)|(lli->lli_st_mode & S_IALLUGO);
262 newvalid |= OBD_MD_FLMODE;
264 if (valid & OBD_MD_FLUID) {
265 dst->o_uid = lli->lli_st_uid;
266 newvalid |= OBD_MD_FLUID;
268 if (valid & OBD_MD_FLGID) {
269 dst->o_gid = lli->lli_st_gid;
270 newvalid |= OBD_MD_FLGID;
272 if (valid & OBD_MD_FLFLAGS) {
273 dst->o_flags = lli->lli_st_flags;
274 newvalid |= OBD_MD_FLFLAGS;
276 if (valid & OBD_MD_FLGENER) {
277 dst->o_generation = lli->lli_st_generation;
278 newvalid |= OBD_MD_FLGENER;
281 dst->o_valid |= newvalid;
285 * really does the getattr on the inode and updates its fields
287 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
289 struct llu_inode_info *lli = llu_i2info(inode);
290 struct obd_export *exp = llu_i2obdexp(inode);
291 struct ptlrpc_request_set *set;
293 obd_flag refresh_valid;
300 memset(&oa, 0, sizeof oa);
301 oa.o_id = lsm->lsm_object_id;
303 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
304 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
307 set = ptlrpc_prep_set();
309 CERROR ("ENOMEM allocing request set\n");
312 rc = obd_getattr_async(exp, &oa, lsm, set);
314 rc = ptlrpc_set_wait(set);
315 ptlrpc_set_destroy(set);
320 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
321 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
323 /* We set this flag in commit write as we extend the file size. When
324 * the bit is set and the lock is canceled that covers the file size,
325 * we clear the bit. This is enough to protect the window where our
326 * local size extension is needed for writeback. However, it relies on
327 * behaviour that won't be true in the near future. This assumes that
328 * all getattr callers get extent locks, which they currnetly do. It
329 * also assumes that we only send discarding asts for {0,eof} truncates
330 * as is currently the case. This will have to be replaced by the
331 * proper eoc communication between clients and the ost, which is on
333 if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
334 if (oa.o_size < lli->lli_st_size)
335 refresh_valid &= ~OBD_MD_FLSIZE;
337 clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
340 obdo_refresh_inode(inode, &oa, refresh_valid);
345 static struct inode* llu_new_inode(struct filesys *fs,
346 struct lustre_id *id)
349 struct llu_inode_info *lli;
351 OBD_ALLOC(lli, sizeof(*lli));
355 /* initialize lli here */
356 lli->lli_sbi = llu_fs2sbi(fs);
358 lli->lli_symlink_name = NULL;
360 lli->lli_maxbytes = (__u64)(~0UL);
361 lli->lli_file_data = NULL;
363 lli->lli_sysio_fid.fid_data = &lli->lli_id;
364 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_id);
366 memcpy(&lli->lli_id, id, sizeof(*id));
368 /* file identifier is needed by functions like _sysio_i_find() */
369 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
370 #ifndef AUTOMOUNT_FILE_NAME
371 id->li_stc.u.e3s.l3s_type & S_IFMT,
373 id->li_stc.u.e3s.l3s_type, /* all of the bits! */
376 &llu_inode_ops, lli);
379 OBD_FREE(lli, sizeof(*lli));
384 static int llu_have_md_lock(struct inode *inode, __u64 lockpart)
386 struct llu_sb_info *sbi = llu_i2sbi(inode);
387 struct llu_inode_info *lli = llu_i2info(inode);
388 struct lustre_handle lockh;
389 struct ldlm_res_id res_id = { .name = {0} };
390 struct obd_device *obddev;
391 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
397 obddev = sbi->ll_lmv_exp->exp_obd;
398 res_id.name[0] = id_fid(&lli->lli_id);
399 res_id.name[1] = id_group(&lli->lli_id);
401 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
403 /* FIXME use LDLM_FL_TEST_LOCK instead */
404 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
405 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
406 &policy, LCK_PR, &lockh)) {
407 ldlm_lock_decref(&lockh, LCK_PR);
411 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
412 &policy, LCK_PW, &lockh)) {
413 ldlm_lock_decref(&lockh, LCK_PW);
419 static int llu_inode_revalidate(struct inode *inode)
421 struct llu_inode_info *lli = llu_i2info(inode);
422 struct lov_stripe_md *lsm = NULL;
426 CERROR("REPORT THIS LINE TO PETER\n");
430 if (!llu_have_md_lock(inode, MDS_INODELOCK_UPDATE)) {
432 struct ptlrpc_request *req = NULL;
433 struct llu_sb_info *sbi = llu_i2sbi(inode);
435 unsigned long valid = 0;
438 /* Why don't we update all valid MDS fields here, if we're doing
439 * an RPC anyways? -phil */
440 if (S_ISREG(lli->lli_st_mode)) {
441 ealen = obd_size_diskmd(sbi->ll_lov_exp, NULL);
442 valid |= OBD_MD_FLEASIZE;
444 ll_inode2id(&id, inode);
445 rc = mdc_getattr(sbi->ll_lmv_exp, &id, valid, ealen, &req);
447 CERROR("failure %d inode %lu\n", rc, lli->lli_st_ino);
450 rc = mdc_req2lustre_md(sbi->ll_lmv_exp, req, 0,
451 sbi->ll_lov_exp, &md);
453 /* XXX Too paranoid? */
454 if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) &&
455 !((md.body->valid & OBD_MD_FLNLINK) &&
456 (md.body->nlink == 0))) {
457 CERROR("Asked for %s eadata but got %s (%d)\n",
458 (valid & OBD_MD_FLEASIZE) ? "some" : "no",
459 (md.body->valid & OBD_MD_FLEASIZE) ? "some":"none",
460 md.body->eadatasize);
463 ptlrpc_req_finished(req);
468 llu_update_inode(inode, md.body, md.lsm);
469 if (md.lsm != NULL && llu_i2info(inode)->lli_smd != md.lsm)
470 obd_free_memmd(sbi->ll_lov_exp, &md.lsm);
472 if (md.body->valid & OBD_MD_FLSIZE)
473 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
474 &llu_i2info(inode)->lli_flags);
475 ptlrpc_req_finished(req);
478 lsm = llu_i2info(inode)->lli_smd;
479 if (!lsm) /* object not yet allocated, don't validate size */
482 /* ll_glimpse_size will prefer locally cached writes if they extend
484 RETURN(llu_glimpse_size(inode));
487 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
489 struct llu_inode_info *lli = llu_i2info(ino);
491 b->st_dev = lli->lli_st_dev;
492 b->st_ino = lli->lli_st_ino;
493 b->st_mode = lli->lli_st_mode;
494 b->st_nlink = lli->lli_st_nlink;
495 b->st_uid = lli->lli_st_uid;
496 b->st_gid = lli->lli_st_gid;
497 b->st_rdev = lli->lli_st_rdev;
498 b->st_size = lli->lli_st_size;
499 b->st_blksize = lli->lli_st_blksize;
500 b->st_blocks = lli->lli_st_blocks;
501 b->st_atime = lli->lli_st_atime;
502 b->st_mtime = lli->lli_st_mtime;
503 b->st_ctime = lli->lli_st_ctime;
506 static int llu_iop_getattr(struct pnode *pno,
508 struct intnl_stat *b)
513 liblustre_wait_event(0);
517 LASSERT(pno->p_base->pb_ino);
518 ino = pno->p_base->pb_ino;
520 LASSERT(!pno || pno->p_base->pb_ino == ino);
523 /* libsysio might call us directly without intent lock,
524 * we must re-fetch the attrs here
526 rc = llu_inode_revalidate(ino);
528 copy_stat_buf(ino, b);
529 LASSERT(!llu_i2info(ino)->lli_it);
535 static int null_if_equal(struct ldlm_lock *lock, void *data)
537 if (data == lock->l_ast_data) {
538 lock->l_ast_data = NULL;
540 if (lock->l_req_mode != lock->l_granted_mode)
541 LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
544 return LDLM_ITER_CONTINUE;
547 void llu_clear_inode(struct inode *inode)
550 struct llu_inode_info *lli = llu_i2info(inode);
551 struct llu_sb_info *sbi = llu_i2sbi(inode);
554 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu(%p)\n", lli->lli_st_ino,
555 lli->lli_st_generation, inode);
557 ll_inode2id(&id, inode);
558 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
559 mdc_change_cbdata(sbi->ll_lmv_exp, &id, null_if_equal, inode);
562 obd_change_cbdata(sbi->ll_lov_exp, lli->lli_smd,
563 null_if_equal, inode);
566 obd_free_memmd(sbi->ll_lov_exp, &lli->lli_smd);
570 if (lli->lli_symlink_name) {
571 OBD_FREE(lli->lli_symlink_name,
572 strlen(lli->lli_symlink_name) + 1);
573 lli->lli_symlink_name = NULL;
579 void llu_iop_gone(struct inode *inode)
581 struct llu_inode_info *lli = llu_i2info(inode);
584 liblustre_wait_event(0);
585 llu_clear_inode(inode);
587 OBD_FREE(lli, sizeof(*lli));
591 static int inode_setattr(struct inode * inode, struct iattr * attr)
593 unsigned int ia_valid = attr->ia_valid;
594 struct llu_inode_info *lli = llu_i2info(inode);
597 if (ia_valid & ATTR_SIZE) {
598 error = llu_vmtruncate(inode, attr->ia_size);
603 if (ia_valid & ATTR_UID)
604 lli->lli_st_uid = attr->ia_uid;
605 if (ia_valid & ATTR_GID)
606 lli->lli_st_gid = attr->ia_gid;
607 if (ia_valid & ATTR_ATIME)
608 lli->lli_st_atime = attr->ia_atime;
609 if (ia_valid & ATTR_MTIME)
610 lli->lli_st_mtime = attr->ia_mtime;
611 if (ia_valid & ATTR_CTIME)
612 lli->lli_st_ctime = attr->ia_ctime;
613 if (ia_valid & ATTR_MODE) {
614 lli->lli_st_mode = attr->ia_mode;
615 if (!in_group_p(lli->lli_st_gid) && !capable(CAP_FSETID))
616 lli->lli_st_mode &= ~S_ISGID;
618 /* mark_inode_dirty(inode); */
623 /* If this inode has objects allocated to it (lsm != NULL), then the OST
624 * object(s) determine the file size and mtime. Otherwise, the MDS will
625 * keep these values until such a time that objects are allocated for it.
626 * We do the MDS operations first, as it is checking permissions for us.
627 * We don't to the MDS RPC if there is nothing that we want to store there,
628 * otherwise there is no harm in updating mtime/atime on the MDS if we are
629 * going to do an RPC anyways.
631 * If we are doing a truncate, we will send the mtime and ctime updates
632 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
633 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
636 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
638 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
639 struct llu_sb_info *sbi = llu_i2sbi(inode);
640 struct llu_inode_info *lli = llu_i2info(inode);
641 struct ptlrpc_request *request = NULL;
642 struct mdc_op_data op_data;
643 int ia_valid = attr->ia_valid;
647 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
649 if (ia_valid & ATTR_SIZE) {
650 if (attr->ia_size > ll_file_maxbytes(inode)) {
651 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
652 attr->ia_size, ll_file_maxbytes(inode));
656 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
659 /* We mark all of the fields "set" so MDS/OST does not re-set them */
660 if (attr->ia_valid & ATTR_CTIME) {
661 attr->ia_ctime = CURRENT_TIME;
662 attr->ia_valid |= ATTR_CTIME_SET;
664 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
665 attr->ia_atime = CURRENT_TIME;
666 attr->ia_valid |= ATTR_ATIME_SET;
668 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
669 attr->ia_mtime = CURRENT_TIME;
670 attr->ia_valid |= ATTR_MTIME_SET;
673 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
674 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
675 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
676 LTIME_S(CURRENT_TIME));
678 attr->ia_valid &= ~ATTR_SIZE;
680 /* If only OST attributes being set on objects, don't do MDS RPC.
681 * In that case, we need to check permissions and update the local
682 * inode ourselves so we can call obdo_from_inode() always. */
683 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
685 llu_prepare_mdc_data(&op_data, inode, NULL, NULL, 0, 0);
687 rc = mdc_setattr(sbi->ll_lmv_exp, &op_data,
688 attr, NULL, 0, NULL, 0, &request);
691 ptlrpc_req_finished(request);
692 if (rc != -EPERM && rc != -EACCES)
693 CERROR("mdc_setattr fails: rc = %d\n", rc);
697 rc = mdc_req2lustre_md(sbi->ll_lmv_exp, request, 0,
698 sbi->ll_lov_exp, &md);
700 ptlrpc_req_finished(request);
704 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
705 * but needed to set timestamps backwards on utime. */
706 inode_setattr(inode, attr);
707 llu_update_inode(inode, md.body, md.lsm);
708 ptlrpc_req_finished(request);
710 if (!md.lsm || !S_ISREG(lli->lli_st_mode)) {
711 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
715 /* The OST doesn't check permissions, but the alternative is
716 * a gratuitous RPC to the MDS. We already rely on the client
717 * to do read/write/truncate permission checks, so is mtime OK?
719 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
720 /* from sys_utime() */
721 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
722 if (current->fsuid != lli->lli_st_uid &&
723 (rc = ll_permission(inode, MAY_WRITE)) != 0)
726 /* from inode_change_ok() */
727 if (current->fsuid != lli->lli_st_uid &&
728 !capable(CAP_FOWNER))
733 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
734 inode_setattr(inode, attr);
737 if (ia_valid & ATTR_SIZE) {
738 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
740 struct lustre_handle lockh = { 0 };
741 int err, ast_flags = 0;
742 /* XXX when we fix the AST intents to pass the discard-range
743 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
745 if (attr->ia_size == 0)
746 ast_flags = LDLM_AST_DISCARD_DATA;
748 rc = llu_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
750 if (rc != ELDLM_OK) {
756 rc = llu_vmtruncate(inode, attr->ia_size);
758 /* unlock now as we don't mind others file lockers racing with
759 * the mds updates below? */
760 err = llu_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
762 CERROR("llu_extent_unlock failed: %d\n", err);
766 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
769 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
770 lli->lli_st_ino, LTIME_S(attr->ia_mtime));
771 oa.o_id = lsm->lsm_object_id;
772 oa.o_valid = OBD_MD_FLID;
773 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
774 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
775 rc = obd_setattr(sbi->ll_lov_exp, &oa, lsm, NULL);
777 CERROR("obd_setattr fails: rc=%d\n", rc);
782 /* here we simply act as a thin layer to glue it with
783 * llu_setattr_raw(), which is copy from kernel
785 static int llu_iop_setattr(struct pnode *pno,
788 struct intnl_stat *stbuf)
793 liblustre_wait_event(0);
795 LASSERT(!(mask & ~(SETATTR_MTIME | SETATTR_ATIME |
796 SETATTR_UID | SETATTR_GID |
797 SETATTR_LEN | SETATTR_MODE)));
798 memset(&iattr, 0, sizeof(iattr));
800 if (mask & SETATTR_MODE) {
801 iattr.ia_mode = stbuf->st_mode;
802 iattr.ia_valid |= ATTR_MODE;
804 if (mask & SETATTR_MTIME) {
805 iattr.ia_mtime = stbuf->st_mtime;
806 iattr.ia_valid |= ATTR_MTIME;
808 if (mask & SETATTR_ATIME) {
809 iattr.ia_atime = stbuf->st_atime;
810 iattr.ia_valid |= ATTR_ATIME;
812 if (mask & SETATTR_UID) {
813 iattr.ia_uid = stbuf->st_uid;
814 iattr.ia_valid |= ATTR_UID;
816 if (mask & SETATTR_GID) {
817 iattr.ia_gid = stbuf->st_gid;
818 iattr.ia_valid |= ATTR_GID;
820 if (mask & SETATTR_LEN) {
821 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
822 iattr.ia_valid |= ATTR_SIZE;
825 iattr.ia_valid |= ATTR_RAW;
827 RETURN(llu_setattr_raw(ino, &iattr));
830 #define EXT2_LINK_MAX 32000
832 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
834 struct inode *dir = pno->p_base->pb_parent->pb_ino;
835 struct qstr *qstr = &pno->p_base->pb_name;
836 const char *name = qstr->name;
838 struct ptlrpc_request *request = NULL;
839 struct llu_sb_info *sbi = llu_i2sbi(dir);
840 struct mdc_op_data op_data;
844 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
847 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, 0);
848 err = mdc_create(sbi->ll_lmv_exp, &op_data,
849 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
850 current->fsuid, current->fsgid, 0, &request);
851 ptlrpc_req_finished(request);
855 static int llu_readlink_internal(struct inode *inode,
856 struct ptlrpc_request **request,
859 struct llu_inode_info *lli = llu_i2info(inode);
860 struct llu_sb_info *sbi = llu_i2sbi(inode);
862 struct mds_body *body;
863 int rc, symlen = lli->lli_st_size + 1;
868 if (lli->lli_symlink_name) {
869 *symname = lli->lli_symlink_name;
870 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
874 ll_inode2id(&id, inode);
875 rc = mdc_getattr(sbi->ll_lmv_exp, &id,
876 OBD_MD_LINKNAME, symlen, request);
878 CERROR("inode %lu: rc = %d\n", lli->lli_st_ino, rc);
882 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
883 LASSERT (body != NULL);
884 LASSERT_REPSWABBED (*request, 0);
886 if ((body->valid & OBD_MD_LINKNAME) == 0) {
887 CERROR ("OBD_MD_LINKNAME not set on reply\n");
888 GOTO (failed, rc = -EPROTO);
891 LASSERT (symlen != 0);
892 if (body->eadatasize != symlen) {
893 CERROR ("inode %lu: symlink length %d not expected %d\n",
894 lli->lli_st_ino, body->eadatasize - 1, symlen - 1);
895 GOTO (failed, rc = -EPROTO);
898 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
899 if (*symname == NULL ||
900 strnlen (*symname, symlen) != symlen - 1) {
901 /* not full/NULL terminated */
902 CERROR ("inode %lu: symlink not NULL terminated string"
903 "of length %d\n", lli->lli_st_ino, symlen - 1);
904 GOTO (failed, rc = -EPROTO);
907 OBD_ALLOC(lli->lli_symlink_name, symlen);
908 /* do not return an error if we cannot cache the symlink locally */
909 if (lli->lli_symlink_name)
910 memcpy(lli->lli_symlink_name, *symname, symlen);
915 ptlrpc_req_finished (*request);
919 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
921 struct inode *inode = pno->p_base->pb_ino;
922 struct ptlrpc_request *request;
927 rc = llu_readlink_internal(inode, &request, &symname);
932 strncpy(data, symname, bufsize);
934 ptlrpc_req_finished(request);
939 static int llu_iop_mknod_raw(struct pnode *pno,
943 struct ptlrpc_request *request = NULL;
944 struct inode *dir = pno->p_parent->p_base->pb_ino;
945 struct llu_sb_info *sbi = llu_i2sbi(dir);
946 struct mdc_op_data op_data;
950 CDEBUG(D_VFSTRACE, "VFS Op:name=%s,dir=%lu\n",
951 pno->p_base->pb_name.name, llu_i2info(dir)->lli_st_ino);
953 if (llu_i2info(dir)->lli_st_nlink >= EXT2_LINK_MAX)
956 mode &= ~current->fs->umask;
958 switch (mode & S_IFMT) {
961 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
966 llu_prepare_mdc_data(&op_data, dir, NULL,
967 pno->p_base->pb_name.name,
968 pno->p_base->pb_name.len,
970 err = mdc_create(sbi->ll_lmv_exp, &op_data, NULL, 0, mode,
971 current->fsuid, current->fsgid, dev, &request);
972 ptlrpc_req_finished(request);
983 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
985 struct inode *src = old->p_base->pb_ino;
986 struct inode *dir = new->p_parent->p_base->pb_ino;
987 const char *name = new->p_base->pb_name.name;
988 int namelen = new->p_base->pb_name.len;
989 struct ptlrpc_request *request = NULL;
990 struct mdc_op_data op_data;
997 liblustre_wait_event(0);
998 llu_prepare_mdc_data(&op_data, src, dir, name, namelen, 0);
999 rc = mdc_link(llu_i2sbi(src)->ll_lmv_exp, &op_data, &request);
1000 ptlrpc_req_finished(request);
1001 liblustre_wait_event(0);
1007 * libsysio will clear the inode immediately after return
1009 static int llu_iop_unlink_raw(struct pnode *pno)
1011 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1012 struct qstr *qstr = &pno->p_base->pb_name;
1013 const char *name = qstr->name;
1014 int len = qstr->len;
1015 struct inode *target = pno->p_base->pb_ino;
1016 struct ptlrpc_request *request = NULL;
1017 struct mdc_op_data op_data;
1023 liblustre_wait_event(0);
1024 llu_prepare_mdc_data(&op_data, dir, NULL, name, len, 0);
1025 rc = mdc_unlink(llu_i2sbi(dir)->ll_lmv_exp, &op_data, &request);
1027 rc = llu_objects_destroy(request, dir);
1028 ptlrpc_req_finished(request);
1029 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_data(&op_data, src, tgt, NULL, 0, 0);
1050 rc = mdc_rename(llu_i2sbi(src)->ll_lmv_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_lmv_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_lov_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_fstc.__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_data(&op_data, dir, NULL, name, len, 0);
1193 err = mdc_create(llu_i2sbi(dir)->ll_lmv_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_data(&op_data, dir, NULL, name, len, S_IFDIR);
1214 rc = mdc_unlink(llu_i2sbi(dir)->ll_lmv_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 does not 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;
1356 struct lustre_id id;
1357 struct file_identifier fileid = {&id, sizeof(id)};
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);
1369 /* try to find existing inode */
1370 inode = _sysio_i_find(fs, &fileid);
1372 struct llu_inode_info *lli = llu_i2info(inode);
1374 if (inode->i_zombie ||
1375 lli->lli_st_generation != id_gen(&md->body->id1)) {
1379 llu_update_inode(inode, md->body, md->lsm);
1384 inode = llu_new_inode(fs, &id);
1386 llu_update_inode(inode, md->body, md->lsm);
1392 llu_fsswop_mount(const char *source,
1394 const void *data __IS_UNUSED,
1395 struct pnode *tocover,
1396 struct mount **mntp)
1400 struct pnode_base *rootpb;
1401 struct obd_device *obd;
1402 struct lustre_id rootid;
1403 struct llu_sb_info *sbi;
1404 struct obd_statfs osfs;
1405 static struct qstr noname = { NULL, 0, 0 };
1406 struct ptlrpc_request *request = NULL;
1407 struct lustre_handle lmv_conn = {0, };
1408 struct lustre_handle lov_conn = {0, };
1409 struct lustre_md md;
1411 struct config_llog_instance cfg;
1412 struct lustre_profile *lprof;
1413 char *lov = NULL, *lmv = NULL;
1414 int async = 1, err = -EINVAL;
1418 /* allocate & initialize sbi */
1419 OBD_ALLOC(sbi, sizeof(*sbi));
1423 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1424 generate_random_uuid(uuid);
1425 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1427 /* generate a string unique to this super, let's try
1428 the address of the super itself.*/
1429 OBD_ALLOC(sbi->ll_instance, sizeof(sbi) * 2 + 1);
1430 if (sbi->ll_instance == NULL)
1431 GOTO(out_free, err = -ENOMEM);
1432 sprintf(sbi->ll_instance, "%p", sbi);
1434 /* retrive & parse config log */
1435 cfg.cfg_instance = sbi->ll_instance;
1436 cfg.cfg_uuid = sbi->ll_sb_uuid;
1437 err = liblustre_process_log(&cfg, 1);
1439 CERROR("Unable to process log: %s\n", g_zconf_profile);
1440 GOTO(out_free, err);
1443 lprof = class_get_profile(g_zconf_profile);
1444 if (lprof == NULL) {
1445 CERROR("No profile found: %s\n", g_zconf_profile);
1446 GOTO(out_free, err = -EINVAL);
1449 OBD_FREE(lov, strlen(lov) + 1);
1450 OBD_ALLOC(lov, strlen(lprof->lp_lov) +
1451 strlen(sbi->ll_instance) + 2);
1452 sprintf(lov, "%s-%s", lprof->lp_lov, sbi->ll_instance);
1455 OBD_FREE(lmv, strlen(lmv) + 1);
1456 OBD_ALLOC(lmv, strlen(lprof->lp_lmv) +
1457 strlen(sbi->ll_instance) + 2);
1458 sprintf(lmv, "%s-%s", lprof->lp_lmv, sbi->ll_instance);
1462 GOTO(out_free, err = -EINVAL);
1466 GOTO(out_free, err = -EINVAL);
1469 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1475 obd = class_name2obd(lmv);
1477 CERROR("MDC %s: not setup or attached\n", lmv);
1478 GOTO(out_free, err = -EINVAL);
1480 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1481 sizeof(async), &async);
1482 #warning "FIXME ASAP!"
1484 if (mdc_init_ea_size(obd, lov))
1485 GOTO(out_free, err = -EINVAL);
1488 err = obd_connect(&lmv_conn, obd, &sbi->ll_sb_uuid, 0);
1490 CERROR("cannot connect to %s: rc = %d\n", lmv, err);
1491 GOTO(out_free, err);
1493 sbi->ll_lmv_exp = class_conn2export(&lmv_conn);
1495 err = obd_statfs(obd, &osfs, 100000000);
1500 * FIXME fill fs stat data into sbi here!!! FIXME
1504 obd = class_name2obd(lov);
1506 CERROR("OSC %s: not setup or attached\n", lov);
1507 GOTO(out_lmv, err = -EINVAL);
1509 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1510 sizeof(async), &async);
1512 err = obd_connect(&lov_conn, obd, &sbi->ll_sb_uuid, 0);
1514 CERROR("cannot connect to %s: rc = %d\n", lov, err);
1517 sbi->ll_lov_exp = class_conn2export(&lov_conn);
1519 err = mdc_getstatus(sbi->ll_lmv_exp, &rootid);
1521 CERROR("cannot mds_connect: rc = %d\n", err);
1524 CDEBUG(D_SUPER, "rootid "LPU64"\n", rootid.li_stc.u.e3s.l3s_ino);
1525 sbi->ll_rootino = rootid.li_stc.u.e3s.l3s_ino;
1527 /* fetch attr of root inode */
1528 err = mdc_getattr(sbi->ll_lmv_exp, &rootid,
1529 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
1531 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1535 err = mdc_req2lustre_md(sbi->ll_lmv_exp, request, 0,
1536 sbi->ll_lov_exp, &md);
1538 CERROR("failed to understand root inode md: rc = %d\n",err);
1539 GOTO(out_request, err);
1542 LASSERT(sbi->ll_rootino != 0);
1544 root = llu_iget(fs, &md);
1545 if (!root || IS_ERR(root)) {
1546 CERROR("fail to generate root inode\n");
1547 GOTO(out_request, err = -EBADF);
1551 * Generate base path-node for root.
1553 rootpb = _sysio_pb_new(&noname, NULL, root);
1559 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1561 _sysio_pb_gone(rootpb);
1565 ptlrpc_req_finished(request);
1567 printf("LibLustre: namespace mounted successfully!\n");
1572 _sysio_i_gone(root);
1574 ptlrpc_req_finished(request);
1576 obd_disconnect(sbi->ll_lov_exp, 0);
1578 obd_disconnect(sbi->ll_lmv_exp, 0);
1580 OBD_FREE(sbi, sizeof(*sbi));
1584 struct fssw_ops llu_fssw_ops = {
1588 struct inode_ops llu_inode_ops = {
1589 .inop_lookup = llu_iop_lookup,
1590 .inop_getattr = llu_iop_getattr,
1591 .inop_setattr = llu_iop_setattr,
1592 .inop_getdirentries = llu_iop_getdirentries,
1593 .inop_mkdir = llu_iop_mkdir_raw,
1594 .inop_rmdir = llu_iop_rmdir_raw,
1595 .inop_symlink = llu_iop_symlink_raw,
1596 .inop_readlink = llu_iop_readlink,
1597 .inop_open = llu_iop_open,
1598 .inop_close = llu_iop_close,
1599 .inop_link = llu_iop_link_raw,
1600 .inop_unlink = llu_iop_unlink_raw,
1601 .inop_rename = llu_iop_rename_raw,
1602 .inop_iodone = llu_iop_iodone,
1603 .inop_fcntl = llu_iop_fcntl,
1604 .inop_sync = llu_iop_sync,
1605 .inop_read = llu_iop_read,
1606 .inop_write = llu_iop_write,
1607 .inop_datasync = llu_iop_datasync,
1608 .inop_ioctl = llu_iop_ioctl,
1609 .inop_mknod = llu_iop_mknod_raw,
1610 #ifdef _HAVE_STATVFS
1611 .inop_statvfs = llu_iop_statvfs,
1613 .inop_gone = llu_iop_gone,