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>
33 #include <sys/queue.h>
35 # include <sys/statvfs.h>
37 # include <sys/statfs.h>
53 #include "llite_lib.h"
61 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
63 static int ll_permission(struct inode *inode, int mask)
65 struct intnl_stat *st = llu_i2stat(inode);
66 mode_t mode = st->st_mode;
68 if (current->fsuid == st->st_uid)
70 else if (in_group_p(st->st_gid))
73 if ((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask)
76 if ((mask & (MAY_READ|MAY_WRITE)) ||
77 (st->st_mode & S_IXUGO))
78 if (capable(CAP_DAC_OVERRIDE))
81 if (mask == MAY_READ ||
82 (S_ISDIR(st->st_mode) && !(mask & MAY_WRITE))) {
83 if (capable(CAP_DAC_READ_SEARCH))
90 static void llu_fsop_gone(struct filesys *fs)
92 struct llu_sb_info *sbi = (struct llu_sb_info *) fs->fs_private;
93 struct obd_device *obd = class_exp2obd(sbi->ll_md_exp);
97 list_del(&sbi->ll_conn_chain);
98 obd_disconnect(sbi->ll_dt_exp);
99 obd_disconnect(sbi->ll_md_exp);
101 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL){
102 struct lustre_cfg_bufs bufs;
103 struct lustre_cfg *lcfg;
106 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
107 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
108 err = class_process_config(lcfg);
109 lustre_cfg_free(lcfg);
111 CERROR("cleanup failed: %s\n", obd->obd_name);
113 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
114 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
115 err = class_process_config(lcfg);
117 CERROR("detach failed: %s\n", obd->obd_name);
120 OBD_FREE(sbi, sizeof(*sbi));
125 static struct inode_ops llu_inode_ops;
127 void llu_update_inode(struct inode *inode, struct mdt_body *body,
128 struct lov_stripe_md *lsm)
130 struct llu_inode_info *lli = llu_i2info(inode);
131 struct intnl_stat *st = llu_i2stat(inode);
133 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
135 if (lli->lli_smd == NULL) {
137 lli->lli_maxbytes = lsm->lsm_maxbytes;
138 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
139 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
141 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
142 CERROR("lsm mismatch for inode %lld\n",
143 (long long)st->st_ino);
149 if (body->valid & OBD_MD_FLMTIME &&
150 body->mtime > LTIME_S(st->st_mtime))
151 LTIME_S(st->st_mtime) = body->mtime;
152 if (body->valid & OBD_MD_FLATIME &&
153 body->atime > LTIME_S(st->st_atime))
154 LTIME_S(st->st_atime) = body->atime;
155 if (body->valid & OBD_MD_FLCTIME &&
156 body->ctime > LTIME_S(st->st_ctime))
157 LTIME_S(st->st_ctime) = body->ctime;
158 if (body->valid & OBD_MD_FLMODE)
159 st->st_mode = (st->st_mode & S_IFMT)|(body->mode & ~S_IFMT);
160 if (body->valid & OBD_MD_FLTYPE)
161 st->st_mode = (st->st_mode & ~S_IFMT)|(body->mode & S_IFMT);
162 if (S_ISREG(st->st_mode))
163 st->st_blksize = min(2UL * PTLRPC_MAX_BRW_SIZE, LL_MAX_BLKSIZE);
165 st->st_blksize = 4096;
166 if (body->valid & OBD_MD_FLUID)
167 st->st_uid = body->uid;
168 if (body->valid & OBD_MD_FLGID)
169 st->st_gid = body->gid;
170 if (body->valid & OBD_MD_FLNLINK)
171 st->st_nlink = body->nlink;
172 if (body->valid & OBD_MD_FLRDEV)
173 st->st_rdev = body->rdev;
174 if (body->valid & OBD_MD_FLSIZE)
175 st->st_size = body->size;
176 if (body->valid & OBD_MD_FLBLOCKS)
177 st->st_blocks = body->blocks;
178 if (body->valid & OBD_MD_FLFLAGS)
179 lli->lli_st_flags = body->flags;
182 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
184 struct llu_inode_info *lli = llu_i2info(dst);
185 struct intnl_stat *st = llu_i2stat(dst);
187 valid &= src->o_valid;
189 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
190 CDEBUG(D_INODE,"valid "LPX64", cur time %lu/%lu, new %lu/%lu\n",
192 LTIME_S(st->st_mtime), LTIME_S(st->st_ctime),
193 (long)src->o_mtime, (long)src->o_ctime);
195 if (valid & OBD_MD_FLATIME)
196 LTIME_S(st->st_atime) = src->o_atime;
197 if (valid & OBD_MD_FLMTIME)
198 LTIME_S(st->st_mtime) = src->o_mtime;
199 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(st->st_ctime))
200 LTIME_S(st->st_ctime) = src->o_ctime;
201 if (valid & OBD_MD_FLSIZE)
202 st->st_size = src->o_size;
203 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
204 st->st_blocks = src->o_blocks;
205 if (valid & OBD_MD_FLBLKSZ)
206 st->st_blksize = src->o_blksize;
207 if (valid & OBD_MD_FLTYPE)
208 st->st_mode = (st->st_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
209 if (valid & OBD_MD_FLMODE)
210 st->st_mode = (st->st_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
211 if (valid & OBD_MD_FLUID)
212 st->st_uid = src->o_uid;
213 if (valid & OBD_MD_FLGID)
214 st->st_gid = src->o_gid;
215 if (valid & OBD_MD_FLFLAGS)
216 lli->lli_st_flags = src->o_flags;
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 struct intnl_stat *st = llu_i2stat(src);
226 obd_flag newvalid = 0;
228 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
229 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
230 valid, LTIME_S(st->st_mtime),
231 LTIME_S(st->st_ctime));
233 if (valid & OBD_MD_FLATIME) {
234 dst->o_atime = LTIME_S(st->st_atime);
235 newvalid |= OBD_MD_FLATIME;
237 if (valid & OBD_MD_FLMTIME) {
238 dst->o_mtime = LTIME_S(st->st_mtime);
239 newvalid |= OBD_MD_FLMTIME;
241 if (valid & OBD_MD_FLCTIME) {
242 dst->o_ctime = LTIME_S(st->st_ctime);
243 newvalid |= OBD_MD_FLCTIME;
245 if (valid & OBD_MD_FLSIZE) {
246 dst->o_size = st->st_size;
247 newvalid |= OBD_MD_FLSIZE;
249 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
250 dst->o_blocks = st->st_blocks;
251 newvalid |= OBD_MD_FLBLOCKS;
253 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
254 dst->o_blksize = st->st_blksize;
255 newvalid |= OBD_MD_FLBLKSZ;
257 if (valid & OBD_MD_FLTYPE) {
258 dst->o_mode = (dst->o_mode & S_IALLUGO)|(st->st_mode & S_IFMT);
259 newvalid |= OBD_MD_FLTYPE;
261 if (valid & OBD_MD_FLMODE) {
262 dst->o_mode = (dst->o_mode & S_IFMT)|(st->st_mode & S_IALLUGO);
263 newvalid |= OBD_MD_FLMODE;
265 if (valid & OBD_MD_FLUID) {
266 dst->o_uid = st->st_uid;
267 newvalid |= OBD_MD_FLUID;
269 if (valid & OBD_MD_FLGID) {
270 dst->o_gid = st->st_gid;
271 newvalid |= OBD_MD_FLGID;
273 if (valid & OBD_MD_FLFLAGS) {
274 dst->o_flags = lli->lli_st_flags;
275 newvalid |= OBD_MD_FLFLAGS;
277 if (valid & OBD_MD_FLGENER) {
278 dst->o_generation = lli->lli_st_generation;
279 newvalid |= OBD_MD_FLGENER;
281 if (valid & OBD_MD_FLFID) {
282 dst->o_fid = st->st_ino;
283 newvalid |= OBD_MD_FLFID;
286 dst->o_valid |= newvalid;
290 * really does the getattr on the inode and updates its fields
292 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
294 struct llu_inode_info *lli = llu_i2info(inode);
295 struct obd_export *exp = llu_i2obdexp(inode);
296 struct ptlrpc_request_set *set;
298 obd_flag refresh_valid;
305 memset(&oa, 0, sizeof oa);
306 oa.o_id = lsm->lsm_object_id;
308 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
309 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
312 set = ptlrpc_prep_set();
314 CERROR ("ENOMEM allocing request set\n");
317 rc = obd_getattr_async(exp, &oa, lsm, set);
319 rc = ptlrpc_set_wait(set);
320 ptlrpc_set_destroy(set);
325 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
326 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
328 obdo_refresh_inode(inode, &oa, refresh_valid);
333 static struct inode* llu_new_inode(struct filesys *fs,
337 struct llu_inode_info *lli;
338 struct intnl_stat st = {
341 #ifndef AUTOMOUNT_FILE_NAME
342 .st_mode = fid->f_type & S_IFMT,
344 .st_mode = fid->f_type /* all of the bits! */
347 /* FIXME: fix this later */
354 OBD_ALLOC(lli, sizeof(*lli));
358 /* initialize lli here */
359 lli->lli_sbi = llu_fs2sbi(fs);
361 lli->lli_symlink_name = NULL;
363 lli->lli_maxbytes = (__u64)(~0UL);
364 lli->lli_file_data = NULL;
366 lli->lli_sysio_fid.fid_data = &lli->lli_fid;
367 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_fid);
370 /* file identifier is needed by functions like _sysio_i_find() */
371 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
372 &st, 0, &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] = fid_seq(&lli->lli_fid);
395 res_id.name[1] = fid_oid(&lli->lli_fid);
396 res_id.name[2] = fid_ver(&lli->lli_fid);
398 CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
400 /* FIXME use LDLM_FL_TEST_LOCK instead */
401 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
402 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
403 &policy, LCK_PR, &lockh)) {
404 ldlm_lock_decref(&lockh, LCK_PR);
408 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_IBITS,
409 &policy, LCK_PW, &lockh)) {
410 ldlm_lock_decref(&lockh, LCK_PW);
416 static int llu_inode_revalidate(struct inode *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);
430 unsigned long valid = OBD_MD_FLGETATTR;
433 /* Why don't we update all valid MDS fields here, if we're
434 * doing an RPC anyways? -phil */
435 if (S_ISREG(llu_i2stat(inode)->st_mode)) {
436 ealen = obd_size_diskmd(sbi->ll_dt_exp, NULL);
437 valid |= OBD_MD_FLEASIZE;
439 rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
442 CERROR("failure %d inode %llu\n", rc,
443 (long long)llu_i2stat(inode)->st_ino);
446 rc = md_get_lustre_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 *b = *llu_i2stat(ino);
488 static int llu_iop_getattr(struct pnode *pno,
490 struct intnl_stat *b)
495 liblustre_wait_event(0);
499 LASSERT(pno->p_base->pb_ino);
500 ino = pno->p_base->pb_ino;
502 LASSERT(!pno || pno->p_base->pb_ino == ino);
505 /* libsysio might call us directly without intent lock,
506 * we must re-fetch the attrs here
508 rc = llu_inode_revalidate(ino);
510 copy_stat_buf(ino, b);
511 LASSERT(!llu_i2info(ino)->lli_it);
514 liblustre_wait_event(0);
518 static int null_if_equal(struct ldlm_lock *lock, void *data)
520 if (data == lock->l_ast_data) {
521 lock->l_ast_data = NULL;
523 if (lock->l_req_mode != lock->l_granted_mode)
524 LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
527 return LDLM_ITER_CONTINUE;
530 void llu_clear_inode(struct inode *inode)
532 struct llu_inode_info *lli = llu_i2info(inode);
533 struct llu_sb_info *sbi = llu_i2sbi(inode);
536 CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu/%lu(%p)\n",
537 (long long)llu_i2stat(inode)->st_ino, lli->lli_st_generation,
540 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
541 md_change_cbdata(sbi->ll_md_exp, ll_inode2fid(inode),
542 null_if_equal, inode);
545 obd_change_cbdata(sbi->ll_dt_exp, lli->lli_smd,
546 null_if_equal, inode);
549 obd_free_memmd(sbi->ll_dt_exp, &lli->lli_smd);
553 if (lli->lli_symlink_name) {
554 OBD_FREE(lli->lli_symlink_name,
555 strlen(lli->lli_symlink_name) + 1);
556 lli->lli_symlink_name = NULL;
562 void llu_iop_gone(struct inode *inode)
564 struct llu_inode_info *lli = llu_i2info(inode);
567 liblustre_wait_event(0);
568 llu_clear_inode(inode);
570 OBD_FREE(lli, sizeof(*lli));
574 static int inode_setattr(struct inode * inode, struct iattr * attr)
576 unsigned int ia_valid = attr->ia_valid;
577 struct intnl_stat *st = llu_i2stat(inode);
581 * inode_setattr() is only ever invoked with ATTR_SIZE (by
582 * llu_setattr_raw()) when file has no bodies. Check this.
584 LASSERT(ergo(ia_valid & ATTR_SIZE, llu_i2info(inode)->lli_smd == NULL));
586 if (ia_valid & ATTR_SIZE)
587 st->st_size = attr->ia_size;
588 if (ia_valid & ATTR_UID)
589 st->st_uid = attr->ia_uid;
590 if (ia_valid & ATTR_GID)
591 st->st_gid = attr->ia_gid;
592 if (ia_valid & ATTR_ATIME)
593 st->st_atime = attr->ia_atime;
594 if (ia_valid & ATTR_MTIME)
595 st->st_mtime = attr->ia_mtime;
596 if (ia_valid & ATTR_CTIME)
597 st->st_ctime = attr->ia_ctime;
598 if (ia_valid & ATTR_MODE) {
599 st->st_mode = attr->ia_mode;
600 if (!in_group_p(st->st_gid) && !capable(CAP_FSETID))
601 st->st_mode &= ~S_ISGID;
603 /* mark_inode_dirty(inode); */
607 /* If this inode has objects allocated to it (lsm != NULL), then the OST
608 * object(s) determine the file size and mtime. Otherwise, the MDS will
609 * keep these values until such a time that objects are allocated for it.
610 * We do the MDS operations first, as it is checking permissions for us.
611 * We don't to the MDS RPC if there is nothing that we want to store there,
612 * otherwise there is no harm in updating mtime/atime on the MDS if we are
613 * going to do an RPC anyways.
615 * If we are doing a truncate, we will send the mtime and ctime updates
616 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
617 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
620 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
622 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
623 struct llu_sb_info *sbi = llu_i2sbi(inode);
624 struct intnl_stat *st = llu_i2stat(inode);
625 struct ptlrpc_request *request = NULL;
626 struct md_op_data op_data = { { 0 } };
627 int ia_valid = attr->ia_valid;
631 CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu\n", (long long)st->st_ino);
633 if (ia_valid & ATTR_SIZE) {
634 if (attr->ia_size > ll_file_maxbytes(inode)) {
635 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
636 (long long)attr->ia_size,
637 ll_file_maxbytes(inode));
641 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
644 /* We mark all of the fields "set" so MDS/OST does not re-set them */
645 if (attr->ia_valid & ATTR_CTIME) {
646 attr->ia_ctime = CURRENT_TIME;
647 attr->ia_valid |= ATTR_CTIME_SET;
649 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
650 attr->ia_atime = CURRENT_TIME;
651 attr->ia_valid |= ATTR_ATIME_SET;
653 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
654 attr->ia_mtime = CURRENT_TIME;
655 attr->ia_valid |= ATTR_MTIME_SET;
658 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
659 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
660 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
661 LTIME_S(CURRENT_TIME));
663 attr->ia_valid &= ~ATTR_SIZE;
665 /* If only OST attributes being set on objects, don't do MDS RPC.
666 * In that case, we need to check permissions and update the local
667 * inode ourselves so we can call obdo_from_inode() always. */
668 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
670 llu_prepare_md_op_data(&op_data, inode, NULL, NULL, 0, 0);
672 rc = md_setattr(sbi->ll_md_exp, &op_data,
673 attr, NULL, 0, NULL, 0, &request);
676 ptlrpc_req_finished(request);
677 if (rc != -EPERM && rc != -EACCES)
678 CERROR("mdc_setattr fails: rc = %d\n", rc);
682 rc = md_get_lustre_md(sbi->ll_md_exp, request, 0,
683 sbi->ll_dt_exp, &md);
685 ptlrpc_req_finished(request);
689 /* We call inode_setattr to adjust timestamps.
690 * If there is at least some data in file, we cleared ATTR_SIZE
691 * above to avoid invoking vmtruncate, otherwise it is important
692 * to call vmtruncate in inode_setattr to update inode->i_size
694 inode_setattr(inode, attr);
695 llu_update_inode(inode, md.body, md.lsm);
696 ptlrpc_req_finished(request);
698 if (!lsm || !S_ISREG(st->st_mode)) {
699 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
703 /* The OST doesn't check permissions, but the alternative is
704 * a gratuitous RPC to the MDS. We already rely on the client
705 * to do read/write/truncate permission checks, so is mtime OK?
707 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
708 /* from sys_utime() */
709 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
710 if (current->fsuid != st->st_uid &&
711 (rc = ll_permission(inode, MAY_WRITE)) != 0)
714 /* from inode_change_ok() */
715 if (current->fsuid != st->st_uid &&
716 !capable(CAP_FOWNER))
721 /* Won't invoke llu_vmtruncate(), as we already cleared
723 inode_setattr(inode, attr);
726 if (ia_valid & ATTR_SIZE) {
727 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
729 struct lustre_handle lockh = { 0, };
730 struct lustre_handle match_lockh = { 0, };
733 int flags = LDLM_FL_TEST_LOCK; /* for assertion check below */
737 /* check that there are no matching locks */
738 LASSERT(obd_match(sbi->ll_dt_exp, lsm, LDLM_EXTENT, &policy,
739 LCK_PW, &flags, inode, &match_lockh) <= 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 flags = (attr->ia_size == 0) ? LDLM_AST_DISCARD_DATA : 0;
746 if (sbi->ll_lco.lco_flags & OBD_CONNECT_TRUNCLOCK) {
748 obd_flags = OBD_FL_TRUNCLOCK;
749 CDEBUG(D_INODE, "delegating locking to the OST");
755 /* with lock_mode == LK_NL no lock is taken. */
756 rc = llu_extent_lock(NULL, inode, lsm, lock_mode, &policy,
758 if (rc != ELDLM_OK) {
764 rc = llu_vmtruncate(inode, attr->ia_size, obd_flags);
766 /* unlock now as we don't mind others file lockers racing with
767 * the mds updates below? */
768 err = llu_extent_unlock(NULL, inode, lsm, lock_mode, &lockh);
770 CERROR("llu_extent_unlock failed: %d\n", err);
774 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
777 CDEBUG(D_INODE, "set mtime on OST inode %llu to %lu\n",
778 (long long)st->st_ino, LTIME_S(attr->ia_mtime));
779 oa.o_id = lsm->lsm_object_id;
780 oa.o_valid = OBD_MD_FLID;
781 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
782 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
783 rc = obd_setattr(sbi->ll_dt_exp, &oa, lsm, NULL);
785 CERROR("obd_setattr fails: rc=%d\n", rc);
790 /* here we simply act as a thin layer to glue it with
791 * llu_setattr_raw(), which is copy from kernel
793 static int llu_iop_setattr(struct pnode *pno,
796 struct intnl_stat *stbuf)
802 liblustre_wait_event(0);
804 LASSERT(!(mask & ~(SETATTR_MTIME | SETATTR_ATIME |
805 SETATTR_UID | SETATTR_GID |
806 SETATTR_LEN | SETATTR_MODE)));
807 memset(&iattr, 0, sizeof(iattr));
809 if (mask & SETATTR_MODE) {
810 iattr.ia_mode = stbuf->st_mode;
811 iattr.ia_valid |= ATTR_MODE;
813 if (mask & SETATTR_MTIME) {
814 iattr.ia_mtime = stbuf->st_mtime;
815 iattr.ia_valid |= ATTR_MTIME | ATTR_MTIME_SET;
817 if (mask & SETATTR_ATIME) {
818 iattr.ia_atime = stbuf->st_atime;
819 iattr.ia_valid |= ATTR_ATIME | ATTR_ATIME_SET;
821 if (mask & SETATTR_UID) {
822 iattr.ia_uid = stbuf->st_uid;
823 iattr.ia_valid |= ATTR_UID;
825 if (mask & SETATTR_GID) {
826 iattr.ia_gid = stbuf->st_gid;
827 iattr.ia_valid |= ATTR_GID;
829 if (mask & SETATTR_LEN) {
830 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
831 iattr.ia_valid |= ATTR_SIZE;
834 iattr.ia_valid |= ATTR_RAW | ATTR_CTIME;
835 iattr.ia_ctime = CURRENT_TIME;
837 rc = llu_setattr_raw(ino, &iattr);
838 liblustre_wait_event(0);
842 #define EXT2_LINK_MAX 32000
844 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
846 struct inode *dir = pno->p_base->pb_parent->pb_ino;
847 struct qstr *qstr = &pno->p_base->pb_name;
848 const char *name = qstr->name;
850 struct ptlrpc_request *request = NULL;
851 struct llu_sb_info *sbi = llu_i2sbi(dir);
852 struct md_op_data op_data = { { 0 } };
853 struct lu_placement_hint hint = {
856 .ph_opc = LUSTRE_OPC_SYMLINK
861 liblustre_wait_event(0);
862 if (llu_i2stat(dir)->st_nlink >= EXT2_LINK_MAX)
865 /* allocate new fid */
866 err = llu_fid_md_alloc(sbi, &op_data.fid2, &hint);
868 CERROR("can't allocate new fid, rc %d\n", err);
871 llu_prepare_md_op_data(&op_data, dir, NULL, name, len, 0);
872 err = md_create(sbi->ll_md_exp, &op_data,
873 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
874 current->fsuid, current->fsgid, current->cap_effective,
876 ptlrpc_req_finished(request);
877 liblustre_wait_event(0);
881 static int llu_readlink_internal(struct inode *inode,
882 struct ptlrpc_request **request,
885 struct llu_inode_info *lli = llu_i2info(inode);
886 struct llu_sb_info *sbi = llu_i2sbi(inode);
887 struct mdt_body *body;
888 struct intnl_stat *st = llu_i2stat(inode);
889 int rc, symlen = st->st_size + 1;
894 if (lli->lli_symlink_name) {
895 *symname = lli->lli_symlink_name;
896 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
900 rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
901 OBD_MD_LINKNAME, symlen, request);
903 CERROR("inode %llu: rc = %d\n", (long long)st->st_ino, rc);
907 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
908 LASSERT (body != NULL);
909 LASSERT_REPSWABBED (*request, 0);
911 if ((body->valid & OBD_MD_LINKNAME) == 0) {
912 CERROR ("OBD_MD_LINKNAME not set on reply\n");
913 GOTO (failed, rc = -EPROTO);
916 LASSERT(symlen != 0);
917 if (body->eadatasize != symlen) {
918 CERROR("inode %llu: symlink length %d not expected %d\n",
919 (long long)st->st_ino, body->eadatasize - 1, symlen - 1);
920 GOTO(failed, rc = -EPROTO);
923 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
924 if (*symname == NULL ||
925 strnlen(*symname, symlen) != symlen - 1) {
926 /* not full/NULL terminated */
927 CERROR("inode %llu: symlink not NULL terminated string"
928 "of length %d\n", (long long)st->st_ino, symlen - 1);
929 GOTO(failed, rc = -EPROTO);
932 OBD_ALLOC(lli->lli_symlink_name, symlen);
933 /* do not return an error if we cannot cache the symlink locally */
934 if (lli->lli_symlink_name)
935 memcpy(lli->lli_symlink_name, *symname, symlen);
940 ptlrpc_req_finished (*request);
944 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
946 struct inode *inode = pno->p_base->pb_ino;
947 struct ptlrpc_request *request;
952 liblustre_wait_event(0);
953 rc = llu_readlink_internal(inode, &request, &symname);
958 strncpy(data, symname, bufsize);
959 rc = strlen(symname);
961 ptlrpc_req_finished(request);
963 liblustre_wait_event(0);
967 static int llu_iop_mknod_raw(struct pnode *pno,
971 struct ptlrpc_request *request = NULL;
972 struct inode *dir = pno->p_parent->p_base->pb_ino;
973 struct llu_sb_info *sbi = llu_i2sbi(dir);
974 struct md_op_data op_data = { { 0 } };
976 struct lu_placement_hint hint = {
978 .ph_cname = &pno->p_base->pb_name,
979 .ph_opc = LUSTRE_OPC_MKNOD
983 liblustre_wait_event(0);
984 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%llu\n",
985 (int)pno->p_base->pb_name.len, pno->p_base->pb_name.name,
986 (long long)llu_i2stat(dir)->st_ino);
988 if (llu_i2stat(dir)->st_nlink >= EXT2_LINK_MAX)
991 switch (mode & S_IFMT) {
994 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
999 /* allocate new fid */
1000 err = llu_fid_md_alloc(sbi, &op_data.fid2, &hint);
1002 CERROR("can't allocate new fid, rc %d\n", err);
1006 llu_prepare_md_op_data(&op_data, dir, NULL,
1007 pno->p_base->pb_name.name,
1008 pno->p_base->pb_name.len,
1010 err = md_create(sbi->ll_md_exp, &op_data, NULL, 0, mode,
1011 current->fsuid, current->fsgid,
1012 current->cap_effective, dev, &request);
1013 ptlrpc_req_finished(request);
1021 liblustre_wait_event(0);
1025 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
1027 struct inode *src = old->p_base->pb_ino;
1028 struct inode *dir = new->p_parent->p_base->pb_ino;
1029 const char *name = new->p_base->pb_name.name;
1030 int namelen = new->p_base->pb_name.len;
1031 struct ptlrpc_request *request = NULL;
1032 struct md_op_data op_data = { { 0 } };
1039 liblustre_wait_event(0);
1040 llu_prepare_md_op_data(&op_data, src, dir, name, namelen, 0);
1041 rc = md_link(llu_i2sbi(src)->ll_md_exp, &op_data, &request);
1042 ptlrpc_req_finished(request);
1043 liblustre_wait_event(0);
1049 * libsysio will clear the inode immediately after return
1051 static int llu_iop_unlink_raw(struct pnode *pno)
1053 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1054 struct qstr *qstr = &pno->p_base->pb_name;
1055 const char *name = qstr->name;
1056 int len = qstr->len;
1057 struct inode *target = pno->p_base->pb_ino;
1058 struct ptlrpc_request *request = NULL;
1059 struct md_op_data op_data = { { 0 } };
1065 liblustre_wait_event(0);
1066 llu_prepare_md_op_data(&op_data, dir, NULL, name, len, 0);
1067 rc = md_unlink(llu_i2sbi(dir)->ll_md_exp, &op_data, &request);
1069 rc = llu_objects_destroy(request, dir);
1070 ptlrpc_req_finished(request);
1071 liblustre_wait_event(0);
1076 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
1078 struct inode *src = old->p_parent->p_base->pb_ino;
1079 struct inode *tgt = new->p_parent->p_base->pb_ino;
1080 const char *oldname = old->p_base->pb_name.name;
1081 int oldnamelen = old->p_base->pb_name.len;
1082 const char *newname = new->p_base->pb_name.name;
1083 int newnamelen = new->p_base->pb_name.len;
1084 struct ptlrpc_request *request = NULL;
1085 struct md_op_data op_data = { { 0 } };
1092 liblustre_wait_event(0);
1093 llu_prepare_md_op_data(&op_data, src, tgt, NULL, 0, 0);
1094 rc = md_rename(llu_i2sbi(src)->ll_md_exp, &op_data,
1095 oldname, oldnamelen, newname, newnamelen,
1098 rc = llu_objects_destroy(request, src);
1101 ptlrpc_req_finished(request);
1102 liblustre_wait_event(0);
1107 #ifdef _HAVE_STATVFS
1108 static int llu_statfs_internal(struct llu_sb_info *sbi,
1109 struct obd_statfs *osfs,
1110 unsigned long max_age)
1112 struct obd_statfs obd_osfs;
1116 rc = obd_statfs(class_exp2obd(sbi->ll_md_exp), osfs, max_age);
1118 CERROR("mdc_statfs fails: rc = %d\n", rc);
1122 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1123 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1125 rc = obd_statfs(class_exp2obd(sbi->ll_dt_exp), &obd_osfs, max_age);
1127 CERROR("obd_statfs fails: rc = %d\n", rc);
1131 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1132 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1135 osfs->os_blocks = obd_osfs.os_blocks;
1136 osfs->os_bfree = obd_osfs.os_bfree;
1137 osfs->os_bavail = obd_osfs.os_bavail;
1139 /* If we don't have as many objects free on the OST as inodes
1140 * on the MDS, we reduce the total number of inodes to
1141 * compensate, so that the "inodes in use" number is correct.
1143 if (obd_osfs.os_ffree < osfs->os_ffree) {
1144 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1146 osfs->os_ffree = obd_osfs.os_ffree;
1152 static int llu_statfs(struct llu_sb_info *sbi, struct statfs *sfs)
1154 struct obd_statfs osfs;
1157 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1159 /* For now we will always get up-to-date statfs values, but in the
1160 * future we may allow some amount of caching on the client (e.g.
1161 * from QOS or lprocfs updates). */
1162 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1166 statfs_unpack(sfs, &osfs);
1168 if (sizeof(sfs->f_blocks) == 4) {
1169 while (osfs.os_blocks > ~0UL) {
1172 osfs.os_blocks >>= 1;
1173 osfs.os_bfree >>= 1;
1174 osfs.os_bavail >>= 1;
1178 sfs->f_blocks = osfs.os_blocks;
1179 sfs->f_bfree = osfs.os_bfree;
1180 sfs->f_bavail = osfs.os_bavail;
1185 static int llu_iop_statvfs(struct pnode *pno,
1187 struct intnl_statvfs *buf)
1193 liblustre_wait_event(0);
1196 LASSERT(pno->p_base->pb_ino);
1197 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1201 /* from native driver */
1202 buf->f_bsize = fs.f_bsize; /* file system block size */
1203 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1204 buf->f_blocks = fs.f_blocks;
1205 buf->f_bfree = fs.f_bfree;
1206 buf->f_bavail = fs.f_bavail;
1207 buf->f_files = fs.f_files; /* Total number serial numbers */
1208 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1209 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1210 buf->f_fsid = fs.f_fsid.__val[1];
1211 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1212 buf->f_namemax = fs.f_namelen;
1215 liblustre_wait_event(0);
1218 #endif /* _HAVE_STATVFS */
1220 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1222 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1223 struct qstr *qstr = &pno->p_base->pb_name;
1224 const char *name = qstr->name;
1225 int len = qstr->len;
1226 struct ptlrpc_request *request = NULL;
1227 struct intnl_stat *st = llu_i2stat(dir);
1228 struct md_op_data op_data = { { 0 } };
1229 struct lu_placement_hint hint = {
1232 .ph_opc = LUSTRE_OPC_MKDIR
1238 liblustre_wait_event(0);
1239 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%llu/%lu(%p)\n", len, name,
1240 (long long)st->st_ino, llu_i2info(dir)->lli_st_generation, dir);
1242 if (st->st_nlink >= EXT2_LINK_MAX)
1245 /* allocate new fid */
1246 err = llu_fid_md_alloc(llu_i2sbi(dir), &op_data.fid2, &hint);
1248 CERROR("can't allocate new fid, rc %d\n", err);
1251 llu_prepare_md_op_data(&op_data, dir, NULL, name, len, 0);
1252 err = md_create(llu_i2sbi(dir)->ll_md_exp, &op_data, NULL, 0, mode,
1253 current->fsuid, current->fsgid, current->cap_effective,
1255 ptlrpc_req_finished(request);
1256 liblustre_wait_event(0);
1260 static int llu_iop_rmdir_raw(struct pnode *pno)
1262 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1263 struct qstr *qstr = &pno->p_base->pb_name;
1264 const char *name = qstr->name;
1265 int len = qstr->len;
1266 struct ptlrpc_request *request = NULL;
1267 struct md_op_data op_data = { { 0 } };
1271 liblustre_wait_event(0);
1272 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%llu/%lu(%p)\n", len, name,
1273 (long long)llu_i2stat(dir)->st_ino,
1274 llu_i2info(dir)->lli_st_generation, dir);
1276 llu_prepare_md_op_data(&op_data, dir, NULL, name, len, S_IFDIR);
1277 rc = md_unlink(llu_i2sbi(dir)->ll_md_exp, &op_data, &request);
1278 ptlrpc_req_finished(request);
1280 liblustre_wait_event(0);
1285 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC|O_DIRECT)
1287 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC)
1289 #define FCNTL_FLMASK_INVALID (O_NONBLOCK|O_ASYNC)
1291 /* refer to ll_file_flock() for details */
1292 static int llu_file_flock(struct inode *ino,
1294 struct file_lock *file_lock)
1296 struct obd_device *obddev;
1297 struct llu_inode_info *lli = llu_i2info(ino);
1298 struct intnl_stat *st = llu_i2stat(ino);
1299 struct ldlm_res_id res_id =
1300 { .name = {fid_seq(&lli->lli_fid),
1301 fid_oid(&lli->lli_fid),
1302 fid_ver(&lli->lli_fid),
1304 struct lustre_handle lockh = {0};
1305 ldlm_policy_data_t flock;
1306 ldlm_mode_t mode = 0;
1310 CDEBUG(D_VFSTRACE, "VFS Op:inode="LPU64" file_lock=%p\n",
1311 st->st_ino, file_lock);
1313 flock.l_flock.pid = file_lock->fl_pid;
1314 flock.l_flock.start = file_lock->fl_start;
1315 flock.l_flock.end = file_lock->fl_end;
1317 switch (file_lock->fl_type) {
1328 CERROR("unknown fcntl lock type: %d\n", file_lock->fl_type);
1335 #if F_SETLKW64 != F_SETLKW
1343 #if F_SETLK64 != F_SETLK
1347 flags = LDLM_FL_BLOCK_NOWAIT;
1351 #if F_GETLK64 != F_GETLK
1355 flags = LDLM_FL_TEST_LOCK;
1356 file_lock->fl_type = mode;
1359 CERROR("unknown fcntl cmd: %d\n", cmd);
1363 CDEBUG(D_DLMTRACE, "inode="LPU64", pid=%u, flags=%#x, mode=%u, "
1364 "start="LPU64", end="LPU64"\n", st->st_ino, flock.l_flock.pid,
1365 flags, mode, flock.l_flock.start, flock.l_flock.end);
1367 obddev = llu_i2mdcexp(ino)->exp_obd;
1368 rc = ldlm_cli_enqueue(llu_i2mdcexp(ino), NULL, obddev->obd_namespace,
1369 res_id, LDLM_FLOCK, &flock, mode, &flags,
1370 NULL, ldlm_flock_completion_ast, NULL, file_lock,
1371 NULL, 0, NULL, &lockh);
1375 static int assign_type(struct file_lock *fl, int type)
1388 static int flock_to_posix_lock(struct inode *ino,
1389 struct file_lock *fl,
1392 switch (l->l_whence) {
1393 /* XXX: only SEEK_SET is supported in lustre */
1401 fl->fl_end = l->l_len - 1;
1405 fl->fl_end = OFFSET_MAX;
1407 fl->fl_pid = getpid();
1408 fl->fl_flags = FL_POSIX;
1409 fl->fl_notify = NULL;
1410 fl->fl_insert = NULL;
1411 fl->fl_remove = NULL;
1412 /* XXX: these fields can't be filled with suitable values,
1413 but I think lustre doesn't use them.
1415 fl->fl_owner = NULL;
1418 return assign_type(fl, l->l_type);
1421 static int llu_fcntl_getlk(struct inode *ino, struct flock *flock)
1423 struct file_lock fl;
1427 if ((flock->l_type != F_RDLCK) && (flock->l_type != F_WRLCK))
1430 error = flock_to_posix_lock(ino, &fl, flock);
1434 error = llu_file_flock(ino, F_GETLK, &fl);
1438 flock->l_type = F_UNLCK;
1439 if (fl.fl_type != F_UNLCK) {
1440 flock->l_pid = fl.fl_pid;
1441 flock->l_start = fl.fl_start;
1442 flock->l_len = fl.fl_end == OFFSET_MAX ? 0:
1443 fl.fl_end - fl.fl_start + 1;
1444 flock->l_whence = SEEK_SET;
1445 flock->l_type = fl.fl_type;
1452 static int llu_fcntl_setlk(struct inode *ino, int cmd, struct flock *flock)
1454 struct file_lock fl;
1455 int flags = llu_i2info(ino)->lli_open_flags + 1;
1458 error = flock_to_posix_lock(ino, &fl, flock);
1461 if (cmd == F_SETLKW)
1462 fl.fl_flags |= FL_SLEEP;
1465 switch (flock->l_type) {
1467 if (!(flags & FMODE_READ))
1471 if (!(flags & FMODE_WRITE))
1481 error = llu_file_flock(ino, cmd, &fl);
1489 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn)
1491 struct llu_inode_info *lli = llu_i2info(ino);
1493 struct flock *flock;
1496 liblustre_wait_event(0);
1499 *rtn = lli->lli_open_flags;
1502 flags = va_arg(ap, long);
1503 flags &= FCNTL_FLMASK;
1504 if (flags & FCNTL_FLMASK_INVALID) {
1505 CERROR("liblustre don't support O_NONBLOCK, O_ASYNC, "
1506 "and O_DIRECT on file descriptor\n");
1511 lli->lli_open_flags = (int)(flags & FCNTL_FLMASK) |
1512 (lli->lli_open_flags & ~FCNTL_FLMASK);
1517 #if F_GETLK64 != F_GETLK
1521 flock = va_arg(ap, struct flock *);
1522 err = llu_fcntl_getlk(ino, flock);
1527 #if F_SETLKW64 != F_SETLKW
1533 #if F_SETLK64 != F_SETLK
1537 flock = va_arg(ap, struct flock *);
1538 err = llu_fcntl_setlk(ino, cmd, flock);
1542 CERROR("unsupported fcntl cmd %x\n", cmd);
1548 liblustre_wait_event(0);
1552 static int llu_get_grouplock(struct inode *inode, unsigned long arg)
1554 struct llu_inode_info *lli = llu_i2info(inode);
1555 struct ll_file_data *fd = lli->lli_file_data;
1556 ldlm_policy_data_t policy = { .l_extent = { .start = 0,
1557 .end = OBD_OBJECT_EOF}};
1558 struct lustre_handle lockh = { 0 };
1559 struct lov_stripe_md *lsm = lli->lli_smd;
1564 if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
1568 policy.l_extent.gid = arg;
1569 if (lli->lli_open_flags & O_NONBLOCK)
1570 flags = LDLM_FL_BLOCK_NOWAIT;
1572 err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
1577 fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
1579 memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
1584 static int llu_put_grouplock(struct inode *inode, unsigned long arg)
1586 struct llu_inode_info *lli = llu_i2info(inode);
1587 struct ll_file_data *fd = lli->lli_file_data;
1588 struct lov_stripe_md *lsm = lli->lli_smd;
1592 if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
1595 if (fd->fd_gid != arg)
1598 fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
1600 err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
1605 memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
1610 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1616 liblustre_wait_event(0);
1619 case LL_IOC_GROUP_LOCK:
1620 arg = va_arg(ap, unsigned long);
1621 rc = llu_get_grouplock(ino, arg);
1623 case LL_IOC_GROUP_UNLOCK:
1624 arg = va_arg(ap, unsigned long);
1625 rc = llu_put_grouplock(ino, arg);
1628 CERROR("did not support ioctl cmd %lx\n", request);
1633 liblustre_wait_event(0);
1638 * we already do syncronous read/write
1640 static int llu_iop_sync(struct inode *inode)
1642 liblustre_wait_event(0);
1646 static int llu_iop_datasync(struct inode *inode)
1648 liblustre_wait_event(0);
1652 struct filesys_ops llu_filesys_ops =
1654 fsop_gone: llu_fsop_gone,
1657 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1659 struct inode *inode;
1661 struct file_identifier fileid = {&fid, sizeof(fid)};
1663 if ((md->body->valid &
1664 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1665 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) {
1666 CERROR("bad md body valid mask "LPX64"\n", md->body->valid);
1668 return ERR_PTR(-EPERM);
1671 /* try to find existing inode */
1672 fid = md->body->fid1;
1674 inode = _sysio_i_find(fs, &fileid);
1676 if (inode->i_zombie/* ||
1677 lli->lli_st_generation != md->body->generation*/) {
1681 llu_update_inode(inode, md->body, md->lsm);
1686 inode = llu_new_inode(fs, &fid);
1688 llu_update_inode(inode, md->body, md->lsm);
1694 llu_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp)
1696 struct lov_stripe_md lsm = { .lsm_magic = LOV_MAGIC };
1697 __u32 valsize = sizeof(struct lov_desc);
1698 int rc, easize, def_easize, cookiesize;
1699 struct lov_desc desc;
1703 rc = obd_get_info(dt_exp, strlen(KEY_LOVDESC) + 1, KEY_LOVDESC,
1708 stripes = min(desc.ld_tgt_count, (__u32)LOV_MAX_STRIPE_COUNT);
1709 lsm.lsm_stripe_count = stripes;
1710 easize = obd_size_diskmd(dt_exp, &lsm);
1712 lsm.lsm_stripe_count = desc.ld_default_stripe_count;
1713 def_easize = obd_size_diskmd(dt_exp, &lsm);
1715 cookiesize = stripes * sizeof(struct llog_cookie);
1717 CDEBUG(D_HA, "updating max_mdsize/max_cookiesize: %d/%d\n",
1718 easize, cookiesize);
1720 rc = md_init_ea_size(md_exp, easize, def_easize, cookiesize);
1725 llu_fsswop_mount(const char *source,
1727 const void *data __IS_UNUSED,
1728 struct pnode *tocover,
1729 struct mount **mntp)
1733 struct pnode_base *rootpb;
1734 struct obd_device *obd;
1735 struct lu_fid rootfid;
1736 struct llu_sb_info *sbi;
1737 struct obd_statfs osfs;
1738 static struct qstr noname = { NULL, 0, 0 };
1739 struct ptlrpc_request *request = NULL;
1740 struct lustre_handle mdc_conn = {0, };
1741 struct lustre_handle osc_conn = {0, };
1742 struct lustre_md md;
1744 struct config_llog_instance cfg;
1745 char ll_instance[sizeof(sbi) * 2 + 1];
1746 struct lustre_profile *lprof;
1747 char *zconf_mdsnid, *zconf_mdsname, *zconf_profile;
1748 char *osc = NULL, *mdc = NULL;
1749 int async = 1, err = -EINVAL;
1750 struct obd_connect_data ocd = {0,};
1754 if (ll_parse_mount_target(source,
1758 CERROR("mal-formed target %s\n", source);
1761 if (!zconf_mdsnid || !zconf_mdsname || !zconf_profile) {
1762 printf("Liblustre: invalid target %s\n", source);
1765 /* allocate & initialize sbi */
1766 OBD_ALLOC(sbi, sizeof(*sbi));
1770 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1771 generate_random_uuid(uuid);
1772 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1774 /* generate a string unique to this super, let's try
1775 the address of the super itself.*/
1776 sprintf(ll_instance, "%p", sbi);
1778 /* retrive & parse config log */
1779 cfg.cfg_instance = ll_instance;
1780 cfg.cfg_uuid = sbi->ll_sb_uuid;
1781 err = liblustre_process_log(&cfg, zconf_mdsnid, zconf_mdsname,
1784 CERROR("Unable to process log: %s\n", zconf_profile);
1785 GOTO(out_free, err);
1788 lprof = class_get_profile(zconf_profile);
1789 if (lprof == NULL) {
1790 CERROR("No profile found: %s\n", zconf_profile);
1791 GOTO(out_free, err = -EINVAL);
1793 OBD_ALLOC(osc, strlen(lprof->lp_osc) + strlen(ll_instance) + 2);
1794 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
1796 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) + strlen(ll_instance) + 2);
1797 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
1801 GOTO(out_free, err = -EINVAL);
1805 GOTO(out_free, err = -EINVAL);
1808 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1814 obd = class_name2obd(mdc);
1816 CERROR("MDC %s: not setup or attached\n", mdc);
1817 GOTO(out_free, err = -EINVAL);
1819 obd_set_info_async(obd->obd_self_export, strlen("async"), "async",
1820 sizeof(async), &async, NULL);
1822 ocd.ocd_connect_flags = OBD_CONNECT_IBITS|OBD_CONNECT_VERSION;
1823 ocd.ocd_ibits_known = MDS_INODELOCK_FULL;
1824 ocd.ocd_version = LUSTRE_VERSION_CODE;
1827 err = obd_connect(NULL, &mdc_conn, obd, &sbi->ll_sb_uuid, &ocd);
1829 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
1830 GOTO(out_free, err);
1832 sbi->ll_md_exp = class_conn2export(&mdc_conn);
1834 err = obd_statfs(obd, &osfs, 100000000);
1838 err = llu_fid_md_init(sbi);
1843 * FIXME fill fs stat data into sbi here!!! FIXME
1847 obd = class_name2obd(osc);
1849 CERROR("OSC %s: not setup or attached\n", osc);
1850 GOTO(out_md_fid, err = -EINVAL);
1852 obd_set_info_async(obd->obd_self_export, strlen("async"), "async",
1853 sizeof(async), &async, NULL);
1855 obd->obd_upcall.onu_owner = &sbi->ll_lco;
1856 obd->obd_upcall.onu_upcall = ll_ocd_update;
1858 ocd.ocd_connect_flags = OBD_CONNECT_SRVLOCK|OBD_CONNECT_REQPORTAL|
1859 OBD_CONNECT_VERSION|OBD_CONNECT_TRUNCLOCK;
1860 ocd.ocd_version = LUSTRE_VERSION_CODE;
1861 err = obd_connect(NULL, &osc_conn, obd, &sbi->ll_sb_uuid, &ocd);
1863 CERROR("cannot connect to %s: rc = %d\n", osc, err);
1866 sbi->ll_dt_exp = class_conn2export(&osc_conn);
1867 sbi->ll_lco.lco_flags = ocd.ocd_connect_flags;
1869 err = llu_fid_dt_init(sbi);
1873 llu_init_ea_size(sbi->ll_md_exp, sbi->ll_dt_exp);
1875 err = md_getstatus(sbi->ll_md_exp, &rootfid);
1877 CERROR("cannot mds_connect: rc = %d\n", err);
1878 GOTO(out_dt_fid, err);
1880 CDEBUG(D_SUPER, "rootfid "DFID3"\n", PFID3(&rootfid));
1881 sbi->ll_root_fid = rootfid;
1883 /* fetch attr of root inode */
1884 err = md_getattr(sbi->ll_md_exp, &rootfid,
1885 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS, 0, &request);
1887 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1891 err = md_get_lustre_md(sbi->ll_md_exp, request, 0,
1892 sbi->ll_dt_exp, &md);
1894 CERROR("failed to understand root inode md: rc = %d\n",err);
1895 GOTO(out_request, err);
1898 LASSERT(fid_is_sane(&sbi->ll_root_fid));
1900 root = llu_iget(fs, &md);
1901 if (!root || IS_ERR(root)) {
1902 CERROR("fail to generate root inode\n");
1903 GOTO(out_request, err = -EBADF);
1907 * Generate base path-node for root.
1909 rootpb = _sysio_pb_new(&noname, NULL, root);
1915 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1917 _sysio_pb_gone(rootpb);
1921 ptlrpc_req_finished(request);
1923 CDEBUG(D_SUPER, "LibLustre: %s mounted successfully!\n", source);
1924 liblustre_wait_event(0);
1929 _sysio_i_gone(root);
1931 ptlrpc_req_finished(request);
1933 llu_fid_dt_fini(sbi);
1935 obd_disconnect(sbi->ll_dt_exp);
1937 llu_fid_md_fini(sbi);
1939 obd_disconnect(sbi->ll_md_exp);
1942 OBD_FREE(osc, strlen(osc) + 1);
1944 OBD_FREE(mdc, strlen(mdc) + 1);
1945 OBD_FREE(sbi, sizeof(*sbi));
1949 struct fssw_ops llu_fssw_ops = {
1953 static struct inode_ops llu_inode_ops = {
1954 inop_lookup: llu_iop_lookup,
1955 inop_getattr: llu_iop_getattr,
1956 inop_setattr: llu_iop_setattr,
1957 inop_filldirentries: llu_iop_filldirentries,
1958 inop_mkdir: llu_iop_mkdir_raw,
1959 inop_rmdir: llu_iop_rmdir_raw,
1960 inop_symlink: llu_iop_symlink_raw,
1961 inop_readlink: llu_iop_readlink,
1962 inop_open: llu_iop_open,
1963 inop_close: llu_iop_close,
1964 inop_link: llu_iop_link_raw,
1965 inop_unlink: llu_iop_unlink_raw,
1966 inop_rename: llu_iop_rename_raw,
1967 inop_pos: llu_iop_pos,
1968 inop_read: llu_iop_read,
1969 inop_write: llu_iop_write,
1970 inop_iodone: llu_iop_iodone,
1971 inop_fcntl: llu_iop_fcntl,
1972 inop_sync: llu_iop_sync,
1973 inop_datasync: llu_iop_datasync,
1974 inop_ioctl: llu_iop_ioctl,
1975 inop_mknod: llu_iop_mknod_raw,
1976 #ifdef _HAVE_STATVFS
1977 inop_statvfs: llu_iop_statvfs,
1979 inop_gone: llu_iop_gone,