Whamcloud - gitweb
Branch b1_4_mountconf
[fs/lustre-release.git] / lustre / liblustre / super.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Light Super operations
5  *
6  *  Copyright (c) 2002-2004 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
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.
13  *
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.
18  *
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.
22  */
23
24 #define DEBUG_SUBSYSTEM S_LLITE
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <assert.h>
29 #include <time.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #include <sys/queue.h>
34 #ifndef __CYGWIN__
35 # include <sys/statvfs.h>
36 #else
37 # include <sys/statfs.h>
38 #endif
39
40 #ifdef HAVE_XTIO_H
41 #include <xtio.h>
42 #endif
43 #include <sysio.h>
44 #include <fs.h>
45 #include <mount.h>
46 #include <inode.h>
47 #ifdef HAVE_FILE_H
48 #include <file.h>
49 #endif
50
51 #undef LIST_HEAD
52
53 #include "llite_lib.h"
54 #include <linux/lustre_ver.h>
55
56 #ifndef MAY_EXEC
57 #define MAY_EXEC        1
58 #define MAY_WRITE       2
59 #define MAY_READ        4
60 #endif
61
62 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
63
64 static int ll_permission(struct inode *inode, int mask)
65 {
66         struct intnl_stat *st = llu_i2stat(inode);
67         mode_t mode = st->st_mode;
68
69         if (current->fsuid == st->st_uid)
70                 mode >>= 6;
71         else if (in_group_p(st->st_gid))
72                 mode >>= 3;
73
74         if ((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask)
75                 return 0;
76
77         if ((mask & (MAY_READ|MAY_WRITE)) ||
78             (st->st_mode & S_IXUGO))
79                 if (capable(CAP_DAC_OVERRIDE))
80                         return 0;
81
82         if (mask == MAY_READ ||
83             (S_ISDIR(st->st_mode) && !(mask & MAY_WRITE))) {
84                 if (capable(CAP_DAC_READ_SEARCH))
85                         return 0;
86         }
87
88         return -EACCES;
89 }
90
91 static void llu_fsop_gone(struct filesys *fs)
92 {
93         struct llu_sb_info *sbi = (struct llu_sb_info *) fs->fs_private;
94         struct obd_device *obd = class_exp2obd(sbi->ll_mdc_exp);
95         int next = 0;
96         ENTRY;
97
98         list_del(&sbi->ll_conn_chain);
99         obd_disconnect(sbi->ll_osc_exp);
100         obd_disconnect(sbi->ll_mdc_exp);
101
102         while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL){
103                 struct lustre_cfg_bufs bufs;
104                 struct lustre_cfg *lcfg;
105                 int err;
106
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);
111                 if (err)
112                         CERROR("cleanup failed: %s\n", obd->obd_name);
113
114                 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
115                 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
116                 err = class_process_config(lcfg);
117                 if (err)
118                         CERROR("detach failed: %s\n", obd->obd_name);
119         }
120
121         OBD_FREE(sbi, sizeof(*sbi));
122
123         EXIT;
124 }
125
126 static struct inode_ops llu_inode_ops;
127
128 void llu_update_inode(struct inode *inode, struct mds_body *body,
129                       struct lov_stripe_md *lsm)
130 {
131         struct llu_inode_info *lli = llu_i2info(inode);
132         struct intnl_stat *st = llu_i2stat(inode);
133
134         LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
135         if (lsm != NULL) {
136                 if (lli->lli_smd == NULL) {
137                         lli->lli_smd = lsm;
138                         lli->lli_maxbytes = lsm->lsm_maxbytes;
139                         if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
140                                 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
141                 } else {
142                         if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
143                                 CERROR("lsm mismatch for inode %lld\n",
144                                        (long long)st->st_ino);
145                                 LBUG();
146                         }
147                 }
148         }
149
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);
164         else
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;
182
183         /* fillin fid */
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;
190 }
191
192 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
193 {
194         struct llu_inode_info *lli = llu_i2info(dst);
195         struct intnl_stat *st = llu_i2stat(dst);
196
197         valid &= src->o_valid;
198
199         if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
200                 CDEBUG(D_INODE,"valid "LPX64", cur time %lu/%lu, new %lu/%lu\n",
201                        src->o_valid,
202                        LTIME_S(st->st_mtime), LTIME_S(st->st_ctime),
203                        (long)src->o_mtime, (long)src->o_ctime);
204
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;
229 }
230
231 #define S_IRWXUGO       (S_IRWXU|S_IRWXG|S_IRWXO)
232 #define S_IALLUGO       (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
233
234 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
235 {
236         struct llu_inode_info *lli = llu_i2info(src);
237         struct intnl_stat *st = llu_i2stat(src);
238         obd_flag newvalid = 0;
239
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));
244
245         if (valid & OBD_MD_FLATIME) {
246                 dst->o_atime = LTIME_S(st->st_atime);
247                 newvalid |= OBD_MD_FLATIME;
248         }
249         if (valid & OBD_MD_FLMTIME) {
250                 dst->o_mtime = LTIME_S(st->st_mtime);
251                 newvalid |= OBD_MD_FLMTIME;
252         }
253         if (valid & OBD_MD_FLCTIME) {
254                 dst->o_ctime = LTIME_S(st->st_ctime);
255                 newvalid |= OBD_MD_FLCTIME;
256         }
257         if (valid & OBD_MD_FLSIZE) {
258                 dst->o_size = st->st_size;
259                 newvalid |= OBD_MD_FLSIZE;
260         }
261         if (valid & OBD_MD_FLBLOCKS) {  /* allocation of space (x512 bytes) */
262                 dst->o_blocks = st->st_blocks;
263                 newvalid |= OBD_MD_FLBLOCKS;
264         }
265         if (valid & OBD_MD_FLBLKSZ) {   /* optimal block size */
266                 dst->o_blksize = st->st_blksize;
267                 newvalid |= OBD_MD_FLBLKSZ;
268         }
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;
272         }
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;
276         }
277         if (valid & OBD_MD_FLUID) {
278                 dst->o_uid = st->st_uid;
279                 newvalid |= OBD_MD_FLUID;
280         }
281         if (valid & OBD_MD_FLGID) {
282                 dst->o_gid = st->st_gid;
283                 newvalid |= OBD_MD_FLGID;
284         }
285         if (valid & OBD_MD_FLFLAGS) {
286                 dst->o_flags = lli->lli_st_flags;
287                 newvalid |= OBD_MD_FLFLAGS;
288         }
289         if (valid & OBD_MD_FLGENER) {
290                 dst->o_generation = lli->lli_st_generation;
291                 newvalid |= OBD_MD_FLGENER;
292         }
293
294         dst->o_valid |= newvalid;
295 }
296
297 /*
298  * really does the getattr on the inode and updates its fields
299  */
300 int llu_inode_getattr(struct inode *inode, struct lov_stripe_md *lsm)
301 {
302         struct llu_inode_info *lli = llu_i2info(inode);
303         struct obd_export *exp = llu_i2obdexp(inode);
304         struct ptlrpc_request_set *set;
305         struct obdo oa;
306         obd_flag refresh_valid;
307         int rc;
308         ENTRY;
309
310         LASSERT(lsm);
311         LASSERT(lli);
312
313         memset(&oa, 0, sizeof oa);
314         oa.o_id = lsm->lsm_object_id;
315         oa.o_mode = S_IFREG;
316         oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
317                 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
318                 OBD_MD_FLCTIME;
319
320         set = ptlrpc_prep_set();
321         if (set == NULL) {
322                 CERROR ("ENOMEM allocing request set\n");
323                 rc = -ENOMEM;
324         } else {
325                 rc = obd_getattr_async(exp, &oa, lsm, set);
326                 if (rc == 0)
327                         rc = ptlrpc_set_wait(set);
328                 ptlrpc_set_destroy(set);
329         }
330         if (rc)
331                 RETURN(rc);
332
333         refresh_valid = OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
334                         OBD_MD_FLCTIME | OBD_MD_FLSIZE;
335
336         obdo_refresh_inode(inode, &oa, refresh_valid);
337
338         RETURN(0);
339 }
340
341 static struct inode* llu_new_inode(struct filesys *fs,
342                                    struct ll_fid *fid)
343 {
344         struct inode *inode;
345         struct llu_inode_info *lli;
346         struct intnl_stat st = {
347                 st_dev:         0,
348 #ifndef AUTOMOUNT_FILE_NAME
349                 st_mode:        fid->f_type & S_IFMT,
350 #else
351                 st_mode:        fid->f_type /* all of the bits! */
352 #endif
353                 st_uid:         geteuid(),
354                 st_gid:         getegid(),
355         };
356
357         OBD_ALLOC(lli, sizeof(*lli));
358         if (!lli)
359                 return NULL;
360
361         /* initialize lli here */
362         lli->lli_sbi = llu_fs2sbi(fs);
363         lli->lli_smd = NULL;
364         lli->lli_symlink_name = NULL;
365         lli->lli_flags = 0;
366         lli->lli_maxbytes = (__u64)(~0UL);
367         lli->lli_file_data = NULL;
368
369         lli->lli_sysio_fid.fid_data = &lli->lli_fid;
370         lli->lli_sysio_fid.fid_len = sizeof(lli->lli_fid);
371
372         memcpy(&lli->lli_fid, fid, sizeof(*fid));
373
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);
377
378         if (!inode)
379                 OBD_FREE(lli, sizeof(*lli));
380
381         return inode;
382 }
383
384 static int llu_have_md_lock(struct inode *inode)
385 {
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         int flags;
392         ENTRY;
393
394         LASSERT(inode);
395
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;
399
400         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
401
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);
407                 RETURN(1);
408         }
409
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);
413                 RETURN(1);
414         }
415         RETURN(0);
416 }
417
418 static int llu_inode_revalidate(struct inode *inode)
419 {
420         struct lov_stripe_md *lsm = NULL;
421         ENTRY;
422
423         if (!inode) {
424                 CERROR("REPORT THIS LINE TO PETER\n");
425                 RETURN(0);
426         }
427
428         if (!llu_have_md_lock(inode)) {
429                 struct lustre_md md;
430                 struct ptlrpc_request *req = NULL;
431                 struct llu_sb_info *sbi = llu_i2sbi(inode);
432                 struct ll_fid fid;
433                 unsigned long valid = OBD_MD_FLGETATTR;
434                 int rc, ealen = 0;
435
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;
441                 }
442                 ll_inode2fid(&fid, inode);
443                 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
444                 if (rc) {
445                         CERROR("failure %d inode %llu\n", rc,
446                                (long long)llu_i2stat(inode)->st_ino);
447                         RETURN(-abs(rc));
448                 }
449                 rc = mdc_req2lustre_md(req, 0, sbi->ll_osc_exp, &md);
450
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);
459                 }
460                 if (rc) {
461                         ptlrpc_req_finished(req);
462                         RETURN(rc);
463                 }
464
465
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);
469
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);
474         }
475
476         lsm = llu_i2info(inode)->lli_smd;
477         if (!lsm)       /* object not yet allocated, don't validate size */
478                 RETURN(0);
479
480         /* ll_glimpse_size will prefer locally cached writes if they extend
481          * the file */
482         RETURN(llu_glimpse_size(inode));
483 }
484
485 static void copy_stat_buf(struct inode *ino, struct intnl_stat *b)
486 {
487         *b = *llu_i2stat(ino);
488 }
489
490 static int llu_iop_getattr(struct pnode *pno,
491                            struct inode *ino,
492                            struct intnl_stat *b)
493 {
494         int rc;
495         ENTRY;
496
497         liblustre_wait_event(0);
498
499         if (!ino) {
500                 LASSERT(pno);
501                 LASSERT(pno->p_base->pb_ino);
502                 ino = pno->p_base->pb_ino;
503         } else {
504                 LASSERT(!pno || pno->p_base->pb_ino == ino);
505         }
506
507         /* libsysio might call us directly without intent lock,
508          * we must re-fetch the attrs here
509          */
510         rc = llu_inode_revalidate(ino);
511         if (!rc) {
512                 copy_stat_buf(ino, b);
513                 LASSERT(!llu_i2info(ino)->lli_it);
514         }
515
516         liblustre_wait_event(0);
517         RETURN(rc);
518 }
519
520 static int null_if_equal(struct ldlm_lock *lock, void *data)
521 {
522         if (data == lock->l_ast_data) {
523                 lock->l_ast_data = NULL;
524
525                 if (lock->l_req_mode != lock->l_granted_mode)
526                         LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
527         }
528
529         return LDLM_ITER_CONTINUE;
530 }
531
532 void llu_clear_inode(struct inode *inode)
533 {
534         struct ll_fid fid;
535         struct llu_inode_info *lli = llu_i2info(inode);
536         struct llu_sb_info *sbi = llu_i2sbi(inode);
537         ENTRY;
538
539         CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu/%lu(%p)\n",
540                (long long)llu_i2stat(inode)->st_ino, lli->lli_st_generation,
541                inode);
542
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);
546
547         if (lli->lli_smd)
548                 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
549                                   null_if_equal, inode);
550
551         if (lli->lli_smd) {
552                 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
553                 lli->lli_smd = NULL;
554         }
555
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;
560         }
561
562         EXIT;
563 }
564
565 void llu_iop_gone(struct inode *inode)
566 {
567         struct llu_inode_info *lli = llu_i2info(inode);
568         ENTRY;
569
570         liblustre_wait_event(0);
571         llu_clear_inode(inode);
572
573         OBD_FREE(lli, sizeof(*lli));
574         EXIT;
575 }
576
577 static int inode_setattr(struct inode * inode, struct iattr * attr)
578 {
579         unsigned int ia_valid = attr->ia_valid;
580         struct intnl_stat *st = llu_i2stat(inode);
581         int error = 0;
582
583         /*
584          * inode_setattr() is only ever invoked with ATTR_SIZE (by
585          * llu_setattr_raw()) when file has no bodies. Check this.
586          */
587         LASSERT(ergo(ia_valid & ATTR_SIZE, llu_i2info(inode)->lli_smd == NULL));
588
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;
605         }
606         /* mark_inode_dirty(inode); */
607         return error;
608 }
609
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.
617  *
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
621  * at the same time.
622  */
623 int llu_setattr_raw(struct inode *inode, struct iattr *attr)
624 {
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;
631         int rc = 0;
632         ENTRY;
633
634         CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu\n", (long long)st->st_ino);
635
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));
641                         RETURN(-EFBIG);
642                 }
643
644                 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
645         }
646
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;
651         }
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;
655         }
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;
659         }
660
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));
665         if (lsm)
666                 attr->ia_valid &= ~ATTR_SIZE;
667
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)) {
672                 struct lustre_md md;
673                 llu_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
674
675                 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
676                                   attr, NULL, 0, NULL, 0, &request);
677
678                 if (rc) {
679                         ptlrpc_req_finished(request);
680                         if (rc != -EPERM && rc != -EACCES)
681                                 CERROR("mdc_setattr fails: rc = %d\n", rc);
682                         RETURN(rc);
683                 }
684
685                 rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
686                 if (rc) {
687                         ptlrpc_req_finished(request);
688                         RETURN(rc);
689                 }
690
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
695                  * (bug 6196) */
696                 inode_setattr(inode, attr);
697                 llu_update_inode(inode, md.body, md.lsm);
698                 ptlrpc_req_finished(request);
699
700                 if (!lsm || !S_ISREG(st->st_mode)) {
701                         CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
702                         RETURN(0);
703                 }
704         } else {
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?
708                  */
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)
714                                         RETURN(rc);
715                         } else {
716                                 /* from inode_change_ok() */
717                                 if (current->fsuid != st->st_uid &&
718                                     !capable(CAP_FOWNER))
719                                         RETURN(-EPERM);
720                         }
721                 }
722
723                 /* Won't invoke llu_vmtruncate(), as we already cleared
724                  * ATTR_SIZE */
725                 inode_setattr(inode, attr);
726         }
727
728         if (ia_valid & ATTR_SIZE) {
729                 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
730                                                            OBD_OBJECT_EOF} };
731                 struct lustre_handle lockh = { 0, };
732                 struct lustre_handle match_lockh = { 0, };
733
734                 int err;
735                 int flags = LDLM_FL_TEST_LOCK; /* for assertion check below */
736                 int lock_mode;
737                 obd_flag obd_flags;
738
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);
742
743                 /* XXX when we fix the AST intents to pass the discard-range
744                  * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
745                  * XXX here. */
746                 flags = (attr->ia_size == 0) ? LDLM_AST_DISCARD_DATA : 0;
747
748                 if (sbi->ll_lco.lco_flags & OBD_CONNECT_TRUNCLOCK) {
749                         lock_mode = LCK_NL;
750                         obd_flags = OBD_FL_TRUNCLOCK;
751                         CDEBUG(D_INODE, "delegating locking to the OST");
752                 } else {
753                         lock_mode = LCK_PW;
754                         obd_flags = 0;
755                 }
756
757                 /* with lock_mode == LK_NL no lock is taken. */
758                 rc = llu_extent_lock(NULL, inode, lsm, lock_mode, &policy,
759                                      &lockh, flags);
760                 if (rc != ELDLM_OK) {
761                         if (rc > 0)
762                                 RETURN(-ENOLCK);
763                         RETURN(rc);
764                 }
765
766                 rc = llu_vmtruncate(inode, attr->ia_size, obd_flags);
767
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);
771                 if (err) {
772                         CERROR("llu_extent_unlock failed: %d\n", err);
773                         if (!rc)
774                                 rc = err;
775                 }
776         } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
777                 struct obdo oa;
778
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);
786                 if (rc)
787                         CERROR("obd_setattr fails: rc=%d\n", rc);
788         }
789         RETURN(rc);
790 }
791
792 /* here we simply act as a thin layer to glue it with
793  * llu_setattr_raw(), which is copy from kernel
794  */
795 static int llu_iop_setattr(struct pnode *pno,
796                            struct inode *ino,
797                            unsigned mask,
798                            struct intnl_stat *stbuf)
799 {
800         struct iattr iattr;
801         int rc;
802         ENTRY;
803
804         liblustre_wait_event(0);
805
806         LASSERT(!(mask & ~(SETATTR_MTIME | SETATTR_ATIME |
807                            SETATTR_UID | SETATTR_GID |
808                            SETATTR_LEN | SETATTR_MODE)));
809         memset(&iattr, 0, sizeof(iattr));
810
811         if (mask & SETATTR_MODE) {
812                 iattr.ia_mode = stbuf->st_mode;
813                 iattr.ia_valid |= ATTR_MODE;
814         }
815         if (mask & SETATTR_MTIME) {
816                 iattr.ia_mtime = stbuf->st_mtime;
817                 iattr.ia_valid |= ATTR_MTIME;
818         }
819         if (mask & SETATTR_ATIME) {
820                 iattr.ia_atime = stbuf->st_atime;
821                 iattr.ia_valid |= ATTR_ATIME;
822         }
823         if (mask & SETATTR_UID) {
824                 iattr.ia_uid = stbuf->st_uid;
825                 iattr.ia_valid |= ATTR_UID;
826         }
827         if (mask & SETATTR_GID) {
828                 iattr.ia_gid = stbuf->st_gid;
829                 iattr.ia_valid |= ATTR_GID;
830         }
831         if (mask & SETATTR_LEN) {
832                 iattr.ia_size = stbuf->st_size; /* XXX signed expansion problem */
833                 iattr.ia_valid |= ATTR_SIZE;
834         }
835
836         iattr.ia_valid |= ATTR_RAW | ATTR_CTIME;
837         iattr.ia_ctime = CURRENT_TIME;
838
839         rc = llu_setattr_raw(ino, &iattr);
840         liblustre_wait_event(0);
841         RETURN(rc);
842 }
843
844 #define EXT2_LINK_MAX           32000
845
846 static int llu_iop_symlink_raw(struct pnode *pno, const char *tgt)
847 {
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;
851         int len = qstr->len;
852         struct ptlrpc_request *request = NULL;
853         struct llu_sb_info *sbi = llu_i2sbi(dir);
854         struct mdc_op_data op_data;
855         int err = -EMLINK;
856         ENTRY;
857
858         liblustre_wait_event(0);
859         if (llu_i2stat(dir)->st_nlink >= EXT2_LINK_MAX)
860                 RETURN(err);
861
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,
866                          0, &request);
867         ptlrpc_req_finished(request);
868         liblustre_wait_event(0);
869         RETURN(err);
870 }
871
872 static int llu_readlink_internal(struct inode *inode,
873                                  struct ptlrpc_request **request,
874                                  char **symname)
875 {
876         struct llu_inode_info *lli = llu_i2info(inode);
877         struct llu_sb_info *sbi = llu_i2sbi(inode);
878         struct ll_fid fid;
879         struct mds_body *body;
880         struct intnl_stat *st = llu_i2stat(inode);
881         int rc, symlen = st->st_size + 1;
882         ENTRY;
883
884         *request = NULL;
885
886         if (lli->lli_symlink_name) {
887                 *symname = lli->lli_symlink_name;
888                 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
889                 RETURN(0);
890         }
891
892         ll_inode2fid(&fid, inode);
893         rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
894                          OBD_MD_LINKNAME, symlen, request);
895         if (rc) {
896                 CERROR("inode %llu: rc = %d\n", (long long)st->st_ino, rc);
897                 RETURN(rc);
898         }
899
900         body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
901         LASSERT (body != NULL);
902         LASSERT_REPSWABBED (*request, 0);
903
904         if ((body->valid & OBD_MD_LINKNAME) == 0) {
905                 CERROR ("OBD_MD_LINKNAME not set on reply\n");
906                 GOTO (failed, rc = -EPROTO);
907         }
908
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);
914         }
915
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);
923         }
924
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);
929
930         RETURN(0);
931
932  failed:
933         ptlrpc_req_finished (*request);
934         RETURN (-EPROTO);
935 }
936
937 static int llu_iop_readlink(struct pnode *pno, char *data, size_t bufsize)
938 {
939         struct inode *inode = pno->p_base->pb_ino;
940         struct ptlrpc_request *request;
941         char *symname;
942         int rc;
943         ENTRY;
944
945         liblustre_wait_event(0);
946         rc = llu_readlink_internal(inode, &request, &symname);
947         if (rc)
948                 GOTO(out, rc);
949
950         LASSERT(symname);
951         strncpy(data, symname, bufsize);
952         rc = strlen(symname);
953
954         ptlrpc_req_finished(request);
955  out:
956         liblustre_wait_event(0);
957         RETURN(rc);
958 }
959
960 static int llu_iop_mknod_raw(struct pnode *pno,
961                              mode_t mode,
962                              dev_t dev)
963 {
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;
968         int err = -EMLINK;
969         ENTRY;
970
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);
975
976         if (llu_i2stat(dir)->st_nlink >= EXT2_LINK_MAX)
977                 RETURN(err);
978
979         switch (mode & S_IFMT) {
980         case 0:
981         case S_IFREG:
982                 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
983         case S_IFCHR:
984         case S_IFBLK:
985         case S_IFIFO:
986         case S_IFSOCK:
987                 llu_prepare_mdc_op_data(&op_data, dir, NULL,
988                                         pno->p_base->pb_name.name,
989                                         pno->p_base->pb_name.len,
990                                         0);
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);
995                 break;
996         case S_IFDIR:
997                 err = -EPERM;
998                 break;
999         default:
1000                 err = -EINVAL;
1001         }
1002         liblustre_wait_event(0);
1003         RETURN(err);
1004 }
1005
1006 static int llu_iop_link_raw(struct pnode *old, struct pnode *new)
1007 {
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;
1014         int rc;
1015         ENTRY;
1016
1017         LASSERT(src);
1018         LASSERT(dir);
1019
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);
1025
1026         RETURN(rc);
1027 }
1028
1029 /*
1030  * libsysio will clear the inode immediately after return
1031  */
1032 static int llu_iop_unlink_raw(struct pnode *pno)
1033 {
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;
1041         int rc;
1042         ENTRY;
1043
1044         LASSERT(target);
1045
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);
1049         if (!rc)
1050                 rc = llu_objects_destroy(request, dir);
1051         ptlrpc_req_finished(request);
1052         liblustre_wait_event(0);
1053
1054         RETURN(rc);
1055 }
1056
1057 static int llu_iop_rename_raw(struct pnode *old, struct pnode *new)
1058 {
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;
1067         int rc;
1068         ENTRY;
1069
1070         LASSERT(src);
1071         LASSERT(tgt);
1072
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,
1077                         &request);
1078         if (!rc) {
1079                 rc = llu_objects_destroy(request, src);
1080         }
1081
1082         ptlrpc_req_finished(request);
1083         liblustre_wait_event(0);
1084
1085         RETURN(rc);
1086 }
1087
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)
1092 {
1093         struct obd_statfs obd_osfs;
1094         int rc;
1095         ENTRY;
1096
1097         rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1098         if (rc) {
1099                 CERROR("mdc_statfs fails: rc = %d\n", rc);
1100                 RETURN(rc);
1101         }
1102
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);
1105
1106         rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1107         if (rc) {
1108                 CERROR("obd_statfs fails: rc = %d\n", rc);
1109                 RETURN(rc);
1110         }
1111
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,
1114                obd_osfs.os_files);
1115
1116         osfs->os_blocks = obd_osfs.os_blocks;
1117         osfs->os_bfree = obd_osfs.os_bfree;
1118         osfs->os_bavail = obd_osfs.os_bavail;
1119
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.
1123          */
1124         if (obd_osfs.os_ffree < osfs->os_ffree) {
1125                 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1126                         obd_osfs.os_ffree;
1127                 osfs->os_ffree = obd_osfs.os_ffree;
1128         }
1129
1130         RETURN(rc);
1131 }
1132
1133 static int llu_statfs(struct llu_sb_info *sbi, struct statfs *sfs)
1134 {
1135         struct obd_statfs osfs;
1136         int rc;
1137
1138         CDEBUG(D_VFSTRACE, "VFS Op:\n");
1139
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);
1144         if (rc)
1145                 return rc;
1146
1147         statfs_unpack(sfs, &osfs);
1148
1149         if (sizeof(sfs->f_blocks) == 4) {
1150                 while (osfs.os_blocks > ~0UL) {
1151                         sfs->f_bsize <<= 1;
1152
1153                         osfs.os_blocks >>= 1;
1154                         osfs.os_bfree >>= 1;
1155                         osfs.os_bavail >>= 1;
1156                 }
1157         }
1158
1159         sfs->f_blocks = osfs.os_blocks;
1160         sfs->f_bfree = osfs.os_bfree;
1161         sfs->f_bavail = osfs.os_bavail;
1162
1163         return 0;
1164 }
1165
1166 static int llu_iop_statvfs(struct pnode *pno,
1167                            struct inode *ino,
1168                            struct intnl_statvfs *buf)
1169 {
1170         struct statfs fs;
1171         int rc;
1172         ENTRY;
1173
1174         liblustre_wait_event(0);
1175
1176 #ifndef __CYGWIN__
1177         LASSERT(pno->p_base->pb_ino);
1178         rc = llu_statfs(llu_i2sbi(pno->p_base->pb_ino), &fs);
1179         if (rc)
1180                 RETURN(rc);
1181
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;
1194 #endif
1195
1196         liblustre_wait_event(0);
1197         RETURN(0);
1198 }
1199 #endif /* _HAVE_STATVFS */
1200
1201 static int llu_iop_mkdir_raw(struct pnode *pno, mode_t mode)
1202 {
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;
1210         int err = -EMLINK;
1211         ENTRY;
1212
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);
1216
1217         if (st->st_nlink >= EXT2_LINK_MAX)
1218                 RETURN(err);
1219
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,
1223                          0, &request);
1224         ptlrpc_req_finished(request);
1225         liblustre_wait_event(0);
1226         RETURN(err);
1227 }
1228
1229 static int llu_iop_rmdir_raw(struct pnode *pno)
1230 {
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;
1237         int rc;
1238         ENTRY;
1239
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);
1244
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);
1248
1249         liblustre_wait_event(0);
1250         RETURN(rc);
1251 }
1252
1253 #ifdef O_DIRECT
1254 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC|O_DIRECT)
1255 #else
1256 #define FCNTL_FLMASK (O_APPEND|O_NONBLOCK|O_ASYNC)
1257 #endif
1258 #define FCNTL_FLMASK_INVALID (O_NONBLOCK|O_ASYNC)
1259
1260 /* refer to ll_file_flock() for details */
1261 static int llu_file_flock(struct inode *ino,
1262                           int cmd,
1263                           struct file_lock *file_lock)
1264 {
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;
1274         int flags = 0;
1275         int rc;
1276
1277         CDEBUG(D_VFSTRACE, "VFS Op:inode="LPU64" file_lock=%p\n",
1278                st->st_ino, file_lock);
1279
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;
1283
1284         switch (file_lock->fl_type) {
1285         case F_RDLCK:
1286                 mode = LCK_PR;
1287                 break;
1288         case F_UNLCK:
1289                 mode = LCK_NL;
1290                 break;
1291         case F_WRLCK:
1292                 mode = LCK_PW;
1293                 break;
1294         default:
1295                 CERROR("unknown fcntl lock type: %d\n", file_lock->fl_type);
1296                 LBUG();
1297         }
1298
1299         switch (cmd) {
1300         case F_SETLKW:
1301 #ifdef F_SETLKW64
1302 #if F_SETLKW64 != F_SETLKW
1303         case F_SETLKW64:
1304 #endif
1305 #endif
1306                 flags = 0;
1307                 break;
1308         case F_SETLK:
1309 #ifdef F_SETLK64
1310 #if F_SETLK64 != F_SETLK
1311         case F_SETLK64:
1312 #endif
1313 #endif
1314                 flags = LDLM_FL_BLOCK_NOWAIT;
1315                 break;
1316         case F_GETLK:
1317 #ifdef F_GETLK64
1318 #if F_GETLK64 != F_GETLK
1319         case F_GETLK64:
1320 #endif
1321 #endif
1322                 flags = LDLM_FL_TEST_LOCK;
1323                 file_lock->fl_type = mode;
1324                 break;
1325         default:
1326                 CERROR("unknown fcntl cmd: %d\n", cmd);
1327                 LBUG();
1328         }
1329
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);
1333
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);
1339         RETURN(rc);
1340 }
1341
1342 static int assign_type(struct file_lock *fl, int type)
1343 {
1344         switch (type) {
1345         case F_RDLCK:
1346         case F_WRLCK:
1347         case F_UNLCK:
1348                 fl->fl_type = type;
1349                 return 0;
1350         default:
1351                 return -EINVAL;
1352         }
1353 }
1354
1355 static int flock_to_posix_lock(struct inode *ino,
1356                                struct file_lock *fl,
1357                                struct flock *l)
1358 {
1359         switch (l->l_whence) {
1360         /* XXX: only SEEK_SET is supported in lustre */
1361         case SEEK_SET:
1362                 fl->fl_start = 0;
1363                 break;
1364         default:
1365                 return -EINVAL;
1366         }
1367
1368         fl->fl_end = l->l_len - 1;
1369         if (l->l_len < 0)
1370                 return -EINVAL;
1371         if (l->l_len == 0)
1372                 fl->fl_end = OFFSET_MAX;
1373
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.
1381          */
1382         fl->fl_owner = NULL;
1383         fl->fl_file = NULL;
1384
1385         return assign_type(fl, l->l_type);
1386 }
1387
1388 static int llu_fcntl_getlk(struct inode *ino, struct flock *flock)
1389 {
1390         struct file_lock fl;
1391         int error;
1392
1393         error = EINVAL;
1394         if ((flock->l_type != F_RDLCK) && (flock->l_type != F_WRLCK))
1395                 goto out;
1396
1397         error = flock_to_posix_lock(ino, &fl, flock);
1398         if (error)
1399                 goto out;
1400
1401         error = llu_file_flock(ino, F_GETLK, &fl);
1402         if (error)
1403                 goto out;
1404
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;
1413         }
1414
1415 out:
1416         return error;
1417 }
1418
1419 static int llu_fcntl_setlk(struct inode *ino, int cmd, struct flock *flock)
1420 {
1421         struct file_lock fl;
1422         int flags = llu_i2info(ino)->lli_open_flags + 1;
1423         int error;
1424
1425         error = flock_to_posix_lock(ino, &fl, flock);
1426         if (error)
1427                 goto out;
1428         if (cmd == F_SETLKW)
1429                 fl.fl_flags |= FL_SLEEP;
1430
1431         error = -EBADF;
1432         switch (flock->l_type) {
1433         case F_RDLCK:
1434                 if (!(flags & FMODE_READ))
1435                         goto out;
1436                 break;
1437         case F_WRLCK:
1438                 if (!(flags & FMODE_WRITE))
1439                         goto out;
1440                 break;
1441         case F_UNLCK:
1442                 break;
1443         default:
1444                 error = -EINVAL;
1445                 goto out;
1446         }
1447
1448         error = llu_file_flock(ino, cmd, &fl);
1449         if (error)
1450                 goto out;
1451
1452 out:
1453         return error;
1454 }
1455
1456 static int llu_iop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn)
1457 {
1458         struct llu_inode_info *lli = llu_i2info(ino);
1459         long flags;
1460         struct flock *flock;
1461         long err = 0;
1462
1463         liblustre_wait_event(0);
1464         switch (cmd) {
1465         case F_GETFL:
1466                 *rtn = lli->lli_open_flags;
1467                 break;
1468         case F_SETFL:
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");
1474                         *rtn = -EINVAL;
1475                         err = EINVAL;
1476                         break;
1477                 }
1478                 lli->lli_open_flags = (int)(flags & FCNTL_FLMASK) |
1479                                       (lli->lli_open_flags & ~FCNTL_FLMASK);
1480                 *rtn = 0;
1481                 break;
1482         case F_GETLK:
1483 #ifdef F_GETLK64
1484 #if F_GETLK64 != F_GETLK
1485         case F_GETLK64:
1486 #endif
1487 #endif
1488                 flock = va_arg(ap, struct flock *);
1489                 err = llu_fcntl_getlk(ino, flock);
1490                 *rtn = err? -1: 0;
1491                 break;
1492         case F_SETLK:
1493 #ifdef F_SETLKW64
1494 #if F_SETLKW64 != F_SETLKW
1495         case F_SETLKW64:
1496 #endif
1497 #endif
1498         case F_SETLKW:
1499 #ifdef F_SETLK64
1500 #if F_SETLK64 != F_SETLK
1501         case F_SETLK64:
1502 #endif
1503 #endif
1504                 flock = va_arg(ap, struct flock *);
1505                 err = llu_fcntl_setlk(ino, cmd, flock);
1506                 *rtn = err? -1: 0;
1507                 break;
1508         default:
1509                 CERROR("unsupported fcntl cmd %x\n", cmd);
1510                 *rtn = -ENOSYS;
1511                 err = ENOSYS;
1512                 break;
1513         }
1514
1515         liblustre_wait_event(0);
1516         return err;
1517 }
1518
1519 static int llu_get_grouplock(struct inode *inode, unsigned long arg)
1520 {
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;
1527         ldlm_error_t err;
1528         int flags = 0;
1529         ENTRY;
1530
1531         if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
1532                 RETURN(-EINVAL);
1533         }
1534
1535         policy.l_extent.gid = arg;
1536         if (lli->lli_open_flags & O_NONBLOCK)
1537                 flags = LDLM_FL_BLOCK_NOWAIT;
1538
1539         err = llu_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh,
1540                               flags);
1541         if (err)
1542                 RETURN(err);
1543
1544         fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
1545         fd->fd_gid = arg;
1546         memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
1547
1548         RETURN(0);
1549 }
1550
1551 static int llu_put_grouplock(struct inode *inode, unsigned long arg)
1552 {
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;
1556         ldlm_error_t err;
1557         ENTRY;
1558
1559         if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED))
1560                 RETURN(-EINVAL);
1561
1562         if (fd->fd_gid != arg)
1563                 RETURN(-EINVAL);
1564
1565         fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
1566
1567         err = llu_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
1568         if (err)
1569                 RETURN(err);
1570
1571         fd->fd_gid = 0;
1572         memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
1573
1574         RETURN(0);
1575 }
1576
1577 static int llu_iop_ioctl(struct inode *ino, unsigned long int request,
1578                          va_list ap)
1579 {
1580         unsigned long arg;
1581         int rc;
1582
1583         liblustre_wait_event(0);
1584
1585         switch (request) {
1586         case LL_IOC_GROUP_LOCK:
1587                 arg = va_arg(ap, unsigned long);
1588                 rc = llu_get_grouplock(ino, arg);
1589                 break;
1590         case LL_IOC_GROUP_UNLOCK:
1591                 arg = va_arg(ap, unsigned long);
1592                 rc = llu_put_grouplock(ino, arg);
1593                 break;
1594         default:
1595                 CERROR("did not support ioctl cmd %lx\n", request);
1596                 rc = -ENOSYS;
1597                 break;
1598         }
1599
1600         liblustre_wait_event(0);
1601         return rc;
1602 }
1603
1604 /*
1605  * we already do syncronous read/write
1606  */
1607 static int llu_iop_sync(struct inode *inode)
1608 {
1609         liblustre_wait_event(0);
1610         return 0;
1611 }
1612
1613 static int llu_iop_datasync(struct inode *inode)
1614 {
1615         liblustre_wait_event(0);
1616         return 0;
1617 }
1618
1619 struct filesys_ops llu_filesys_ops =
1620 {
1621         fsop_gone: llu_fsop_gone,
1622 };
1623
1624 struct inode *llu_iget(struct filesys *fs, struct lustre_md *md)
1625 {
1626         struct inode *inode;
1627         struct ll_fid fid;
1628         struct file_identifier fileid = {&fid, sizeof(fid)};
1629
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);
1634                 LBUG();
1635                 return ERR_PTR(-EPERM);
1636         }
1637
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;
1642
1643         inode = _sysio_i_find(fs, &fileid);
1644         if (inode) {
1645                 struct llu_inode_info *lli = llu_i2info(inode);
1646
1647                 if (inode->i_zombie ||
1648                     lli->lli_st_generation != md->body->generation) {
1649                         I_RELE(inode);
1650                 }
1651                 else {
1652                         llu_update_inode(inode, md->body, md->lsm);
1653                         return inode;
1654                 }
1655         }
1656
1657         inode = llu_new_inode(fs, &fid);
1658         if (inode)
1659                 llu_update_inode(inode, md->body, md->lsm);
1660
1661         return inode;
1662 }
1663
1664 extern struct list_head lustre_profile_list;
1665
1666 static int
1667 llu_fsswop_mount(const char *source,
1668                  unsigned flags,
1669                  const void *data __IS_UNUSED,
1670                  struct pnode *tocover,
1671                  struct mount **mntp)
1672 {
1673         struct filesys *fs;
1674         struct inode *root;
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;
1685         class_uuid_t uuid;
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,};
1693
1694         ENTRY;
1695
1696         if (ll_parse_mount_target(source,
1697                                   &zconf_mdsnid,
1698                                   &zconf_mdsname,
1699                                   &zconf_profile)) {
1700                 CERROR("mal-formed target %s\n", source);
1701                 RETURN(err);
1702         }
1703         if (!zconf_mdsnid || !zconf_mdsname || !zconf_profile) {
1704                 printf("Liblustre: invalid target %s\n", source);
1705                 RETURN(err);
1706         }
1707         /* allocate & initialize sbi */
1708         OBD_ALLOC(sbi, sizeof(*sbi));
1709         if (!sbi)
1710                 RETURN(-ENOMEM);
1711
1712         INIT_LIST_HEAD(&sbi->ll_conn_chain);
1713         generate_random_uuid(uuid);
1714         class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
1715
1716         /* generate a string unique to this super, let's try
1717          the address of the super itself.*/
1718         sprintf(ll_instance, "%p", sbi);
1719
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,
1724                                     zconf_profile, 1);
1725         if (err < 0) {
1726                 CERROR("Unable to process log: %s\n", zconf_profile);
1727                 GOTO(out_free, err);
1728         }
1729
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);
1734         }
1735         OBD_ALLOC(osc, strlen(lprof->lp_osc) + strlen(ll_instance) + 2);
1736         sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
1737
1738         OBD_ALLOC(mdc, strlen(lprof->lp_mdc) + strlen(ll_instance) + 2);
1739         sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
1740
1741         if (!osc) {
1742                 CERROR("no osc\n");
1743                 GOTO(out_free, err = -EINVAL);
1744         }
1745         if (!mdc) {
1746                 CERROR("no mdc\n");
1747                 GOTO(out_free, err = -EINVAL);
1748         }
1749
1750         fs = _sysio_fs_new(&llu_filesys_ops, flags, sbi);
1751         if (!fs) {
1752                 err = -ENOMEM;
1753                 goto out_free;
1754         }
1755
1756         obd = class_name2obd(mdc);
1757         if (!obd) {
1758                 CERROR("MDC %s: not setup or attached\n", mdc);
1759                 GOTO(out_free, err = -EINVAL);
1760         }
1761         obd_set_info(obd->obd_self_export, strlen("async"), "async",
1762                      sizeof(async), &async);
1763
1764         ocd.ocd_connect_flags = OBD_CONNECT_VERSION;
1765         ocd.ocd_version = LUSTRE_VERSION_CODE;
1766
1767         /* setup mdc */
1768         err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, &ocd);
1769         if (err) {
1770                 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
1771                 GOTO(out_free, err);
1772         }
1773         sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
1774
1775         err = obd_statfs(obd, &osfs, 100000000);
1776         if (err)
1777                 GOTO(out_mdc, err);
1778
1779         /*
1780          * FIXME fill fs stat data into sbi here!!! FIXME
1781          */
1782
1783         /* setup osc */
1784         obd = class_name2obd(osc);
1785         if (!obd) {
1786                 CERROR("OSC %s: not setup or attached\n", osc);
1787                 GOTO(out_mdc, err = -EINVAL);
1788         }
1789         obd_set_info(obd->obd_self_export, strlen("async"), "async",
1790                      sizeof(async), &async);
1791
1792         obd->obd_upcall.onu_owner = &sbi->ll_lco;
1793         obd->obd_upcall.onu_upcall = ll_ocd_update;
1794
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);
1799         if (err) {
1800                 CERROR("cannot connect to %s: rc = %d\n", osc, err);
1801                 GOTO(out_mdc, err);
1802         }
1803         sbi->ll_osc_exp = class_conn2export(&osc_conn);
1804         sbi->ll_lco.lco_flags = ocd.ocd_connect_flags;
1805
1806         mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
1807
1808         err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
1809         if (err) {
1810                 CERROR("cannot mds_connect: rc = %d\n", err);
1811                 GOTO(out_osc, err);
1812         }
1813         CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
1814         sbi->ll_rootino = rootfid.id;
1815
1816         /* fetch attr of root inode */
1817         err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
1818                           OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS, 0, &request);
1819         if (err) {
1820                 CERROR("mdc_getattr failed for root: rc = %d\n", err);
1821                 GOTO(out_osc, err);
1822         }
1823
1824         err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
1825         if (err) {
1826                 CERROR("failed to understand root inode md: rc = %d\n",err);
1827                 GOTO(out_request, err);
1828         }
1829
1830         LASSERT(sbi->ll_rootino != 0);
1831
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);
1836         }
1837
1838         /*
1839          * Generate base path-node for root.
1840          */
1841         rootpb = _sysio_pb_new(&noname, NULL, root);
1842         if (!rootpb) {
1843                 err = -ENOMEM;
1844                 goto out_inode;
1845         }
1846
1847         err = _sysio_do_mount(fs, rootpb, flags, tocover, mntp);
1848         if (err) {
1849                 _sysio_pb_gone(rootpb);
1850                 goto out_inode;
1851         }
1852
1853         ptlrpc_req_finished(request);
1854
1855         CDEBUG(D_SUPER, "LibLustre: %s mounted successfully!\n", source);
1856         liblustre_wait_event(0);
1857
1858         return 0;
1859
1860 out_inode:
1861         _sysio_i_gone(root);
1862 out_request:
1863         ptlrpc_req_finished(request);
1864 out_osc:
1865         obd_disconnect(sbi->ll_osc_exp);
1866 out_mdc:
1867         obd_disconnect(sbi->ll_mdc_exp);
1868 out_free:
1869         if (osc)
1870                 OBD_FREE(osc, strlen(osc) + 1);
1871         if (mdc)
1872                 OBD_FREE(mdc, strlen(mdc) + 1);
1873         OBD_FREE(sbi, sizeof(*sbi));
1874         return err;
1875 }
1876
1877 struct fssw_ops llu_fssw_ops = {
1878         llu_fsswop_mount
1879 };
1880
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,
1906 #endif
1907         inop_gone:      llu_iop_gone,
1908 };