linux-bk/fs/xfs/linux-2.6/xfs_super.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
   3 *
   4 * This program is free software; you can redistribute it and/or modify it
   5 * under the terms of version 2 of the GNU General Public License as
   6 * published by the Free Software Foundation.
   7 *
   8 * This program is distributed in the hope that it would be useful, but
   9 * WITHOUT ANY WARRANTY; without even the implied warranty of
  10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11 *
  12 * Further, this software is distributed without any warranty that it is
  13 * free of the rightful claim of any third person regarding infringement
  14 * or the like.  Any license provided herein, whether implied or
  15 * otherwise, applies only to this software file.  Patent licenses, if
  16 * any, provided herein do not apply to combinations of this program with
  17 * other software, or any other product whatsoever.
  18 *
  19 * You should have received a copy of the GNU General Public License along
  20 * with this program; if not, write the Free Software Foundation, Inc., 59
  21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22 *
  23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24 * Mountain View, CA  94043, or:
  25 *
  26 * http://www.sgi.com
  27 *
  28 * For further information regarding this notice, see:
  29 *
  30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31 */
  32
  33#include "xfs.h"
  34
  35#include "xfs_inum.h"
  36#include "xfs_log.h"
  37#include "xfs_clnt.h"
  38#include "xfs_trans.h"
  39#include "xfs_sb.h"
  40#include "xfs_dir.h"
  41#include "xfs_dir2.h"
  42#include "xfs_alloc.h"
  43#include "xfs_dmapi.h"
  44#include "xfs_quota.h"
  45#include "xfs_mount.h"
  46#include "xfs_alloc_btree.h"
  47#include "xfs_bmap_btree.h"
  48#include "xfs_ialloc_btree.h"
  49#include "xfs_btree.h"
  50#include "xfs_ialloc.h"
  51#include "xfs_attr_sf.h"
  52#include "xfs_dir_sf.h"
  53#include "xfs_dir2_sf.h"
  54#include "xfs_dinode.h"
  55#include "xfs_inode.h"
  56#include "xfs_bmap.h"
  57#include "xfs_bit.h"
  58#include "xfs_rtalloc.h"
  59#include "xfs_error.h"
  60#include "xfs_itable.h"
  61#include "xfs_rw.h"
  62#include "xfs_acl.h"
  63#include "xfs_cap.h"
  64#include "xfs_mac.h"
  65#include "xfs_attr.h"
  66#include "xfs_buf_item.h"
  67#include "xfs_utils.h"
  68#include "xfs_version.h"
  69#include "xfs_ioctl32.h"
  70
  71#include <linux/namei.h>
  72#include <linux/init.h>
  73#include <linux/mount.h>
  74#include <linux/writeback.h>
  75
  76STATIC struct quotactl_ops linvfs_qops;
  77STATIC struct super_operations linvfs_sops;
  78STATIC kmem_zone_t *linvfs_inode_zone;
  79STATIC kmem_shaker_t xfs_inode_shaker;
  80
  81STATIC struct xfs_mount_args *
  82xfs_args_allocate(
  83        struct super_block      *sb)
  84{
  85        struct xfs_mount_args   *args;
  86
  87        args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP);
  88        args->logbufs = args->logbufsize = -1;
  89        strncpy(args->fsname, sb->s_id, MAXNAMELEN);
  90
  91        /* Copy the already-parsed mount(2) flags we're interested in */
  92        if (sb->s_flags & MS_NOATIME)
  93                args->flags |= XFSMNT_NOATIME;
  94
  95        /* Default to 32 bit inodes on Linux all the time */
  96        args->flags |= XFSMNT_32BITINODES;
  97
  98        return args;
  99}
 100
 101__uint64_t
 102xfs_max_file_offset(
 103        unsigned int            blockshift)
 104{
 105        unsigned int            pagefactor = 1;
 106        unsigned int            bitshift = BITS_PER_LONG - 1;
 107
 108        /* Figure out maximum filesize, on Linux this can depend on
 109         * the filesystem blocksize (on 32 bit platforms).
 110         * __block_prepare_write does this in an [unsigned] long...
 111         *      page->index << (PAGE_CACHE_SHIFT - bbits)
 112         * So, for page sized blocks (4K on 32 bit platforms),
 113         * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
 114         *      (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
 115         * but for smaller blocksizes it is less (bbits = log2 bsize).
 116         * Note1: get_block_t takes a long (implicit cast from above)
 117         * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
 118         * can optionally convert the [unsigned] long from above into
 119         * an [unsigned] long long.
 120         */
 121
 122#if BITS_PER_LONG == 32
 123# if defined(CONFIG_LBD)
 124        ASSERT(sizeof(sector_t) == 8);
 125        pagefactor = PAGE_CACHE_SIZE;
 126        bitshift = BITS_PER_LONG;
 127# else
 128        pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
 129# endif
 130#endif
 131
 132        return (((__uint64_t)pagefactor) << bitshift) - 1;
 133}
 134
 135STATIC __inline__ void
 136xfs_set_inodeops(
 137        struct inode            *inode)
 138{
 139        vnode_t                 *vp = LINVFS_GET_VP(inode);
 140
 141        if (vp->v_type == VNON) {
 142                vn_mark_bad(vp);
 143        } else if (S_ISREG(inode->i_mode)) {
 144                inode->i_op = &linvfs_file_inode_operations;
 145                inode->i_fop = &linvfs_file_operations;
 146                inode->i_mapping->a_ops = &linvfs_aops;
 147        } else if (S_ISDIR(inode->i_mode)) {
 148                inode->i_op = &linvfs_dir_inode_operations;
 149                inode->i_fop = &linvfs_dir_operations;
 150        } else if (S_ISLNK(inode->i_mode)) {
 151                inode->i_op = &linvfs_symlink_inode_operations;
 152                if (inode->i_blocks)
 153                        inode->i_mapping->a_ops = &linvfs_aops;
 154        } else {
 155                inode->i_op = &linvfs_file_inode_operations;
 156                init_special_inode(inode, inode->i_mode, inode->i_rdev);
 157        }
 158}
 159
 160STATIC __inline__ void
 161xfs_revalidate_inode(
 162        xfs_mount_t             *mp,
 163        vnode_t                 *vp,
 164        xfs_inode_t             *ip)
 165{
 166        struct inode            *inode = LINVFS_GET_IP(vp);
 167
 168        inode->i_mode   = (ip->i_d.di_mode & MODEMASK) | VTTOIF(vp->v_type);
 169        inode->i_nlink  = ip->i_d.di_nlink;
 170        inode->i_uid    = ip->i_d.di_uid;
 171        inode->i_gid    = ip->i_d.di_gid;
 172        if (((1 << vp->v_type) & ((1<<VBLK) | (1<<VCHR))) == 0) {
 173                inode->i_rdev = 0;
 174        } else {
 175                xfs_dev_t dev = ip->i_df.if_u2.if_rdev;
 176                inode->i_rdev = MKDEV(sysv_major(dev) & 0x1ff, sysv_minor(dev));
 177        }
 178        inode->i_blksize = PAGE_CACHE_SIZE;
 179        inode->i_generation = ip->i_d.di_gen;
 180        i_size_write(inode, ip->i_d.di_size);
 181        inode->i_blocks =
 182                XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
 183        inode->i_atime.tv_sec   = ip->i_d.di_atime.t_sec;
 184        inode->i_atime.tv_nsec  = ip->i_d.di_atime.t_nsec;
 185        inode->i_mtime.tv_sec   = ip->i_d.di_mtime.t_sec;
 186        inode->i_mtime.tv_nsec  = ip->i_d.di_mtime.t_nsec;
 187        inode->i_ctime.tv_sec   = ip->i_d.di_ctime.t_sec;
 188        inode->i_ctime.tv_nsec  = ip->i_d.di_ctime.t_nsec;
 189        if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
 190                inode->i_flags |= S_IMMUTABLE;
 191        else
 192                inode->i_flags &= ~S_IMMUTABLE;
 193        if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
 194                inode->i_flags |= S_APPEND;
 195        else
 196                inode->i_flags &= ~S_APPEND;
 197        if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
 198                inode->i_flags |= S_SYNC;
 199        else
 200                inode->i_flags &= ~S_SYNC;
 201        if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
 202                inode->i_flags |= S_NOATIME;
 203        else
 204                inode->i_flags &= ~S_NOATIME;
 205        vp->v_flag &= ~VMODIFIED;
 206}
 207
 208void
 209xfs_initialize_vnode(
 210        bhv_desc_t              *bdp,
 211        vnode_t                 *vp,
 212        bhv_desc_t              *inode_bhv,
 213        int                     unlock)
 214{
 215        xfs_inode_t             *ip = XFS_BHVTOI(inode_bhv);
 216        struct inode            *inode = LINVFS_GET_IP(vp);
 217
 218        if (!inode_bhv->bd_vobj) {
 219                vp->v_vfsp = bhvtovfs(bdp);
 220                bhv_desc_init(inode_bhv, ip, vp, &xfs_vnodeops);
 221                bhv_insert(VN_BHV_HEAD(vp), inode_bhv);
 222        }
 223
 224        /*
 225         * We need to set the ops vectors, and unlock the inode, but if
 226         * we have been called during the new inode create process, it is
 227         * too early to fill in the Linux inode.  We will get called a
 228         * second time once the inode is properly set up, and then we can
 229         * finish our work.
 230         */
 231        if (ip->i_d.di_mode != 0 && unlock && (inode->i_state & I_NEW)) {
 232                vp->v_type = IFTOVT(ip->i_d.di_mode);
 233                xfs_revalidate_inode(XFS_BHVTOM(bdp), vp, ip);
 234                xfs_set_inodeops(inode);
 235        
 236                ip->i_flags &= ~XFS_INEW;
 237                barrier();
 238
 239                unlock_new_inode(inode);
 240        }
 241}
 242
 243int
 244xfs_blkdev_get(
 245        xfs_mount_t             *mp,
 246        const char              *name,
 247        struct block_device     **bdevp)
 248{
 249        int                     error = 0;
 250
 251        *bdevp = open_bdev_excl(name, 0, mp);
 252        if (IS_ERR(*bdevp)) {
 253                error = PTR_ERR(*bdevp);
 254                printk("XFS: Invalid device [%s], error=%d\n", name, error);
 255        }
 256
 257        return -error;
 258}
 259
 260void
 261xfs_blkdev_put(
 262        struct block_device     *bdev)
 263{
 264        if (bdev)
 265                close_bdev_excl(bdev);
 266}
 267
 268
 269STATIC struct inode *
 270linvfs_alloc_inode(
 271        struct super_block      *sb)
 272{
 273        vnode_t                 *vp;
 274
 275        vp = (vnode_t *)kmem_cache_alloc(linvfs_inode_zone, 
 276                kmem_flags_convert(KM_SLEEP));
 277        if (!vp)
 278                return NULL;
 279        return LINVFS_GET_IP(vp);
 280}
 281
 282STATIC void
 283linvfs_destroy_inode(
 284        struct inode            *inode)
 285{
 286        kmem_cache_free(linvfs_inode_zone, LINVFS_GET_VP(inode));
 287}
 288
 289STATIC int
 290xfs_inode_shake(
 291        int             priority,
 292        unsigned int    gfp_mask)
 293{
 294        int             pages;
 295
 296        pages = kmem_zone_shrink(linvfs_inode_zone);
 297        pages += kmem_zone_shrink(xfs_inode_zone);
 298        return pages;
 299}
 300
 301STATIC void
 302init_once(
 303        void                    *data,
 304        kmem_cache_t            *cachep,
 305        unsigned long           flags)
 306{
 307        vnode_t                 *vp = (vnode_t *)data;
 308
 309        if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
 310            SLAB_CTOR_CONSTRUCTOR)
 311                inode_init_once(LINVFS_GET_IP(vp));
 312}
 313
 314STATIC int
 315init_inodecache( void )
 316{
 317        linvfs_inode_zone = kmem_cache_create("linvfs_icache",
 318                                sizeof(vnode_t), 0, SLAB_RECLAIM_ACCOUNT,
 319                                init_once, NULL);
 320        if (linvfs_inode_zone == NULL)
 321                return -ENOMEM;
 322        return 0;
 323}
 324
 325STATIC void
 326destroy_inodecache( void )
 327{
 328        if (kmem_cache_destroy(linvfs_inode_zone))
 329                printk(KERN_WARNING "%s: cache still in use!\n", __FUNCTION__);
 330}
 331
 332/*
 333 * Attempt to flush the inode, this will actually fail
 334 * if the inode is pinned, but we dirty the inode again
 335 * at the point when it is unpinned after a log write,
 336 * since this is when the inode itself becomes flushable. 
 337 */
 338STATIC int
 339linvfs_write_inode(
 340        struct inode            *inode,
 341        int                     sync)
 342{
 343        vnode_t                 *vp = LINVFS_GET_VP(inode);
 344        int                     error = 0, flags = FLUSH_INODE;
 345
 346        if (vp) {
 347                vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
 348                if (sync)
 349                        flags |= FLUSH_SYNC;
 350                VOP_IFLUSH(vp, flags, error);
 351                if (error == EAGAIN) {
 352                        if (sync)
 353                                VOP_IFLUSH(vp, flags | FLUSH_LOG, error);
 354                        else
 355                                error = 0;
 356                }
 357        }
 358
 359        return -error;
 360}
 361
 362STATIC void
 363linvfs_clear_inode(
 364        struct inode            *inode)
 365{
 366        vnode_t                 *vp = LINVFS_GET_VP(inode);
 367
 368        if (vp) {
 369                vn_rele(vp);
 370                vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
 371                /*
 372                 * Do all our cleanup, and remove this vnode.
 373                 */
 374                vn_remove(vp);
 375        }
 376}
 377
 378
 379/*
 380 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
 381 * Doing this has two advantages:
 382 * - It saves on stack space, which is tight in certain situations
 383 * - It can be used (with care) as a mechanism to avoid deadlocks.
 384 * Flushing while allocating in a full filesystem requires both.
 385 */
 386STATIC void
 387xfs_syncd_queue_work(
 388        struct vfs      *vfs,
 389        void            *data,
 390        void            (*syncer)(vfs_t *, void *))
 391{
 392        vfs_sync_work_t *work;
 393
 394        work = kmem_alloc(sizeof(struct vfs_sync_work), KM_SLEEP);
 395        INIT_LIST_HEAD(&work->w_list);
 396        work->w_syncer = syncer;
 397        work->w_data = data;
 398        work->w_vfs = vfs;
 399        spin_lock(&vfs->vfs_sync_lock);
 400        list_add_tail(&work->w_list, &vfs->vfs_sync_list);
 401        spin_unlock(&vfs->vfs_sync_lock);
 402        wake_up_process(vfs->vfs_sync_task);
 403}
 404
 405/*
 406 * Flush delayed allocate data, attempting to free up reserved space
 407 * from existing allocations.  At this point a new allocation attempt
 408 * has failed with ENOSPC and we are in the process of scratching our
 409 * heads, looking about for more room...
 410 */
 411STATIC void
 412xfs_flush_inode_work(
 413        vfs_t           *vfs,
 414        void            *inode)
 415{
 416        filemap_flush(((struct inode *)inode)->i_mapping);
 417        iput((struct inode *)inode);
 418}
 419
 420void
 421xfs_flush_inode(
 422        xfs_inode_t     *ip)
 423{
 424        struct inode    *inode = LINVFS_GET_IP(XFS_ITOV(ip));
 425        struct vfs      *vfs = XFS_MTOVFS(ip->i_mount);
 426
 427        igrab(inode);
 428        xfs_syncd_queue_work(vfs, inode, xfs_flush_inode_work);
 429        delay(HZ/2);
 430}
 431
 432/*
 433 * This is the "bigger hammer" version of xfs_flush_inode_work...
 434 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
 435 */
 436STATIC void
 437xfs_flush_device_work(
 438        vfs_t           *vfs,
 439        void            *inode)
 440{
 441        sync_blockdev(vfs->vfs_super->s_bdev);
 442        iput((struct inode *)inode);
 443}
 444
 445void
 446xfs_flush_device(
 447        xfs_inode_t     *ip)
 448{
 449        struct inode    *inode = LINVFS_GET_IP(XFS_ITOV(ip));
 450        struct vfs      *vfs = XFS_MTOVFS(ip->i_mount);
 451
 452        igrab(inode);
 453        xfs_syncd_queue_work(vfs, inode, xfs_flush_device_work);
 454        delay(HZ/2);
 455        xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
 456}
 457
 458#define SYNCD_FLAGS     (SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR)
 459STATIC void
 460vfs_sync_worker(
 461        vfs_t           *vfsp,
 462        void            *unused)
 463{
 464        int             error;
 465
 466        if (!(vfsp->vfs_flag & VFS_RDONLY))
 467                VFS_SYNC(vfsp, SYNCD_FLAGS, NULL, error);
 468        vfsp->vfs_sync_seq++;
 469        wmb();
 470        wake_up(&vfsp->vfs_wait_single_sync_task);
 471}
 472
 473STATIC int
 474xfssyncd(
 475        void                    *arg)
 476{
 477        long                    timeleft;
 478        vfs_t                   *vfsp = (vfs_t *) arg;
 479        struct list_head        tmp;
 480        struct vfs_sync_work    *work, *n;
 481
 482        daemonize("xfssyncd");
 483
 484        vfsp->vfs_sync_work.w_vfs = vfsp;
 485        vfsp->vfs_sync_work.w_syncer = vfs_sync_worker;
 486        vfsp->vfs_sync_task = current;
 487        wmb();
 488        wake_up(&vfsp->vfs_wait_sync_task);
 489
 490        INIT_LIST_HEAD(&tmp);
 491        timeleft = (xfs_syncd_centisecs * HZ) / 100;
 492        for (;;) {
 493                set_current_state(TASK_INTERRUPTIBLE);
 494                timeleft = schedule_timeout(timeleft);
 495                /* swsusp */
 496                try_to_freeze(PF_FREEZE);
 497                if (vfsp->vfs_flag & VFS_UMOUNT)
 498                        break;
 499
 500                spin_lock(&vfsp->vfs_sync_lock);
 501                /*
 502                 * We can get woken by laptop mode, to do a sync -
 503                 * that's the (only!) case where the list would be
 504                 * empty with time remaining.
 505                 */
 506                if (!timeleft || list_empty(&vfsp->vfs_sync_list)) {
 507                        if (!timeleft)
 508                                timeleft = (xfs_syncd_centisecs * HZ) / 100;
 509                        INIT_LIST_HEAD(&vfsp->vfs_sync_work.w_list);
 510                        list_add_tail(&vfsp->vfs_sync_work.w_list,
 511                                        &vfsp->vfs_sync_list);
 512                }
 513                list_for_each_entry_safe(work, n, &vfsp->vfs_sync_list, w_list)
 514                        list_move(&work->w_list, &tmp);
 515                spin_unlock(&vfsp->vfs_sync_lock);
 516
 517                list_for_each_entry_safe(work, n, &tmp, w_list) {
 518                        (*work->w_syncer)(vfsp, work->w_data);
 519                        list_del(&work->w_list);
 520                        if (work == &vfsp->vfs_sync_work)
 521                                continue;
 522                        kmem_free(work, sizeof(struct vfs_sync_work));
 523                }
 524        }
 525
 526        vfsp->vfs_sync_task = NULL;
 527        wmb();
 528        wake_up(&vfsp->vfs_wait_sync_task);
 529
 530        return 0;
 531}
 532
 533STATIC int
 534linvfs_start_syncd(
 535        vfs_t                   *vfsp)
 536{
 537        int                     pid;
 538
 539        pid = kernel_thread(xfssyncd, (void *) vfsp,
 540                        CLONE_VM | CLONE_FS | CLONE_FILES);
 541        if (pid < 0)
 542                return -pid;
 543        wait_event(vfsp->vfs_wait_sync_task, vfsp->vfs_sync_task);
 544        return 0;
 545}
 546
 547STATIC void
 548linvfs_stop_syncd(
 549        vfs_t                   *vfsp)
 550{
 551        vfsp->vfs_flag |= VFS_UMOUNT;
 552        wmb();
 553
 554        wake_up_process(vfsp->vfs_sync_task);
 555        wait_event(vfsp->vfs_wait_sync_task, !vfsp->vfs_sync_task);
 556}
 557
 558STATIC void
 559linvfs_put_super(
 560        struct super_block      *sb)
 561{
 562        vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
 563        int                     error;
 564
 565        linvfs_stop_syncd(vfsp);
 566        VFS_SYNC(vfsp, SYNC_ATTR|SYNC_DELWRI, NULL, error);
 567        if (!error)
 568                VFS_UNMOUNT(vfsp, 0, NULL, error);
 569        if (error) {
 570                printk("XFS unmount got error %d\n", error);
 571                printk("%s: vfsp/0x%p left dangling!\n", __FUNCTION__, vfsp);
 572                return;
 573        }
 574
 575        vfs_deallocate(vfsp);
 576}
 577
 578STATIC void
 579linvfs_write_super(
 580        struct super_block      *sb)
 581{
 582        vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
 583        int                     error;
 584
 585        if (sb->s_flags & MS_RDONLY) {
 586                sb->s_dirt = 0; /* paranoia */
 587                return;
 588        }
 589        /* Push the log and superblock a little */
 590        VFS_SYNC(vfsp, SYNC_FSDATA, NULL, error);
 591        sb->s_dirt = 0;
 592}
 593
 594STATIC int
 595linvfs_sync_super(
 596        struct super_block      *sb,
 597        int                     wait)
 598{
 599        vfs_t           *vfsp = LINVFS_GET_VFS(sb);
 600        int             error;
 601        int             flags = SYNC_FSDATA;
 602
 603        if (wait)
 604                flags |= SYNC_WAIT;
 605
 606        VFS_SYNC(vfsp, flags, NULL, error);
 607        sb->s_dirt = 0;
 608
 609        if (unlikely(laptop_mode)) {
 610                int     prev_sync_seq = vfsp->vfs_sync_seq;
 611
 612                /*
 613                 * The disk must be active because we're syncing.
 614                 * We schedule xfssyncd now (now that the disk is
 615                 * active) instead of later (when it might not be).
 616                 */
 617                wake_up_process(vfsp->vfs_sync_task);
 618                /*
 619                 * We have to wait for the sync iteration to complete.
 620                 * If we don't, the disk activity caused by the sync
 621                 * will come after the sync is completed, and that
 622                 * triggers another sync from laptop mode.
 623                 */
 624                wait_event(vfsp->vfs_wait_single_sync_task,
 625                                vfsp->vfs_sync_seq != prev_sync_seq);
 626        }
 627
 628        return -error;
 629}
 630
 631STATIC int
 632linvfs_statfs(
 633        struct super_block      *sb,
 634        struct kstatfs          *statp)
 635{
 636        vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
 637        int                     error;
 638
 639        VFS_STATVFS(vfsp, statp, NULL, error);
 640        return -error;
 641}
 642
 643STATIC int
 644linvfs_remount(
 645        struct super_block      *sb,
 646        int                     *flags,
 647        char                    *options)
 648{
 649        vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
 650        struct xfs_mount_args   *args = xfs_args_allocate(sb);
 651        int                     error;
 652
 653        VFS_PARSEARGS(vfsp, options, args, 1, error);
 654        if (!error)
 655                VFS_MNTUPDATE(vfsp, flags, args, error);
 656        kmem_free(args, sizeof(*args));
 657        return -error;
 658}
 659
 660STATIC void
 661linvfs_freeze_fs(
 662        struct super_block      *sb)
 663{
 664        VFS_FREEZE(LINVFS_GET_VFS(sb));
 665}
 666
 667STATIC int
 668linvfs_show_options(
 669        struct seq_file         *m,
 670        struct vfsmount         *mnt)
 671{
 672        struct vfs              *vfsp = LINVFS_GET_VFS(mnt->mnt_sb);
 673        int                     error;
 674
 675        VFS_SHOWARGS(vfsp, m, error);
 676        return error;
 677}
 678
 679STATIC int
 680linvfs_getxstate(
 681        struct super_block      *sb,
 682        struct fs_quota_stat    *fqs)
 683{
 684        struct vfs              *vfsp = LINVFS_GET_VFS(sb);
 685        int                     error;
 686
 687        VFS_QUOTACTL(vfsp, Q_XGETQSTAT, 0, (caddr_t)fqs, error);
 688        return -error;
 689}
 690
 691STATIC int
 692linvfs_setxstate(
 693        struct super_block      *sb,
 694        unsigned int            flags,
 695        int                     op)
 696{
 697        struct vfs              *vfsp = LINVFS_GET_VFS(sb);
 698        int                     error;
 699
 700        VFS_QUOTACTL(vfsp, op, 0, (caddr_t)&flags, error);
 701        return -error;
 702}
 703
 704STATIC int
 705linvfs_getxquota(
 706        struct super_block      *sb,
 707        int                     type,
 708        qid_t                   id,
 709        struct fs_disk_quota    *fdq)
 710{
 711        struct vfs              *vfsp = LINVFS_GET_VFS(sb);
 712        int                     error, getmode;
 713
 714        getmode = (type == GRPQUOTA) ? Q_XGETGQUOTA : Q_XGETQUOTA;
 715        VFS_QUOTACTL(vfsp, getmode, id, (caddr_t)fdq, error);
 716        return -error;
 717}
 718
 719STATIC int
 720linvfs_setxquota(
 721        struct super_block      *sb,
 722        int                     type,
 723        qid_t                   id,
 724        struct fs_disk_quota    *fdq)
 725{
 726        struct vfs              *vfsp = LINVFS_GET_VFS(sb);
 727        int                     error, setmode;
 728
 729        setmode = (type == GRPQUOTA) ? Q_XSETGQLIM : Q_XSETQLIM;
 730        VFS_QUOTACTL(vfsp, setmode, id, (caddr_t)fdq, error);
 731        return -error;
 732}
 733
 734STATIC int
 735linvfs_fill_super(
 736        struct super_block      *sb,
 737        void                    *data,
 738        int                     silent)
 739{
 740        vnode_t                 *rootvp;
 741        struct vfs              *vfsp = vfs_allocate();
 742        struct xfs_mount_args   *args = xfs_args_allocate(sb);
 743        struct kstatfs          statvfs;
 744        int                     error, error2;
 745
 746        vfsp->vfs_super = sb;
 747        LINVFS_SET_VFS(sb, vfsp);
 748        if (sb->s_flags & MS_RDONLY)
 749                vfsp->vfs_flag |= VFS_RDONLY;
 750        bhv_insert_all_vfsops(vfsp);
 751
 752        VFS_PARSEARGS(vfsp, (char *)data, args, 0, error);
 753        if (error) {
 754                bhv_remove_all_vfsops(vfsp, 1);
 755                goto fail_vfsop;
 756        }
 757
 758        sb_min_blocksize(sb, BBSIZE);
 759#ifdef CONFIG_XFS_EXPORT
 760        sb->s_export_op = &linvfs_export_ops;
 761#endif
 762        sb->s_qcop = &linvfs_qops;
 763        sb->s_op = &linvfs_sops;
 764
 765        VFS_MOUNT(vfsp, args, NULL, error);
 766        if (error) {
 767                bhv_remove_all_vfsops(vfsp, 1);
 768                goto fail_vfsop;
 769        }
 770
 771        VFS_STATVFS(vfsp, &statvfs, NULL, error);
 772        if (error)
 773                goto fail_unmount;
 774
 775        sb->s_dirt = 1;
 776        sb->s_magic = statvfs.f_type;
 777        sb->s_blocksize = statvfs.f_bsize;
 778        sb->s_blocksize_bits = ffs(statvfs.f_bsize) - 1;
 779        sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
 780        sb->s_time_gran = 1;
 781        set_posix_acl_flag(sb);
 782
 783        VFS_ROOT(vfsp, &rootvp, error);
 784        if (error)
 785                goto fail_unmount;
 786
 787        sb->s_root = d_alloc_root(LINVFS_GET_IP(rootvp));
 788        if (!sb->s_root) {
 789                error = ENOMEM;
 790                goto fail_vnrele;
 791        }
 792        if (is_bad_inode(sb->s_root->d_inode)) {
 793                error = EINVAL;
 794                goto fail_vnrele;
 795        }
 796        if ((error = linvfs_start_syncd(vfsp)))
 797                goto fail_vnrele;
 798        vn_trace_exit(rootvp, __FUNCTION__, (inst_t *)__return_address);
 799
 800        kmem_free(args, sizeof(*args));
 801        return 0;
 802
 803fail_vnrele:
 804        if (sb->s_root) {
 805                dput(sb->s_root);
 806                sb->s_root = NULL;
 807        } else {
 808                VN_RELE(rootvp);
 809        }
 810
 811fail_unmount:
 812        VFS_UNMOUNT(vfsp, 0, NULL, error2);
 813
 814fail_vfsop:
 815        vfs_deallocate(vfsp);
 816        kmem_free(args, sizeof(*args));
 817        return -error;
 818}
 819
 820STATIC struct super_block *
 821linvfs_get_sb(
 822        struct file_system_type *fs_type,
 823        int                     flags,
 824        const char              *dev_name,
 825        void                    *data)
 826{
 827        return get_sb_bdev(fs_type, flags, dev_name, data, linvfs_fill_super);
 828}
 829
 830STATIC struct super_operations linvfs_sops = {
 831        .alloc_inode            = linvfs_alloc_inode,
 832        .destroy_inode          = linvfs_destroy_inode,
 833        .write_inode            = linvfs_write_inode,
 834        .clear_inode            = linvfs_clear_inode,
 835        .put_super              = linvfs_put_super,
 836        .write_super            = linvfs_write_super,
 837        .sync_fs                = linvfs_sync_super,
 838        .write_super_lockfs     = linvfs_freeze_fs,
 839        .statfs                 = linvfs_statfs,
 840        .remount_fs             = linvfs_remount,
 841        .show_options           = linvfs_show_options,
 842};
 843
 844STATIC struct quotactl_ops linvfs_qops = {
 845        .get_xstate             = linvfs_getxstate,
 846        .set_xstate             = linvfs_setxstate,
 847        .get_xquota             = linvfs_getxquota,
 848        .set_xquota             = linvfs_setxquota,
 849};
 850
 851STATIC struct file_system_type xfs_fs_type = {
 852        .owner                  = THIS_MODULE,
 853        .name                   = "xfs",
 854        .get_sb                 = linvfs_get_sb,
 855        .kill_sb                = kill_block_super,
 856        .fs_flags               = FS_REQUIRES_DEV,
 857};
 858
 859
 860STATIC int __init
 861init_xfs_fs( void )
 862{
 863        int                     error;
 864        struct sysinfo          si;
 865        static char             message[] __initdata = KERN_INFO \
 866                XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
 867
 868        printk(message);
 869
 870        si_meminfo(&si);
 871        xfs_physmem = si.totalram;
 872
 873        ktrace_init(64);
 874
 875        error = init_inodecache();
 876        if (error < 0)
 877                goto undo_inodecache;
 878
 879        error = pagebuf_init();
 880        if (error < 0)
 881                goto undo_pagebuf;
 882
 883        vn_init();
 884        xfs_init();
 885        uuid_init();
 886        vfs_initquota();
 887
 888        xfs_inode_shaker = kmem_shake_register(xfs_inode_shake);
 889        if (!xfs_inode_shaker) {
 890                error = -ENOMEM;
 891                goto undo_shaker;
 892        }
 893
 894        error = register_filesystem(&xfs_fs_type);
 895        if (error)
 896                goto undo_register;
 897        XFS_DM_INIT(&xfs_fs_type);
 898        return 0;
 899
 900undo_register:
 901        kmem_shake_deregister(xfs_inode_shaker);
 902
 903undo_shaker:
 904        pagebuf_terminate();
 905
 906undo_pagebuf:
 907        destroy_inodecache();
 908
 909undo_inodecache:
 910        return error;
 911}
 912
 913STATIC void __exit
 914exit_xfs_fs( void )
 915{
 916        vfs_exitquota();
 917        XFS_DM_EXIT(&xfs_fs_type);
 918        unregister_filesystem(&xfs_fs_type);
 919        kmem_shake_deregister(xfs_inode_shaker);
 920        xfs_cleanup();
 921        pagebuf_terminate();
 922        destroy_inodecache();
 923        ktrace_uninit();
 924}
 925
 926module_init(init_xfs_fs);
 927module_exit(exit_xfs_fs);
 928
 929MODULE_AUTHOR("Silicon Graphics, Inc.");
 930MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
 931MODULE_LICENSE("GPL");
 932
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.