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"
54 #include <linux/lustre_ver.h>
62 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
64 static int ll_permission(struct inode *inode, int mask)
66 struct intnl_stat *st = llu_i2stat(inode);
67 mode_t mode = st->st_mode;
69 if (current->fsuid == st->st_uid)
71 else if (in_group_p(st->st_gid))
74 if ((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask)
77 if ((mask & (MAY_READ|MAY_WRITE)) ||
78 (st->st_mode & S_IXUGO))
79 if (capable(CAP_DAC_OVERRIDE))
82 if (mask == MAY_READ ||
83 (S_ISDIR(st->st_mode) && !(mask & MAY_WRITE))) {
84 if (capable(CAP_DAC_READ_SEARCH))
91 static void llu_fsop_gone(struct filesys *fs)
93 struct llu_sb_info *sbi = (struct llu_sb_info *) fs->fs_private;
94 struct obd_device *obd = class_exp2obd(sbi->ll_mdc_exp);
98 list_del(&sbi->ll_conn_chain);
99 obd_disconnect(sbi->ll_osc_exp);
100 obd_disconnect(sbi->ll_mdc_exp);
102 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL){
103 struct lustre_cfg_bufs bufs;
104 struct lustre_cfg *lcfg;
107 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
108 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
109 err = class_process_config(lcfg);
110 lustre_cfg_free(lcfg);
112 CERROR("cleanup failed: %s\n", obd->obd_name);
114 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
115 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
116 err = class_process_config(lcfg);
118 CERROR("detach failed: %s\n", obd->obd_name);
121 OBD_FREE(sbi, sizeof(*sbi));
126 static struct inode_ops llu_inode_ops;
128 void llu_update_inode(struct inode *inode, struct mds_body *body,
129 struct lov_stripe_md *lsm)
131 struct llu_inode_info *lli = llu_i2info(inode);
132 struct intnl_stat *st = llu_i2stat(inode);
134 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
136 if (lli->lli_smd == NULL) {
138 lli->lli_maxbytes = lsm->lsm_maxbytes;
139 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
140 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
142 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
143 CERROR("lsm mismatch for inode %lld\n",
144 (long long)st->st_ino);
150 if (body->valid & OBD_MD_FLID)
151 st->st_ino = body->ino;
152 if (body->valid & OBD_MD_FLATIME)
153 LTIME_S(st->st_atime) = body->atime;
154 if (body->valid & OBD_MD_FLMTIME)
155 LTIME_S(st->st_mtime) = body->mtime;
156 if (body->valid & OBD_MD_FLCTIME)
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;
180 if (body->valid & OBD_MD_FLGENER)
181 lli->lli_st_generation = body->generation;
184 if (body->valid & OBD_MD_FLID)
185 lli->lli_fid.id = body->ino;
186 if (body->valid & OBD_MD_FLGENER)
187 lli->lli_fid.generation = body->generation;
188 if (body->valid & OBD_MD_FLTYPE)
189 lli->lli_fid.f_type = body->mode & S_IFMT;
192 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
194 struct llu_inode_info *lli = llu_i2info(dst);
195 struct intnl_stat *st = llu_i2stat(dst);
197 valid &= src->o_valid;
199 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
200 CDEBUG(D_INODE,"valid "LPX64", cur time %lu/%lu, new %lu/%lu\n",
202 LTIME_S(st->st_mtime), LTIME_S(st->st_ctime),
203 (long)src->o_mtime, (long)src->o_ctime);
205 if (valid & OBD_MD_FLATIME)
206 LTIME_S(st->st_atime) = src->o_atime;
207 if (valid & OBD_MD_FLMTIME)
208 LTIME_S(st->st_mtime) = src->o_mtime;
209 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(st->st_ctime))
210 LTIME_S(st->st_ctime) = src->o_ctime;
211 if (valid & OBD_MD_FLSIZE)
212 st->st_size = src->o_size;
213 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
214 st->st_blocks = src->o_blocks;
215 if (valid & OBD_MD_FLBLKSZ)
216 st->st_blksize = src->o_blksize;
217 if (valid & OBD_MD_FLTYPE)
218 st->st_mode = (st->st_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
219 if (valid & OBD_MD_FLMODE)
220 st->st_mode = (st->st_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
221 if (valid & OBD_MD_FLUID)
222 st->st_uid = src->o_uid;
223 if (valid & OBD_MD_FLGID)
224 st->st_gid = src->o_gid;
225 if (valid & OBD_MD_FLFLAGS)
226 lli->lli_st_flags = src->o_flags;
227 if (valid & OBD_MD_FLGENER)
228 lli->lli_st_generation = src->o_generation;
231 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
232 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
234 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
236 struct llu_inode_info *lli = llu_i2info(src);
237 struct intnl_stat *st = llu_i2stat(src);
238 obd_flag newvalid = 0;
240 if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
241 CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
242 valid, LTIME_S(st->st_mtime),
243 LTIME_S(st->st_ctime));
245 if (valid & OBD_MD_FLATIME) {
246 dst->o_atime = LTIME_S(st->st_atime);
247 newvalid |= OBD_MD_FLATIME;
249 if (valid & OBD_MD_FLMTIME) {
250 dst->o_mtime = LTIME_S(st->st_mtime);
251 newvalid |= OBD_MD_FLMTIME;
253 if (valid & OBD_MD_FLCTIME) {
254 dst->o_ctime = LTIME_S(st->st_ctime);
255 newvalid |= OBD_MD_FLCTIME;
257 if (valid & OBD_MD_FLSIZE) {
258 dst->o_size = st->st_size;
259 newvalid |= OBD_MD_FLSIZE;
261 if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */
262 dst->o_blocks = st->st_blocks;
263 newvalid |= OBD_MD_FLBLOCKS;
265 if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
266 dst->o_blksize = st->st_blksize;
267 newvalid |= OBD_MD_FLBLKSZ;
269 if (valid & OBD_MD_FLTYPE) {
270 dst->o_mode = (dst->o_mode & S_IALLUGO)|(st->st_mode & S_IFMT);
271 newvalid |= OBD_MD_FLTYPE;
273 if (valid & OBD_MD_FLMODE) {
274 dst->o_mode = (dst->o_mode & S_IFMT)|(st->st_mode & S_IALLUGO);
275 newvalid |= OBD_MD_FLMODE;
277 if (valid & OBD_MD_FLUID) {
278 dst->o_uid = st->st_uid;
279 newvalid |= OBD_MD_FLUID;
281 if (valid & OBD_MD_FLGID) {
282 dst->o_gid = st->st_gid;
283 newvalid |= OBD_MD_FLGID;
285 if (valid & OBD_MD_FLFLAGS) {
286 dst->o_flags = lli->lli_st_flags;
287 newvalid |= OBD_MD_FLFLAGS;
289 if (valid & OBD_MD_FLGENER) {
290 dst->o_generation = lli->lli_st_generation;
291 newvalid |= OBD_MD_FLGENER;
294 dst->o_valid |= newvalid;
298 * really does the getattr on the inode and updates its fields
300 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
302 struct llu_inode_info *lli = llu_i2info(inode);
303 struct obd_export *exp = llu_i2obdexp(inode);
304 struct ptlrpc_request_set *set;
306 obd_flag refresh_valid;
313 memset(&oa, 0, sizeof oa);
314 oa.o_id = lsm->lsm_object_id;
316 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
317 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
320 set = ptlrpc_prep_set();
322 CERROR ("ENOMEM allocing request set\n");
325 rc = obd_getattr_async(exp, &oa, lsm, set);
327 rc = ptlrpc_set_wait(set);
328 ptlrpc_set_destroy(set);
333 refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
334 OBD_MD_FLCTIME | OBD_MD_FLSIZE;
336 obdo_refresh_inode(inode, &oa, refresh_valid);
341 static struct inode* llu_new_inode(struct filesys *fs,
345 struct llu_inode_info *lli;
346 struct intnl_stat st = {
348 #ifndef AUTOMOUNT_FILE_NAME
349 st_mode: fid->f_type & S_IFMT,
351 st_mode: fid->f_type /* all of the bits! */
357 OBD_ALLOC(lli, sizeof(*lli));
361 /* initialize lli here */
362 lli->lli_sbi = llu_fs2sbi(fs);
364 lli->lli_symlink_name = NULL;
366 lli->lli_maxbytes = (__u64)(~0UL);
367 lli->lli_file_data = NULL;
369 lli->lli_sysio_fid.fid_data = &lli->lli_fid;
370 lli->lli_sysio_fid.fid_len = sizeof(lli->lli_fid);
372 memcpy(&lli->lli_fid, fid, sizeof(*fid));
374 /* file identifier is needed by functions like _sysio_i_find() */
375 inode = _sysio_i_new(fs, &lli->lli_sysio_fid,
376 &st, 0, &llu_inode_ops, lli);
379 OBD_FREE(lli, sizeof(*lli));
384 static int llu_have_md_lock(struct inode *inode)
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;
396 obddev = sbi->ll_mdc_exp->exp_obd;
397 res_id.name[0] = llu_i2stat(inode)->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_PLAIN,
405 NULL, LCK_PR, &lockh)) {
406 ldlm_lock_decref(&lockh, LCK_PR);
410 if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
411 NULL, LCK_PW, &lockh)) {
412 ldlm_lock_decref(&lockh, LCK_PW);
418 static int llu_inode_revalidate(struct inode *inode)
420 struct lov_stripe_md *lsm = NULL;
424 CERROR("REPORT THIS LINE TO PETER\n");
428 if (!llu_have_md_lock(inode)) {
430 struct ptlrpc_request *req = NULL;
431 struct llu_sb_info *sbi = llu_i2sbi(inode);
433 unsigned long valid = OBD_MD_FLGETATTR;
436 /* Why don't we update all valid MDS fields here, if we're
437 * doing an RPC anyways? -phil */
438 if (S_ISREG(llu_i2stat(inode)->st_mode)) {
439 ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
440 valid |= OBD_MD_FLEASIZE;
442 ll_inode2fid(&fid, inode);
443 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
445 CERROR("failure %d inode %llu\n", rc,
446 (long long)llu_i2stat(inode)->st_ino);
449 rc = mdc_req2lustre_md(req, 0, sbi->ll_osc_exp, &md);
451 /* XXX Too paranoid? */
452 if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) &&
453 !((md.body->valid & OBD_MD_FLNLINK) &&
454 (md.body->nlink == 0))) {
455 CERROR("Asked for %s eadata but got %s (%d)\n",
456 (valid & OBD_MD_FLEASIZE) ? "some" : "no",
457 (md.body->valid & OBD_MD_FLEASIZE) ? "some":"none",
458 md.body->eadatasize);
461 ptlrpc_req_finished(req);
466 llu_update_inode(inode, md.body, md.lsm);
467 if (md.lsm != NULL && llu_i2info(inode)->lli_smd != md.lsm)
468 obd_free_memmd(sbi->ll_osc_exp, &md.lsm);
470 if (md.body->valid & OBD_MD_FLSIZE)
471 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
472 &llu_i2info(inode)->lli_flags);
473 ptlrpc_req_finished(req);
476 lsm = llu_i2info(inode)->lli_smd;
477 if (!lsm) /* object not yet allocated, don't validate size */
480 /* ll_glimpse_size will prefer locally cached writes if they extend
482 RETURN(llu_glimpse_size(inode));
485 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
487 *b = *llu_i2stat(ino);
490 static int llu_iop_getattr(struct pnode *pno,
492 struct intnl_stat *b)
497 liblustre_wait_event(0);
501 LASSERT(pno->p_base->pb_ino);
502 ino = pno->p_base->pb_ino;
504 LASSERT(!pno || pno->p_base->pb_ino == ino);
507 /* libsysio might call us directly without intent lock,
508 * we must re-fetch the attrs here
510 rc = llu_inode_revalidate(ino);
512 copy_stat_buf(ino, b);
513 LASSERT(!llu_i2info(ino)->lli_it);
516 liblustre_wait_event(0);
520 static int null_if_equal(struct ldlm_lock *lock, void *data)
522 if (data == lock->l_ast_data) {
523 lock->l_ast_data = NULL;
525 if (lock->l_req_mode != lock->l_granted_mode)
526 LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
529 return LDLM_ITER_CONTINUE;
532 void llu_clear_inode(struct inode *inode)
535 struct llu_inode_info *lli = llu_i2info(inode);
536 struct llu_sb_info *sbi = llu_i2sbi(inode);
539 CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu/%lu(%p)\n",
540 (long long)llu_i2stat(inode)->st_ino, lli->lli_st_generation,
543 ll_inode2fid(&fid, inode);
544 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(lli->lli_flags));
545 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
548 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
549 null_if_equal, inode);
552 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
556 if (lli->lli_symlink_name) {
557 OBD_FREE(lli->lli_symlink_name,
558 strlen(lli->lli_symlink_name) + 1);
559 lli->lli_symlink_name = NULL;
565 void llu_iop_gone(struct inode *inode)
567 struct llu_inode_info *lli = llu_i2info(inode);
570 liblustre_wait_event(0);
571 llu_clear_inode(inode);
573 OBD_FREE(lli, sizeof(*lli));
577 static int inode_setattr(struct inode * inode, struct iattr * attr)
579 unsigned int ia_valid = attr->ia_valid;
580 struct intnl_stat *st = llu_i2stat(inode);
584 * inode_setattr() is only ever invoked with ATTR_SIZE (by
585 * llu_setattr_raw()) when file has no bodies. Check this.
587 LASSERT(ergo(ia_valid & ATTR_SIZE, llu_i2info(inode)->lli_smd == NULL));
589 if (ia_valid & ATTR_SIZE)
590 st->st_size = attr->ia_size;
591 if (ia_valid & ATTR_UID)
592 st->st_uid = attr->ia_uid;
593 if (ia_valid & ATTR_GID)
594 st->st_gid = attr->ia_gid;
595 if (ia_valid & ATTR_ATIME)
596 st->st_atime = attr->ia_atime;
597 if (ia_valid & ATTR_MTIME)
598 st->st_mtime = attr->ia_mtime;
599 if (ia_valid & ATTR_CTIME)
600 st->st_ctime = attr->ia_ctime;
601 if (ia_valid & ATTR_MODE) {
602 st->st_mode = attr->ia_mode;
603 if (!in_group_p(st->st_gid) && !capable(CAP_FSETID))
604 st->st_mode &= ~S_ISGID;
606 /* mark_inode_dirty(inode); */
610 /* If this inode has objects allocated to it (lsm != NULL), then the OST
611 * object(s) determine the file size and mtime. Otherwise, the MDS will
612 * keep these values until such a time that objects are allocated for it.
613 * We do the MDS operations first, as it is checking permissions for us.
614 * We don't to the MDS RPC if there is nothing that we want to store there,
615 * otherwise there is no harm in updating mtime/atime on the MDS if we are
616 * going to do an RPC anyways.
618 * If we are doing a truncate, we will send the mtime and ctime updates
619 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
620 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
623 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
625 struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
626 struct llu_sb_info *sbi = llu_i2sbi(inode);
627 struct intnl_stat *st = llu_i2stat(inode);
628 struct ptlrpc_request *request = NULL;
629 struct mdc_op_data op_data;
630 int ia_valid = attr->ia_valid;
634 CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu\n", (long long)st->st_ino);
636 if (ia_valid & ATTR_SIZE) {
637 if (attr->ia_size > ll_file_maxbytes(inode)) {
638 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
639 (long long)attr->ia_size,
640 ll_file_maxbytes(inode));
644 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
647 /* We mark all of the fields "set" so MDS/OST does not re-set them */
648 if (attr->ia_valid & ATTR_CTIME) {
649 attr->ia_ctime = CURRENT_TIME;
650 attr->ia_valid |= ATTR_CTIME_SET;
652 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
653 attr->ia_atime = CURRENT_TIME;
654 attr->ia_valid |= ATTR_ATIME_SET;
656 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
657 attr->ia_mtime = CURRENT_TIME;
658 attr->ia_valid |= ATTR_MTIME_SET;
661 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
662 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
663 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
664 LTIME_S(CURRENT_TIME));
666 attr->ia_valid &= ~ATTR_SIZE;
668 /* If only OST attributes being set on objects, don't do MDS RPC.
669 * In that case, we need to check permissions and update the local
670 * inode ourselves so we can call obdo_from_inode() always. */
671 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
673 llu_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
675 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
676 attr, NULL, 0, NULL, 0, &request);
679 ptlrpc_req_finished(request);
680 if (rc != -EPERM && rc != -EACCES)
681 CERROR("mdc_setattr fails: rc = %d\n", rc);
685 rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
687 ptlrpc_req_finished(request);
691 /* We call inode_setattr to adjust timestamps.
692 * If there is at least some data in file, we cleared ATTR_SIZE
693 * above to avoid invoking vmtruncate, otherwise it is important
694 * to call vmtruncate in inode_setattr to update inode->i_size
696 inode_setattr(inode, attr);
697 llu_update_inode(inode, md.body, md.lsm);
698 ptlrpc_req_finished(request);
700 if (!lsm || !S_ISREG(st->st_mode)) {
701 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
705 /* The OST doesn't check permissions, but the alternative is
706 * a gratuitous RPC to the MDS. We already rely on the client
707 * to do read/write/truncate permission checks, so is mtime OK?
709 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
710 /* from sys_utime() */
711 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
712 if (current->fsuid != st->st_uid &&
713 (rc = ll_permission(inode, MAY_WRITE)) != 0)
716 /* from inode_change_ok() */
717 if (current->fsuid != st->st_uid &&
718 !capable(CAP_FOWNER))
723 /* Won't invoke llu_vmtruncate(), as we already cleared
725 inode_setattr(inode, attr);
728 if (ia_valid & ATTR_SIZE) {
729 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
731 struct lustre_handle lockh = { 0, };
732 struct lustre_handle match_lockh = { 0, };
735 int flags = LDLM_FL_TEST_LOCK; /* for assertion check below */
739 /* check that there are no matching locks */
740 LASSERT(obd_match(sbi->ll_osc_exp, lsm, LDLM_EXTENT, &policy,
741 LCK_PW, &flags, inode, &match_lockh) <= 0);
743 /* XXX when we fix the AST intents to pass the discard-range
744 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
746 flags = (attr->ia_size == 0) ? LDLM_AST_DISCARD_DATA : 0;
748 if (sbi->ll_lco.lco_flags & OBD_CONNECT_TRUNCLOCK) {
750 obd_flags = OBD_FL_TRUNCLOCK;
751 CDEBUG(D_INODE, "delegating locking to the OST");
757 /* with lock_mode == LK_NL no lock is taken. */
758 rc = llu_extent_lock(NULL, inode, lsm, lock_mode, &policy,
760 if (rc != ELDLM_OK) {
766 rc = llu_vmtruncate(inode, attr->ia_size, obd_flags);
768 /* unlock now as we don't mind others file lockers racing with
769 * the mds updates below? */
770 err = llu_extent_unlock(NULL, inode, lsm, lock_mode, &lockh);
772 CERROR("llu_extent_unlock failed: %d\n", err);
776 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
779 CDEBUG(D_INODE, "set mtime on OST inode %llu to %lu\n",
780 (long long)st->st_ino, LTIME_S(attr->ia_mtime));
781 oa.o_id = lsm->lsm_object_id;
782 oa.o_valid = OBD_MD_FLID;
783 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
784 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
785 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
787 CERROR("obd_setattr fails: rc=%d\n", rc);
792 /* here we simply act as a thin layer to glue it with
793 * llu_setattr_raw(), which is copy from kernel
795 static int llu_iop_setattr(struct pnode *pno,
798 struct intnl_stat *stbuf)
804 liblustre_wait_event(0);
806 LASSERT(!(mask & ~(SETATTR_MTIME | SETATTR_ATIME |
807 SETATTR_UID | SETATTR_GID |
808 SETATTR_LEN | SETATTR_MODE)));
809 memset(&iattr, 0, sizeof(iattr));
811 if (mask & SETATTR_MODE) {
812 iattr.ia_mode = stbuf->st_mode;
813 iattr.ia_valid |= ATTR_MODE;
815 if (mask & SETATTR_MTIME) {
816 iattr.ia_mtime = stbuf->st_mtime;
817 iattr.ia_valid |= ATTR_MTIME;
819 if (mask & SETATTR_ATIME) {
820 iattr.ia_atime = stbuf->st_atime;
821 iattr.ia_valid |= ATTR_ATIME;
823 if (mask & SETATTR_UID) {
824 iattr.ia_uid = stbuf->st_uid;
825 iattr.ia_valid |= ATTR_UID;
827 if (mask & SETATTR_GID) {
828 iattr.ia_gid = stbuf->st_gid;
829 iattr.ia_valid |= ATTR_GID;
831 if (mask & SETATTR_LEN) {
832 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
833 iattr.ia_valid |= ATTR_SIZE;
836 iattr.ia_valid |= ATTR_RAW | ATTR_CTIME;
837 iattr.ia_ctime = CURRENT_TIME;
839 rc = llu_setattr_raw(ino, &iattr);
840 liblustre_wait_event(0);
844 #define EXT2_LINK_MAX 32000
846 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
848 struct inode *dir = pno->p_base->pb_parent->pb_ino;
849 struct qstr *qstr = &pno->p_base->pb_name;
850 const char *name = qstr->name;
852 struct ptlrpc_request *request = NULL;
853 struct llu_sb_info *sbi = llu_i2sbi(dir);
854 struct mdc_op_data op_data;
858 liblustre_wait_event(0);
859 if (llu_i2stat(dir)->st_nlink >= EXT2_LINK_MAX)
862 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
863 err = mdc_create(sbi->ll_mdc_exp, &op_data,
864 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
865 current->fsuid, current->fsgid, current->cap_effective,
867 ptlrpc_req_finished(request);
868 liblustre_wait_event(0);
872 static int llu_readlink_internal(struct inode *inode,
873 struct ptlrpc_request **request,
876 struct llu_inode_info *lli = llu_i2info(inode);
877 struct llu_sb_info *sbi = llu_i2sbi(inode);
879 struct mds_body *body;
880 struct intnl_stat *st = llu_i2stat(inode);
881 int rc, symlen = st->st_size + 1;
886 if (lli->lli_symlink_name) {
887 *symname = lli->lli_symlink_name;
888 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
892 ll_inode2fid(&fid, inode);
893 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
894 OBD_MD_LINKNAME, symlen, request);
896 CERROR("inode %llu: rc = %d\n", (long long)st->st_ino, rc);
900 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
901 LASSERT (body != NULL);
902 LASSERT_REPSWABBED (*request, 0);
904 if ((body->valid & OBD_MD_LINKNAME) == 0) {
905 CERROR ("OBD_MD_LINKNAME not set on reply\n");
906 GOTO (failed, rc = -EPROTO);
909 LASSERT(symlen != 0);
910 if (body->eadatasize != symlen) {
911 CERROR("inode %llu: symlink length %d not expected %d\n",
912 (long long)st->st_ino, body->eadatasize - 1, symlen - 1);
913 GOTO(failed, rc = -EPROTO);
916 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
917 if (*symname == NULL ||
918 strnlen(*symname, symlen) != symlen - 1) {
919 /* not full/NULL terminated */
920 CERROR("inode %llu: symlink not NULL terminated string"
921 "of length %d\n", (long long)st->st_ino, symlen - 1);
922 GOTO(failed, rc = -EPROTO);
925 OBD_ALLOC(lli->lli_symlink_name, symlen);
926 /* do not return an error if we cannot cache the symlink locally */
927 if (lli->lli_symlink_name)
928 memcpy(lli->lli_symlink_name, *symname, symlen);
933 ptlrpc_req_finished (*request);
937 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
939 struct inode *inode = pno->p_base->pb_ino;
940 struct ptlrpc_request *request;
945 liblustre_wait_event(0);
946 rc = llu_readlink_internal(inode, &request, &symname);
951 strncpy(data, symname, bufsize);
952 rc = strlen(symname);
954 ptlrpc_req_finished(request);
956 liblustre_wait_event(0);
960 static int llu_iop_mknod_raw(struct pnode *pno,
964 struct ptlrpc_request *request = NULL;
965 struct inode *dir = pno->p_parent->p_base->pb_ino;
966 struct llu_sb_info *sbi = llu_i2sbi(dir);
967 struct mdc_op_data op_data;
971 liblustre_wait_event(0);
972 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%llu\n",
973 (int)pno->p_base->pb_name.len, pno->p_base->pb_name.name,
974 (long long)llu_i2stat(dir)->st_ino);
976 if (llu_i2stat(dir)->st_nlink >= EXT2_LINK_MAX)
979 switch (mode & S_IFMT) {
982 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
987 llu_prepare_mdc_op_data(&op_data, dir, NULL,
988 pno->p_base->pb_name.name,
989 pno->p_base->pb_name.len,
991 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
992 current->fsuid, current->fsgid,
993 current->cap_effective, dev, &request);
994 ptlrpc_req_finished(request);
1002 liblustre_wait_event(0);
1006 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
1008 struct inode *src = old->p_base->pb_ino;
1009 struct inode *dir = new->p_parent->p_base->pb_ino;
1010 const char *name = new->p_base->pb_name.name;
1011 int namelen = new->p_base->pb_name.len;
1012 struct ptlrpc_request *request = NULL;
1013 struct mdc_op_data op_data;
1020 liblustre_wait_event(0);
1021 llu_prepare_mdc_op_data(&op_data, src, dir, name, namelen, 0);
1022 rc = mdc_link(llu_i2sbi(src)->ll_mdc_exp, &op_data, &request);
1023 ptlrpc_req_finished(request);
1024 liblustre_wait_event(0);
1030 * libsysio will clear the inode immediately after return
1032 static int llu_iop_unlink_raw(struct pnode *pno)
1034 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1035 struct qstr *qstr = &pno->p_base->pb_name;
1036 const char *name = qstr->name;
1037 int len = qstr->len;
1038 struct inode *target = pno->p_base->pb_ino;
1039 struct ptlrpc_request *request = NULL;
1040 struct mdc_op_data op_data;
1046 liblustre_wait_event(0);
1047 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1048 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1050 rc = llu_objects_destroy(request, dir);
1051 ptlrpc_req_finished(request);
1052 liblustre_wait_event(0);
1057 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
1059 struct inode *src = old->p_parent->p_base->pb_ino;
1060 struct inode *tgt = new->p_parent->p_base->pb_ino;
1061 const char *oldname = old->p_base->pb_name.name;
1062 int oldnamelen = old->p_base->pb_name.len;
1063 const char *newname = new->p_base->pb_name.name;
1064 int newnamelen = new->p_base->pb_name.len;
1065 struct ptlrpc_request *request = NULL;
1066 struct mdc_op_data op_data;
1073 liblustre_wait_event(0);
1074 llu_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0);
1075 rc = mdc_rename(llu_i2sbi(src)->ll_mdc_exp, &op_data,
1076 oldname, oldnamelen, newname, newnamelen,
1079 rc = llu_objects_destroy(request, src);
1082 ptlrpc_req_finished(request);
1083 liblustre_wait_event(0);
1088 #ifdef _HAVE_STATVFS
1089 static int llu_statfs_internal(struct llu_sb_info *sbi,
1090 struct obd_statfs *osfs,
1091 unsigned long max_age)
1093 struct obd_statfs obd_osfs;
1097 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1099 CERROR("mdc_statfs fails: rc = %d\n", rc);
1103 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1104 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1106 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1108 CERROR("obd_statfs fails: rc = %d\n", rc);
1112 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1113 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1116 osfs->os_blocks = obd_osfs.os_blocks;
1117 osfs->os_bfree = obd_osfs.os_bfree;
1118 osfs->os_bavail = obd_osfs.os_bavail;
1120 /* If we don't have as many objects free on the OST as inodes
1121 * on the MDS, we reduce the total number of inodes to
1122 * compensate, so that the "inodes in use" number is correct.
1124 if (obd_osfs.os_ffree < osfs->os_ffree) {
1125 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1127 osfs->os_ffree = obd_osfs.os_ffree;
1133 static int llu_statfs(struct llu_sb_info *sbi, struct statfs *sfs)
1135 struct obd_statfs osfs;
1138 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1140 /* For now we will always get up-to-date statfs values, but in the
1141 * future we may allow some amount of caching on the client (e.g.
1142 * from QOS or lprocfs updates). */
1143 rc = llu_statfs_internal(sbi, &osfs, jiffies - 1);
1147 statfs_unpack(sfs, &osfs);
1149 if (sizeof(sfs->f_blocks) == 4) {
1150 while (osfs.os_blocks > ~0UL) {
1153 osfs.os_blocks >>= 1;
1154 osfs.os_bfree >>= 1;
1155 osfs.os_bavail >>= 1;
1159 sfs->f_blocks = osfs.os_blocks;
1160 sfs->f_bfree = osfs.os_bfree;
1161 sfs->f_bavail = osfs.os_bavail;
1166 static int llu_iop_statvfs(struct pnode *pno,
1168 struct intnl_statvfs *buf)
1174 liblustre_wait_event(0);
1177 LASSERT(pno->p_base->pb_ino);
1178 rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1182 /* from native driver */
1183 buf->f_bsize = fs.f_bsize; /* file system block size */
1184 buf->f_frsize = fs.f_bsize; /* file system fundamental block size */
1185 buf->f_blocks = fs.f_blocks;
1186 buf->f_bfree = fs.f_bfree;
1187 buf->f_bavail = fs.f_bavail;
1188 buf->f_files = fs.f_files; /* Total number serial numbers */
1189 buf->f_ffree = fs.f_ffree; /* Number free serial numbers */
1190 buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/
1191 buf->f_fsid = fs.f_fsid.__val[1];
1192 buf->f_flag = 0; /* No equiv in statfs; maybe use type? */
1193 buf->f_namemax = fs.f_namelen;
1196 liblustre_wait_event(0);
1199 #endif /* _HAVE_STATVFS */
1201 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1203 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1204 struct qstr *qstr = &pno->p_base->pb_name;
1205 const char *name = qstr->name;
1206 int len = qstr->len;
1207 struct ptlrpc_request *request = NULL;
1208 struct intnl_stat *st = llu_i2stat(dir);
1209 struct mdc_op_data op_data;
1213 liblustre_wait_event(0);
1214 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%llu/%lu(%p)\n", len, name,
1215 (long long)st->st_ino, llu_i2info(dir)->lli_st_generation, dir);
1217 if (st->st_nlink >= EXT2_LINK_MAX)
1220 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, 0);
1221 err = mdc_create(llu_i2sbi(dir)->ll_mdc_exp, &op_data, NULL, 0, mode,
1222 current->fsuid, current->fsgid, current->cap_effective,
1224 ptlrpc_req_finished(request);
1225 liblustre_wait_event(0);
1229 static int llu_iop_rmdir_raw(struct pnode *pno)
1231 struct inode *dir = pno->p_base->pb_parent->pb_ino;
1232 struct qstr *qstr = &pno->p_base->pb_name;
1233 const char *name = qstr->name;
1234 int len = qstr->len;
1235 struct ptlrpc_request *request = NULL;
1236 struct mdc_op_data op_data;
1240 liblustre_wait_event(0);
1241 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%llu/%lu(%p)\n", len, name,
1242 (long long)llu_i2stat(dir)->st_ino,
1243 llu_i2info(dir)->lli_st_generation, dir);
1245 llu_prepare_mdc_op_data(&op_data, dir, NULL, name, len, S_IFDIR);
1246 rc = mdc_unlink(llu_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
1247 ptlrpc_req_finished(request);
1249 liblustre_wait_event(0);
1254 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC|O_DIRECT)
1256 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC)
1258 #define FCNTL_FLMASK_INVALID (O_NONBLOCK|O_ASYNC)
1260 /* refer to ll_file_flock() for details */
1261 static int llu_file_flock(struct inode *ino,
1263 struct file_lock *file_lock)
1265 struct obd_device *obddev;
1266 struct llu_inode_info *lli = llu_i2info(ino);
1267 struct intnl_stat *st = llu_i2stat(ino);
1268 struct ldlm_res_id res_id =
1269 { .name = {st->st_ino,
1270 lli->lli_st_generation, LDLM_FLOCK} };
1271 struct lustre_handle lockh = {0};
1272 ldlm_policy_data_t flock;
1273 ldlm_mode_t mode = 0;
1277 CDEBUG(D_VFSTRACE, "VFS Op:inode="LPU64" file_lock=%p\n",
1278 st->st_ino, file_lock);
1280 flock.l_flock.pid = file_lock->fl_pid;
1281 flock.l_flock.start = file_lock->fl_start;
1282 flock.l_flock.end = file_lock->fl_end;
1284 switch (file_lock->fl_type) {
1295 CERROR("unknown fcntl lock type: %d\n", file_lock->fl_type);
1302 #if F_SETLKW64 != F_SETLKW
1310 #if F_SETLK64 != F_SETLK
1314 flags = LDLM_FL_BLOCK_NOWAIT;
1318 #if F_GETLK64 != F_GETLK
1322 flags = LDLM_FL_TEST_LOCK;
1323 file_lock->fl_type = mode;
1326 CERROR("unknown fcntl cmd: %d\n", cmd);
1330 CDEBUG(D_DLMTRACE, "inode="LPU64", pid=%u, flags=%#x, mode=%u, "
1331 "start="LPU64", end="LPU64"\n", st->st_ino, flock.l_flock.pid,
1332 flags, mode, flock.l_flock.start, flock.l_flock.end);
1334 obddev = llu_i2mdcexp(ino)->exp_obd;
1335 rc = ldlm_cli_enqueue(llu_i2mdcexp(ino), NULL, obddev->obd_namespace,
1336 res_id, LDLM_FLOCK, &flock, mode, &flags,
1337 NULL, ldlm_flock_completion_ast, NULL, file_lock,
1338 NULL, 0, NULL, &lockh);
1342 static int assign_type(struct file_lock *fl, int type)
1355 static int flock_to_posix_lock(struct inode *ino,
1356 struct file_lock *fl,
1359 switch (l->l_whence) {
1360 /* XXX: only SEEK_SET is supported in lustre */
1368 fl->fl_end = l->l_len - 1;
1372 fl->fl_end = OFFSET_MAX;
1374 fl->fl_pid = getpid();
1375 fl->fl_flags = FL_POSIX;
1376 fl->fl_notify = NULL;
1377 fl->fl_insert = NULL;
1378 fl->fl_remove = NULL;
1379 /* XXX: these fields can't be filled with suitable values,
1380 but I think lustre doesn't use them.
1382 fl->fl_owner = NULL;
1385 return assign_type(fl, l->l_type);
1388 static int llu_fcntl_getlk(struct inode *ino, struct flock *flock)
1390 struct file_lock fl;
1394 if ((flock->l_type != F_RDLCK) && (flock->l_type != F_WRLCK))
1397 error = flock_to_posix_lock(ino, &fl, flock);
1401 error = llu_file_flock(ino, F_GETLK, &fl);
1405 flock->l_type = F_UNLCK;
1406 if (fl.fl_type != F_UNLCK) {
1407 flock->l_pid = fl.fl_pid;
1408 flock->l_start = fl.fl_start;
1409 flock->l_len = fl.fl_end == OFFSET_MAX ? 0:
1410 fl.fl_end - fl.fl_start + 1;
1411 flock->l_whence = SEEK_SET;
1412 flock->l_type = fl.fl_type;
1419 static int llu_fcntl_setlk(struct inode *ino, int cmd, struct flock *flock)
1421 struct file_lock fl;
1422 int flags = llu_i2info(ino)->lli_open_flags + 1;
1425 error = flock_to_posix_lock(ino, &fl, flock);
1428 if (cmd == F_SETLKW)
1429 fl.fl_flags |= FL_SLEEP;
1432 switch (flock->l_type) {
1434 if (!(flags & FMODE_READ))
1438 if (!(flags & FMODE_WRITE))
1448 error = llu_file_flock(ino, cmd, &fl);
1456 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn)
1458 struct llu_inode_info *lli = llu_i2info(ino);
1460 struct flock *flock;
1463 liblustre_wait_event(0);
1466 *rtn = lli->lli_open_flags;
1469 flags = va_arg(ap, long);
1470 flags &= FCNTL_FLMASK;
1471 if (flags & FCNTL_FLMASK_INVALID) {
1472 CERROR("liblustre don't support O_NONBLOCK, O_ASYNC, "
1473 "and O_DIRECT on file descriptor\n");
1478 lli->lli_open_flags = (int)(flags & FCNTL_FLMASK) |
1479 (lli->lli_open_flags & ~FCNTL_FLMASK);
1484 #if F_GETLK64 != F_GETLK
1488 flock = va_arg(ap, struct flock *);
1489 err = llu_fcntl_getlk(ino, flock);
1494 #if F_SETLKW64 != F_SETLKW
1500 #if F_SETLK64 != F_SETLK
1504 flock = va_arg(ap, struct flock *);
1505 err = llu_fcntl_setlk(ino, cmd, flock);
1509 CERROR("unsupported fcntl cmd %x\n", cmd);
1515 liblustre_wait_event(0);
1519 static int llu_get_grouplock(struct inode *inode, unsigned long arg)
1521 struct llu_inode_info *lli = llu_i2info(inode);
1522 struct ll_file_data *fd = lli->lli_file_data;
1523 ldlm_policy_data_t policy = { .l_extent = { .start = 0,
1524 .end = OBD_OBJECT_EOF}};
1525 struct lustre_handle lockh = { 0 };
1526 struct lov_stripe_md *lsm = lli->lli_smd;
1531 if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
1535 policy.l_extent.gid = arg;
1536 if (lli->lli_open_flags & O_NONBLOCK)
1537 flags = LDLM_FL_BLOCK_NOWAIT;
1539 err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
1544 fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
1546 memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
1551 static int llu_put_grouplock(struct inode *inode, unsigned long arg)
1553 struct llu_inode_info *lli = llu_i2info(inode);
1554 struct ll_file_data *fd = lli->lli_file_data;
1555 struct lov_stripe_md *lsm = lli->lli_smd;
1559 if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
1562 if (fd->fd_gid != arg)
1565 fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
1567 err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
1572 memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
1577 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1583 liblustre_wait_event(0);
1586 case LL_IOC_GROUP_LOCK:
1587 arg = va_arg(ap, unsigned long);
1588 rc = llu_get_grouplock(ino, arg);
1590 case LL_IOC_GROUP_UNLOCK:
1591 arg = va_arg(ap, unsigned long);
1592 rc = llu_put_grouplock(ino, arg);
1595 CERROR("did not support ioctl cmd %lx\n", request);
1600 liblustre_wait_event(0);
1605 * we already do syncronous read/write
1607 static int llu_iop_sync(struct inode *inode)
1609 liblustre_wait_event(0);
1613 static int llu_iop_datasync(struct inode *inode)
1615 liblustre_wait_event(0);
1619 struct filesys_ops llu_filesys_ops =
1621 fsop_gone: llu_fsop_gone,
1624 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1626 struct inode *inode;
1628 struct file_identifier fileid = {&fid, sizeof(fid)};
1630 if ((md->body->valid &
1631 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) !=
1632 (OBD_MD_FLGENER | OBD_MD_FLID | OBD_MD_FLTYPE)) {
1633 CERROR("bad md body valid mask "LPX64"\n", md->body->valid);
1635 return ERR_PTR(-EPERM);
1638 /* try to find existing inode */
1639 fid.id = md->body->ino;
1640 fid.generation = md->body->generation;
1641 fid.f_type = md->body->mode & S_IFMT;
1643 inode = _sysio_i_find(fs, &fileid);
1645 struct llu_inode_info *lli = llu_i2info(inode);
1647 if (inode->i_zombie ||
1648 lli->lli_st_generation != md->body->generation) {
1652 llu_update_inode(inode, md->body, md->lsm);
1657 inode = llu_new_inode(fs, &fid);
1659 llu_update_inode(inode, md->body, md->lsm);
1664 extern struct list_head lustre_profile_list;
1667 llu_fsswop_mount(const char *source,
1669 const void *data __IS_UNUSED,
1670 struct pnode *tocover,
1671 struct mount **mntp)
1675 struct pnode_base *rootpb;
1676 struct obd_device *obd;
1677 struct ll_fid rootfid;
1678 struct llu_sb_info *sbi;
1679 struct obd_statfs osfs;
1680 static struct qstr noname = { NULL, 0, 0 };
1681 struct ptlrpc_request *request = NULL;
1682 struct lustre_handle mdc_conn = {0, };
1683 struct lustre_handle osc_conn = {0, };
1684 struct lustre_md md;
1686 struct config_llog_instance cfg;
1687 char ll_instance[sizeof(sbi) * 2 + 1];
1688 struct lustre_profile *lprof;
1689 char *zconf_mdsnid, *zconf_mdsname, *zconf_profile;
1690 char *osc = NULL, *mdc = NULL;
1691 int async = 1, err = -EINVAL;
1692 struct obd_connect_data ocd = {0,};
1696 if (ll_parse_mount_target(source,
1700 CERROR("mal-formed target %s\n", source);
1703 if (!zconf_mdsnid || !zconf_mdsname || !zconf_profile) {
1704 printf("Liblustre: invalid target %s\n", source);
1707 /* allocate & initialize sbi */
1708 OBD_ALLOC(sbi, sizeof(*sbi));
1712 INIT_LIST_HEAD(&sbi->ll_conn_chain);
1713 generate_random_uuid(uuid);
1714 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1716 /* generate a string unique to this super, let's try
1717 the address of the super itself.*/
1718 sprintf(ll_instance, "%p", sbi);
1720 /* retrive & parse config log */
1721 cfg.cfg_instance = ll_instance;
1722 cfg.cfg_uuid = sbi->ll_sb_uuid;
1723 err = liblustre_process_log(&cfg, zconf_mdsnid, zconf_mdsname,
1726 CERROR("Unable to process log: %s\n", zconf_profile);
1727 GOTO(out_free, err);
1730 lprof = class_get_profile(zconf_profile);
1731 if (lprof == NULL) {
1732 CERROR("No profile found: %s\n", zconf_profile);
1733 GOTO(out_free, err = -EINVAL);
1735 OBD_ALLOC(osc, strlen(lprof->lp_osc) + strlen(ll_instance) + 2);
1736 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
1738 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) + strlen(ll_instance) + 2);
1739 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
1743 GOTO(out_free, err = -EINVAL);
1747 GOTO(out_free, err = -EINVAL);
1750 fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1756 obd = class_name2obd(mdc);
1758 CERROR("MDC %s: not setup or attached\n", mdc);
1759 GOTO(out_free, err = -EINVAL);
1761 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1762 sizeof(async), &async);
1764 ocd.ocd_connect_flags = OBD_CONNECT_VERSION;
1765 ocd.ocd_version = LUSTRE_VERSION_CODE;
1768 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, &ocd);
1770 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
1771 GOTO(out_free, err);
1773 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
1775 err = obd_statfs(obd, &osfs, 100000000);
1780 * FIXME fill fs stat data into sbi here!!! FIXME
1784 obd = class_name2obd(osc);
1786 CERROR("OSC %s: not setup or attached\n", osc);
1787 GOTO(out_mdc, err = -EINVAL);
1789 obd_set_info(obd->obd_self_export, strlen("async"), "async",
1790 sizeof(async), &async);
1792 obd->obd_upcall.onu_owner = &sbi->ll_lco;
1793 obd->obd_upcall.onu_upcall = ll_ocd_update;
1795 ocd.ocd_connect_flags = OBD_CONNECT_SRVLOCK|OBD_CONNECT_REQPORTAL|
1796 OBD_CONNECT_VERSION|OBD_CONNECT_TRUNCLOCK;
1797 ocd.ocd_version = LUSTRE_VERSION_CODE;
1798 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, &ocd);
1800 CERROR("cannot connect to %s: rc = %d\n", osc, err);
1803 sbi->ll_osc_exp = class_conn2export(&osc_conn);
1804 sbi->ll_lco.lco_flags = ocd.ocd_connect_flags;
1806 mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
1808 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
1810 CERROR("cannot mds_connect: rc = %d\n", err);
1813 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
1814 sbi->ll_rootino = rootfid.id;
1816 /* fetch attr of root inode */
1817 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
1818 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS, 0, &request);
1820 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1824 err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
1826 CERROR("failed to understand root inode md: rc = %d\n",err);
1827 GOTO(out_request, err);
1830 LASSERT(sbi->ll_rootino != 0);
1832 root = llu_iget(fs, &md);
1833 if (!root || IS_ERR(root)) {
1834 CERROR("fail to generate root inode\n");
1835 GOTO(out_request, err = -EBADF);
1839 * Generate base path-node for root.
1841 rootpb = _sysio_pb_new(&noname, NULL, root);
1847 err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1849 _sysio_pb_gone(rootpb);
1853 ptlrpc_req_finished(request);
1855 CDEBUG(D_SUPER, "LibLustre: %s mounted successfully!\n", source);
1856 liblustre_wait_event(0);
1861 _sysio_i_gone(root);
1863 ptlrpc_req_finished(request);
1865 obd_disconnect(sbi->ll_osc_exp);
1867 obd_disconnect(sbi->ll_mdc_exp);
1870 OBD_FREE(osc, strlen(osc) + 1);
1872 OBD_FREE(mdc, strlen(mdc) + 1);
1873 OBD_FREE(sbi, sizeof(*sbi));
1877 struct fssw_ops llu_fssw_ops = {
1881 static struct inode_ops llu_inode_ops = {
1882 inop_lookup: llu_iop_lookup,
1883 inop_getattr: llu_iop_getattr,
1884 inop_setattr: llu_iop_setattr,
1885 inop_getdirentries: llu_iop_getdirentries,
1886 inop_mkdir: llu_iop_mkdir_raw,
1887 inop_rmdir: llu_iop_rmdir_raw,
1888 inop_symlink: llu_iop_symlink_raw,
1889 inop_readlink: llu_iop_readlink,
1890 inop_open: llu_iop_open,
1891 inop_close: llu_iop_close,
1892 inop_link: llu_iop_link_raw,
1893 inop_unlink: llu_iop_unlink_raw,
1894 inop_rename: llu_iop_rename_raw,
1895 inop_pos: llu_iop_pos,
1896 inop_read: llu_iop_read,
1897 inop_write: llu_iop_write,
1898 inop_iodone: llu_iop_iodone,
1899 inop_fcntl: llu_iop_fcntl,
1900 inop_sync: llu_iop_sync,
1901 inop_datasync: llu_iop_datasync,
1902 inop_ioctl: llu_iop_ioctl,
1903 inop_mknod: llu_iop_mknod_raw,
1904 #ifdef _HAVE_STATVFS
1905 inop_statvfs: llu_iop_statvfs,
1907 inop_gone: llu_iop_gone,