linux/fs/xfs/xfs_iops.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
   3 * All Rights Reserved.
   4 *
   5 * This program is free software; you can redistribute it and/or
   6 * modify it under the terms of the GNU General Public License as
   7 * published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope that it would be useful,
  10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12 * GNU General Public License for more details.
  13 *
  14 * You should have received a copy of the GNU General Public License
  15 * along with this program; if not, write the Free Software Foundation,
  16 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17 */
  18#include "xfs.h"
  19#include "xfs_fs.h"
  20#include "xfs_shared.h"
  21#include "xfs_format.h"
  22#include "xfs_log_format.h"
  23#include "xfs_trans_resv.h"
  24#include "xfs_mount.h"
  25#include "xfs_da_format.h"
  26#include "xfs_inode.h"
  27#include "xfs_bmap.h"
  28#include "xfs_bmap_util.h"
  29#include "xfs_acl.h"
  30#include "xfs_quota.h"
  31#include "xfs_error.h"
  32#include "xfs_attr.h"
  33#include "xfs_trans.h"
  34#include "xfs_trace.h"
  35#include "xfs_icache.h"
  36#include "xfs_symlink.h"
  37#include "xfs_da_btree.h"
  38#include "xfs_dir2.h"
  39#include "xfs_pnfs.h"
  40#include "xfs_iomap.h"
  41#include "xfs_trans_space.h"
  42
  43#include <linux/capability.h>
  44#include <linux/xattr.h>
  45#include <linux/namei.h>
  46#include <linux/posix_acl.h>
  47#include <linux/security.h>
  48#include <linux/iomap.h>
  49#include <linux/slab.h>
  50
  51/*
  52 * Directories have different lock order w.r.t. mmap_sem compared to regular
  53 * files. This is due to readdir potentially triggering page faults on a user
  54 * buffer inside filldir(), and this happens with the ilock on the directory
  55 * held. For regular files, the lock order is the other way around - the
  56 * mmap_sem is taken during the page fault, and then we lock the ilock to do
  57 * block mapping. Hence we need a different class for the directory ilock so
  58 * that lockdep can tell them apart.
  59 */
  60static struct lock_class_key xfs_nondir_ilock_class;
  61static struct lock_class_key xfs_dir_ilock_class;
  62
  63static int
  64xfs_initxattrs(
  65        struct inode            *inode,
  66        const struct xattr      *xattr_array,
  67        void                    *fs_info)
  68{
  69        const struct xattr      *xattr;
  70        struct xfs_inode        *ip = XFS_I(inode);
  71        int                     error = 0;
  72
  73        for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  74                error = xfs_attr_set(ip, xattr->name, xattr->value,
  75                                      xattr->value_len, ATTR_SECURE);
  76                if (error < 0)
  77                        break;
  78        }
  79        return error;
  80}
  81
  82/*
  83 * Hook in SELinux.  This is not quite correct yet, what we really need
  84 * here (as we do for default ACLs) is a mechanism by which creation of
  85 * these attrs can be journalled at inode creation time (along with the
  86 * inode, of course, such that log replay can't cause these to be lost).
  87 */
  88
  89STATIC int
  90xfs_init_security(
  91        struct inode    *inode,
  92        struct inode    *dir,
  93        const struct qstr *qstr)
  94{
  95        return security_inode_init_security(inode, dir, qstr,
  96                                             &xfs_initxattrs, NULL);
  97}
  98
  99static void
 100xfs_dentry_to_name(
 101        struct xfs_name *namep,
 102        struct dentry   *dentry)
 103{
 104        namep->name = dentry->d_name.name;
 105        namep->len = dentry->d_name.len;
 106        namep->type = XFS_DIR3_FT_UNKNOWN;
 107}
 108
 109static int
 110xfs_dentry_mode_to_name(
 111        struct xfs_name *namep,
 112        struct dentry   *dentry,
 113        int             mode)
 114{
 115        namep->name = dentry->d_name.name;
 116        namep->len = dentry->d_name.len;
 117        namep->type = xfs_mode_to_ftype(mode);
 118
 119        if (unlikely(namep->type == XFS_DIR3_FT_UNKNOWN))
 120                return -EFSCORRUPTED;
 121
 122        return 0;
 123}
 124
 125STATIC void
 126xfs_cleanup_inode(
 127        struct inode    *dir,
 128        struct inode    *inode,
 129        struct dentry   *dentry)
 130{
 131        struct xfs_name teardown;
 132
 133        /* Oh, the horror.
 134         * If we can't add the ACL or we fail in
 135         * xfs_init_security we must back out.
 136         * ENOSPC can hit here, among other things.
 137         */
 138        xfs_dentry_to_name(&teardown, dentry);
 139
 140        xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
 141}
 142
 143STATIC int
 144xfs_generic_create(
 145        struct inode    *dir,
 146        struct dentry   *dentry,
 147        umode_t         mode,
 148        dev_t           rdev,
 149        bool            tmpfile)        /* unnamed file */
 150{
 151        struct inode    *inode;
 152        struct xfs_inode *ip = NULL;
 153        struct posix_acl *default_acl = NULL;
 154        struct xfs_name name;
 155        int             error;
 156
 157        /*
 158         * Irix uses Missed'em'V split, but doesn't want to see
 159         * the upper 5 bits of (14bit) major.
 160         */
 161        if (S_ISCHR(mode) || S_ISBLK(mode)) {
 162                if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
 163                        return -EINVAL;
 164        } else {
 165                rdev = 0;
 166        }
 167
 168        if (IS_POSIXACL(dir)) {
 169                default_acl = xfs_get_acl(dir, ACL_TYPE_DEFAULT);
 170                if (IS_ERR(default_acl))
 171                        return PTR_ERR(default_acl);
 172
 173                if (!default_acl)
 174                        mode &= ~current_umask();
 175        }
 176
 177        /* Verify mode is valid also for tmpfile case */
 178        error = xfs_dentry_mode_to_name(&name, dentry, mode);
 179        if (unlikely(error))
 180                goto out_free_acl;
 181
 182        if (!tmpfile) {
 183                error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip);
 184        } else {
 185                error = xfs_create_tmpfile(XFS_I(dir), dentry, mode, &ip);
 186        }
 187        if (unlikely(error))
 188                goto out_free_acl;
 189
 190        inode = VFS_I(ip);
 191
 192        error = xfs_init_security(inode, dir, &dentry->d_name);
 193        if (unlikely(error))
 194                goto out_cleanup_inode;
 195
 196        if (default_acl) {
 197                error = xfs_inherit_acl(inode, default_acl);
 198                default_acl = NULL;
 199                if (unlikely(error))
 200                        goto out_cleanup_inode;
 201        }
 202
 203        xfs_setup_iops(ip);
 204
 205        if (tmpfile) {
 206                /*
 207                 * The VFS requires that any inode fed to d_tmpfile must have
 208                 * nlink == 1 so that it can decrement the nlink in d_tmpfile.
 209                 * However, we created the temp file with nlink == 0 because
 210                 * we're not allowed to put an inode with nlink > 0 on the
 211                 * unlinked list.  Therefore we have to set nlink to 1 so that
 212                 * d_tmpfile can immediately set it back to zero.
 213                 */
 214                set_nlink(inode, 1);
 215                d_tmpfile(dentry, inode);
 216        } else
 217                d_instantiate(dentry, inode);
 218        xfs_finish_inode_setup(ip);
 219        return error;
 220
 221 out_cleanup_inode:
 222        xfs_finish_inode_setup(ip);
 223        if (!tmpfile)
 224                xfs_cleanup_inode(dir, inode, dentry);
 225        iput(inode);
 226 out_free_acl:
 227        posix_acl_release(default_acl);
 228        return error;
 229}
 230
 231STATIC int
 232xfs_vn_mknod(
 233        struct inode    *dir,
 234        struct dentry   *dentry,
 235        umode_t         mode,
 236        dev_t           rdev)
 237{
 238        return xfs_generic_create(dir, dentry, mode, rdev, false);
 239}
 240
 241STATIC int
 242xfs_vn_create(
 243        struct inode    *dir,
 244        struct dentry   *dentry,
 245        umode_t         mode,
 246        bool            flags)
 247{
 248        return xfs_vn_mknod(dir, dentry, mode, 0);
 249}
 250
 251STATIC int
 252xfs_vn_mkdir(
 253        struct inode    *dir,
 254        struct dentry   *dentry,
 255        umode_t         mode)
 256{
 257        return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
 258}
 259
 260STATIC struct dentry *
 261xfs_vn_lookup(
 262        struct inode    *dir,
 263        struct dentry   *dentry,
 264        unsigned int flags)
 265{
 266        struct xfs_inode *cip;
 267        struct xfs_name name;
 268        int             error;
 269
 270        if (dentry->d_name.len >= MAXNAMELEN)
 271                return ERR_PTR(-ENAMETOOLONG);
 272
 273        xfs_dentry_to_name(&name, dentry);
 274        error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
 275        if (unlikely(error)) {
 276                if (unlikely(error != -ENOENT))
 277                        return ERR_PTR(error);
 278                d_add(dentry, NULL);
 279                return NULL;
 280        }
 281
 282        return d_splice_alias(VFS_I(cip), dentry);
 283}
 284
 285STATIC struct dentry *
 286xfs_vn_ci_lookup(
 287        struct inode    *dir,
 288        struct dentry   *dentry,
 289        unsigned int flags)
 290{
 291        struct xfs_inode *ip;
 292        struct xfs_name xname;
 293        struct xfs_name ci_name;
 294        struct qstr     dname;
 295        int             error;
 296
 297        if (dentry->d_name.len >= MAXNAMELEN)
 298                return ERR_PTR(-ENAMETOOLONG);
 299
 300        xfs_dentry_to_name(&xname, dentry);
 301        error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
 302        if (unlikely(error)) {
 303                if (unlikely(error != -ENOENT))
 304                        return ERR_PTR(error);
 305                /*
 306                 * call d_add(dentry, NULL) here when d_drop_negative_children
 307                 * is called in xfs_vn_mknod (ie. allow negative dentries
 308                 * with CI filesystems).
 309                 */
 310                return NULL;
 311        }
 312
 313        /* if exact match, just splice and exit */
 314        if (!ci_name.name)
 315                return d_splice_alias(VFS_I(ip), dentry);
 316
 317        /* else case-insensitive match... */
 318        dname.name = ci_name.name;
 319        dname.len = ci_name.len;
 320        dentry = d_add_ci(dentry, VFS_I(ip), &dname);
 321        kmem_free(ci_name.name);
 322        return dentry;
 323}
 324
 325STATIC int
 326xfs_vn_link(
 327        struct dentry   *old_dentry,
 328        struct inode    *dir,
 329        struct dentry   *dentry)
 330{
 331        struct inode    *inode = old_dentry->d_inode;
 332        struct xfs_name name;
 333        int             error;
 334
 335        error = xfs_dentry_mode_to_name(&name, dentry, inode->i_mode);
 336        if (unlikely(error))
 337                return error;
 338
 339        error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
 340        if (unlikely(error))
 341                return error;
 342
 343        ihold(inode);
 344        d_instantiate(dentry, inode);
 345        return 0;
 346}
 347
 348STATIC int
 349xfs_vn_unlink(
 350        struct inode    *dir,
 351        struct dentry   *dentry)
 352{
 353        struct xfs_name name;
 354        int             error;
 355
 356        xfs_dentry_to_name(&name, dentry);
 357
 358        error = xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
 359        if (error)
 360                return error;
 361
 362        /*
 363         * With unlink, the VFS makes the dentry "negative": no inode,
 364         * but still hashed. This is incompatible with case-insensitive
 365         * mode, so invalidate (unhash) the dentry in CI-mode.
 366         */
 367        if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
 368                d_invalidate(dentry);
 369        return 0;
 370}
 371
 372STATIC int
 373xfs_vn_symlink(
 374        struct inode    *dir,
 375        struct dentry   *dentry,
 376        const char      *symname)
 377{
 378        struct inode    *inode;
 379        struct xfs_inode *cip = NULL;
 380        struct xfs_name name;
 381        int             error;
 382        umode_t         mode;
 383
 384        mode = S_IFLNK |
 385                (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO);
 386        error = xfs_dentry_mode_to_name(&name, dentry, mode);
 387        if (unlikely(error))
 388                goto out;
 389
 390        error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip);
 391        if (unlikely(error))
 392                goto out;
 393
 394        inode = VFS_I(cip);
 395
 396        error = xfs_init_security(inode, dir, &dentry->d_name);
 397        if (unlikely(error))
 398                goto out_cleanup_inode;
 399
 400        xfs_setup_iops(cip);
 401
 402        d_instantiate(dentry, inode);
 403        xfs_finish_inode_setup(cip);
 404        return 0;
 405
 406 out_cleanup_inode:
 407        xfs_finish_inode_setup(cip);
 408        xfs_cleanup_inode(dir, inode, dentry);
 409        iput(inode);
 410 out:
 411        return error;
 412}
 413
 414STATIC int
 415xfs_vn_rename(
 416        struct inode    *odir,
 417        struct dentry   *odentry,
 418        struct inode    *ndir,
 419        struct dentry   *ndentry,
 420        unsigned int    flags)
 421{
 422        struct inode    *new_inode = ndentry->d_inode;
 423        int             omode = 0;
 424        int             error;
 425        struct xfs_name oname;
 426        struct xfs_name nname;
 427
 428        if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
 429                return -EINVAL;
 430
 431        /* if we are exchanging files, we need to set i_mode of both files */
 432        if (flags & RENAME_EXCHANGE)
 433                omode = ndentry->d_inode->i_mode;
 434
 435        error = xfs_dentry_mode_to_name(&oname, odentry, omode);
 436        if (omode && unlikely(error))
 437                return error;
 438
 439        error = xfs_dentry_mode_to_name(&nname, ndentry,
 440                                        d_inode(odentry)->i_mode);
 441        if (unlikely(error))
 442                return error;
 443
 444        return xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
 445                          XFS_I(ndir), &nname,
 446                          new_inode ? XFS_I(new_inode) : NULL, flags);
 447}
 448
 449STATIC int
 450xfs_vn_rename_old(
 451        struct inode    *odir,
 452        struct dentry   *odentry,
 453        struct inode    *ndir,
 454        struct dentry   *ndentry)
 455{
 456        return xfs_vn_rename(odir, odentry, ndir, ndentry, 0);
 457}
 458
 459
 460/*
 461 * careful here - this function can get called recursively, so
 462 * we need to be very careful about how much stack we use.
 463 * uio is kmalloced for this reason...
 464 */
 465STATIC void *
 466xfs_vn_follow_link(
 467        struct dentry           *dentry,
 468        struct nameidata        *nd)
 469{
 470        char                    *link;
 471        int                     error = -ENOMEM;
 472
 473        link = kmalloc(XFS_SYMLINK_MAXLEN+1, GFP_KERNEL);
 474        if (!link)
 475                goto out_err;
 476
 477        error = xfs_readlink(XFS_I(dentry->d_inode), link);
 478        if (unlikely(error))
 479                goto out_kfree;
 480
 481        nd_set_link(nd, link);
 482        return NULL;
 483
 484 out_kfree:
 485        kfree(link);
 486 out_err:
 487        nd_set_link(nd, ERR_PTR(error));
 488        return NULL;
 489}
 490
 491STATIC void
 492xfs_vn_put_link(
 493        struct dentry   *dentry,
 494        struct nameidata *nd,
 495        void            *p)
 496{
 497        char            *s = nd_get_link(nd);
 498
 499        if (!IS_ERR(s))
 500                kfree(s);
 501}
 502
 503STATIC int
 504xfs_vn_getattr(
 505        struct vfsmount         *mnt,
 506        struct dentry           *dentry,
 507        struct kstat            *stat)
 508{
 509        struct inode            *inode = dentry->d_inode;
 510        struct xfs_inode        *ip = XFS_I(inode);
 511        struct xfs_mount        *mp = ip->i_mount;
 512
 513        trace_xfs_getattr(ip);
 514
 515        if (XFS_FORCED_SHUTDOWN(mp))
 516                return -EIO;
 517
 518        stat->size = XFS_ISIZE(ip);
 519        stat->dev = inode->i_sb->s_dev;
 520        stat->mode = inode->i_mode;
 521        stat->nlink = inode->i_nlink;
 522        stat->uid = inode->i_uid;
 523        stat->gid = inode->i_gid;
 524        stat->ino = ip->i_ino;
 525        stat->atime = inode->i_atime;
 526        stat->mtime = inode->i_mtime;
 527        stat->ctime = inode->i_ctime;
 528        stat->blocks =
 529                XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
 530
 531
 532        switch (inode->i_mode & S_IFMT) {
 533        case S_IFBLK:
 534        case S_IFCHR:
 535                stat->blksize = BLKDEV_IOSIZE;
 536                stat->rdev = inode->i_rdev;
 537                break;
 538        default:
 539                if (XFS_IS_REALTIME_INODE(ip)) {
 540                        /*
 541                         * If the file blocks are being allocated from a
 542                         * realtime volume, then return the inode's realtime
 543                         * extent size or the realtime volume's extent size.
 544                         */
 545                        stat->blksize =
 546                                xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
 547                } else
 548                        stat->blksize = xfs_preferred_iosize(mp);
 549                stat->rdev = 0;
 550                break;
 551        }
 552
 553        return 0;
 554}
 555
 556static void
 557xfs_setattr_mode(
 558        struct xfs_inode        *ip,
 559        struct iattr            *iattr)
 560{
 561        struct inode            *inode = VFS_I(ip);
 562        umode_t                 mode = iattr->ia_mode;
 563
 564        ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
 565
 566        inode->i_mode &= S_IFMT;
 567        inode->i_mode |= mode & ~S_IFMT;
 568}
 569
 570void
 571xfs_setattr_time(
 572        struct xfs_inode        *ip,
 573        struct iattr            *iattr)
 574{
 575        struct inode            *inode = VFS_I(ip);
 576
 577        ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
 578
 579        if (iattr->ia_valid & ATTR_ATIME)
 580                inode->i_atime = iattr->ia_atime;
 581        if (iattr->ia_valid & ATTR_CTIME)
 582                inode->i_ctime = iattr->ia_ctime;
 583        if (iattr->ia_valid & ATTR_MTIME)
 584                inode->i_mtime = iattr->ia_mtime;
 585}
 586
 587static int
 588xfs_vn_change_ok(
 589        struct dentry   *dentry,
 590        struct iattr    *iattr)
 591{
 592        struct inode            *inode = d_inode(dentry);
 593        struct xfs_inode        *ip = XFS_I(inode);
 594        struct xfs_mount        *mp = ip->i_mount;
 595
 596        if (mp->m_flags & XFS_MOUNT_RDONLY)
 597                return -EROFS;
 598
 599        if (XFS_FORCED_SHUTDOWN(mp))
 600                return -EIO;
 601
 602        return inode_change_ok(inode, iattr);
 603}
 604
 605/*
 606 * Set non-size attributes of an inode.
 607 *
 608 * Caution: The caller of this function is responsible for calling
 609 * inode_change_ok() or otherwise verifying the change is fine.
 610 */
 611int
 612xfs_setattr_nonsize(
 613        struct xfs_inode        *ip,
 614        struct iattr            *iattr,
 615        int                     flags)
 616{
 617        xfs_mount_t             *mp = ip->i_mount;
 618        struct inode            *inode = VFS_I(ip);
 619        int                     mask = iattr->ia_valid;
 620        xfs_trans_t             *tp;
 621        int                     error;
 622        kuid_t                  uid = GLOBAL_ROOT_UID, iuid = GLOBAL_ROOT_UID;
 623        kgid_t                  gid = GLOBAL_ROOT_GID, igid = GLOBAL_ROOT_GID;
 624        struct xfs_dquot        *udqp = NULL, *gdqp = NULL;
 625        struct xfs_dquot        *olddquot1 = NULL, *olddquot2 = NULL;
 626
 627        ASSERT((mask & ATTR_SIZE) == 0);
 628
 629        /*
 630         * If disk quotas is on, we make sure that the dquots do exist on disk,
 631         * before we start any other transactions. Trying to do this later
 632         * is messy. We don't care to take a readlock to look at the ids
 633         * in inode here, because we can't hold it across the trans_reserve.
 634         * If the IDs do change before we take the ilock, we're covered
 635         * because the i_*dquot fields will get updated anyway.
 636         */
 637        if (XFS_IS_QUOTA_ON(mp) && (mask & (ATTR_UID|ATTR_GID))) {
 638                uint    qflags = 0;
 639
 640                if ((mask & ATTR_UID) && XFS_IS_UQUOTA_ON(mp)) {
 641                        uid = iattr->ia_uid;
 642                        qflags |= XFS_QMOPT_UQUOTA;
 643                } else {
 644                        uid = inode->i_uid;
 645                }
 646                if ((mask & ATTR_GID) && XFS_IS_GQUOTA_ON(mp)) {
 647                        gid = iattr->ia_gid;
 648                        qflags |= XFS_QMOPT_GQUOTA;
 649                }  else {
 650                        gid = inode->i_gid;
 651                }
 652
 653                /*
 654                 * We take a reference when we initialize udqp and gdqp,
 655                 * so it is important that we never blindly double trip on
 656                 * the same variable. See xfs_create() for an example.
 657                 */
 658                ASSERT(udqp == NULL);
 659                ASSERT(gdqp == NULL);
 660                error = xfs_qm_vop_dqalloc(ip, xfs_kuid_to_uid(uid),
 661                                           xfs_kgid_to_gid(gid),
 662                                           xfs_get_projid(ip),
 663                                           qflags, &udqp, &gdqp, NULL);
 664                if (error)
 665                        return error;
 666        }
 667
 668        error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
 669        if (error)
 670                goto out_dqrele;
 671
 672        xfs_ilock(ip, XFS_ILOCK_EXCL);
 673        xfs_trans_ijoin(tp, ip, 0);
 674
 675        /*
 676         * Change file ownership.  Must be the owner or privileged.
 677         */
 678        if (mask & (ATTR_UID|ATTR_GID)) {
 679                /*
 680                 * These IDs could have changed since we last looked at them.
 681                 * But, we're assured that if the ownership did change
 682                 * while we didn't have the inode locked, inode's dquot(s)
 683                 * would have changed also.
 684                 */
 685                iuid = inode->i_uid;
 686                igid = inode->i_gid;
 687                gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
 688                uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
 689
 690                /*
 691                 * Do a quota reservation only if uid/gid is actually
 692                 * going to change.
 693                 */
 694                if (XFS_IS_QUOTA_RUNNING(mp) &&
 695                    ((XFS_IS_UQUOTA_ON(mp) && !uid_eq(iuid, uid)) ||
 696                     (XFS_IS_GQUOTA_ON(mp) && !gid_eq(igid, gid)))) {
 697                        ASSERT(tp);
 698                        error = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
 699                                                NULL, capable(CAP_FOWNER) ?
 700                                                XFS_QMOPT_FORCE_RES : 0);
 701                        if (error)      /* out of quota */
 702                                goto out_cancel;
 703                }
 704        }
 705
 706        /*
 707         * Change file ownership.  Must be the owner or privileged.
 708         */
 709        if (mask & (ATTR_UID|ATTR_GID)) {
 710                /*
 711                 * CAP_FSETID overrides the following restrictions:
 712                 *
 713                 * The set-user-ID and set-group-ID bits of a file will be
 714                 * cleared upon successful return from chown()
 715                 */
 716                if ((inode->i_mode & (S_ISUID|S_ISGID)) &&
 717                    !capable(CAP_FSETID))
 718                        inode->i_mode &= ~(S_ISUID|S_ISGID);
 719
 720                /*
 721                 * Change the ownerships and register quota modifications
 722                 * in the transaction.
 723                 */
 724                if (!uid_eq(iuid, uid)) {
 725                        if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
 726                                ASSERT(mask & ATTR_UID);
 727                                ASSERT(udqp);
 728                                olddquot1 = xfs_qm_vop_chown(tp, ip,
 729                                                        &ip->i_udquot, udqp);
 730                        }
 731                        ip->i_d.di_uid = xfs_kuid_to_uid(uid);
 732                        inode->i_uid = uid;
 733                }
 734                if (!gid_eq(igid, gid)) {
 735                        if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_GQUOTA_ON(mp)) {
 736                                ASSERT(xfs_sb_version_has_pquotino(&mp->m_sb) ||
 737                                       !XFS_IS_PQUOTA_ON(mp));
 738                                ASSERT(mask & ATTR_GID);
 739                                ASSERT(gdqp);
 740                                olddquot2 = xfs_qm_vop_chown(tp, ip,
 741                                                        &ip->i_gdquot, gdqp);
 742                        }
 743                        ip->i_d.di_gid = xfs_kgid_to_gid(gid);
 744                        inode->i_gid = gid;
 745                }
 746        }
 747
 748        if (mask & ATTR_MODE)
 749                xfs_setattr_mode(ip, iattr);
 750        if (mask & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
 751                xfs_setattr_time(ip, iattr);
 752
 753        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 754
 755        XFS_STATS_INC(mp, xs_ig_attrchg);
 756
 757        if (mp->m_flags & XFS_MOUNT_WSYNC)
 758                xfs_trans_set_sync(tp);
 759        error = xfs_trans_commit(tp);
 760
 761        xfs_iunlock(ip, XFS_ILOCK_EXCL);
 762
 763        /*
 764         * Release any dquot(s) the inode had kept before chown.
 765         */
 766        xfs_qm_dqrele(olddquot1);
 767        xfs_qm_dqrele(olddquot2);
 768        xfs_qm_dqrele(udqp);
 769        xfs_qm_dqrele(gdqp);
 770
 771        if (error)
 772                return error;
 773
 774        /*
 775         * XXX(hch): Updating the ACL entries is not atomic vs the i_mode
 776         *           update.  We could avoid this with linked transactions
 777         *           and passing down the transaction pointer all the way
 778         *           to attr_set.  No previous user of the generic
 779         *           Posix ACL code seems to care about this issue either.
 780         */
 781        if ((mask & ATTR_MODE) && !(flags & XFS_ATTR_NOACL)) {
 782                error = xfs_acl_chmod(inode);
 783                if (error)
 784                        return error;
 785        }
 786
 787        return 0;
 788
 789out_cancel:
 790        xfs_trans_cancel(tp);
 791        xfs_iunlock(ip, XFS_ILOCK_EXCL);
 792out_dqrele:
 793        xfs_qm_dqrele(udqp);
 794        xfs_qm_dqrele(gdqp);
 795        return error;
 796}
 797
 798int
 799xfs_vn_setattr_nonsize(
 800        struct dentry           *dentry,
 801        struct iattr            *iattr)
 802{
 803        struct xfs_inode        *ip = XFS_I(d_inode(dentry));
 804        int error;
 805
 806        trace_xfs_setattr(ip);
 807
 808        error = xfs_vn_change_ok(dentry, iattr);
 809        if (error)
 810                return error;
 811        return xfs_setattr_nonsize(ip, iattr, 0);
 812}
 813
 814/*
 815 * Truncate file.  Must have write permission and not be a directory.
 816 *
 817 * Caution: The caller of this function is responsible for calling
 818 * inode_change_ok() or otherwise verifying the change is fine.
 819 */
 820STATIC int
 821xfs_setattr_size(
 822        struct xfs_inode        *ip,
 823        struct iattr            *iattr)
 824{
 825        struct xfs_mount        *mp = ip->i_mount;
 826        struct inode            *inode = VFS_I(ip);
 827        xfs_off_t               oldsize, newsize;
 828        struct xfs_trans        *tp;
 829        int                     error;
 830        uint                    lock_flags = 0;
 831        bool                    did_zeroing = false;
 832
 833        ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
 834        ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL));
 835        ASSERT(S_ISREG(inode->i_mode));
 836        ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
 837                ATTR_MTIME_SET|ATTR_KILL_PRIV|ATTR_TIMES_SET)) == 0);
 838
 839        oldsize = inode->i_size;
 840        newsize = iattr->ia_size;
 841
 842        /*
 843         * Short circuit the truncate case for zero length files.
 844         */
 845        if (newsize == 0 && oldsize == 0 && ip->i_d.di_nextents == 0) {
 846                if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
 847                        return 0;
 848
 849                /*
 850                 * Use the regular setattr path to update the timestamps.
 851                 */
 852                iattr->ia_valid &= ~ATTR_SIZE;
 853                return xfs_setattr_nonsize(ip, iattr, 0);
 854        }
 855
 856        /*
 857         * Make sure that the dquots are attached to the inode.
 858         */
 859        error = xfs_qm_dqattach(ip, 0);
 860        if (error)
 861                return error;
 862
 863        /*
 864         * Wait for all direct I/O to complete.
 865         */
 866        inode_dio_wait(inode);
 867
 868        /*
 869         * File data changes must be complete before we start the transaction to
 870         * modify the inode.  This needs to be done before joining the inode to
 871         * the transaction because the inode cannot be unlocked once it is a
 872         * part of the transaction.
 873         *
 874         * Start with zeroing any data beyond EOF that we may expose on file
 875         * extension, or zeroing out the rest of the block on a downward
 876         * truncate.
 877         */
 878        if (newsize > oldsize) {
 879                error = xfs_zero_eof(ip, newsize, oldsize, &did_zeroing);
 880        } else {
 881                error = iomap_truncate_page(inode, newsize, &did_zeroing,
 882                                &xfs_iomap_ops);
 883        }
 884
 885        if (error)
 886                return error;
 887
 888        /*
 889         * We've already locked out new page faults, so now we can safely remove
 890         * pages from the page cache knowing they won't get refaulted until we
 891         * drop the XFS_MMAP_EXCL lock after the extent manipulations are
 892         * complete. The truncate_setsize() call also cleans partial EOF page
 893         * PTEs on extending truncates and hence ensures sub-page block size
 894         * filesystems are correctly handled, too.
 895         *
 896         * We have to do all the page cache truncate work outside the
 897         * transaction context as the "lock" order is page lock->log space
 898         * reservation as defined by extent allocation in the writeback path.
 899         * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
 900         * having already truncated the in-memory version of the file (i.e. made
 901         * user visible changes). There's not much we can do about this, except
 902         * to hope that the caller sees ENOMEM and retries the truncate
 903         * operation.
 904         *
 905         * And we update in-core i_size and truncate page cache beyond newsize
 906         * before writeback the [di_size, newsize] range, so we're guaranteed
 907         * not to write stale data past the new EOF on truncate down.
 908         */
 909        truncate_setsize(inode, newsize);
 910
 911        /*
 912         * We are going to log the inode size change in this transaction so
 913         * any previous writes that are beyond the on disk EOF and the new
 914         * EOF that have not been written out need to be written here.  If we
 915         * do not write the data out, we expose ourselves to the null files
 916         * problem. Note that this includes any block zeroing we did above;
 917         * otherwise those blocks may not be zeroed after a crash.
 918         */
 919        if (did_zeroing ||
 920            (newsize > ip->i_d.di_size && oldsize != ip->i_d.di_size)) {
 921                error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
 922                                                ip->i_d.di_size, newsize - 1);
 923                if (error)
 924                        return error;
 925        }
 926
 927        error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
 928        if (error)
 929                return error;
 930
 931        lock_flags |= XFS_ILOCK_EXCL;
 932        xfs_ilock(ip, XFS_ILOCK_EXCL);
 933        xfs_trans_ijoin(tp, ip, 0);
 934
 935        /*
 936         * Only change the c/mtime if we are changing the size or we are
 937         * explicitly asked to change it.  This handles the semantic difference
 938         * between truncate() and ftruncate() as implemented in the VFS.
 939         *
 940         * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
 941         * special case where we need to update the times despite not having
 942         * these flags set.  For all other operations the VFS set these flags
 943         * explicitly if it wants a timestamp update.
 944         */
 945        if (newsize != oldsize &&
 946            !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) {
 947                iattr->ia_ctime = iattr->ia_mtime =
 948                        current_fs_time(inode->i_sb);
 949                iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
 950        }
 951
 952        /*
 953         * The first thing we do is set the size to new_size permanently on
 954         * disk.  This way we don't have to worry about anyone ever being able
 955         * to look at the data being freed even in the face of a crash.
 956         * What we're getting around here is the case where we free a block, it
 957         * is allocated to another file, it is written to, and then we crash.
 958         * If the new data gets written to the file but the log buffers
 959         * containing the free and reallocation don't, then we'd end up with
 960         * garbage in the blocks being freed.  As long as we make the new size
 961         * permanent before actually freeing any blocks it doesn't matter if
 962         * they get written to.
 963         */
 964        ip->i_d.di_size = newsize;
 965        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 966
 967        if (newsize <= oldsize) {
 968                error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, newsize);
 969                if (error)
 970                        goto out_trans_cancel;
 971
 972                /*
 973                 * Truncated "down", so we're removing references to old data
 974                 * here - if we delay flushing for a long time, we expose
 975                 * ourselves unduly to the notorious NULL files problem.  So,
 976                 * we mark this inode and flush it when the file is closed,
 977                 * and do not wait the usual (long) time for writeout.
 978                 */
 979                xfs_iflags_set(ip, XFS_ITRUNCATED);
 980
 981                /* A truncate down always removes post-EOF blocks. */
 982                xfs_inode_clear_eofblocks_tag(ip);
 983        }
 984
 985        if (iattr->ia_valid & ATTR_MODE)
 986                xfs_setattr_mode(ip, iattr);
 987        if (iattr->ia_valid & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
 988                xfs_setattr_time(ip, iattr);
 989
 990        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 991
 992        XFS_STATS_INC(mp, xs_ig_attrchg);
 993
 994        if (mp->m_flags & XFS_MOUNT_WSYNC)
 995                xfs_trans_set_sync(tp);
 996
 997        error = xfs_trans_commit(tp);
 998out_unlock:
 999        if (lock_flags)
1000                xfs_iunlock(ip, lock_flags);
1001        return error;
1002
1003out_trans_cancel:
1004        xfs_trans_cancel(tp);
1005        goto out_unlock;
1006}
1007
1008int
1009xfs_vn_setattr_size(
1010        struct dentry           *dentry,
1011        struct iattr            *iattr)
1012{
1013        struct xfs_inode        *ip = XFS_I(d_inode(dentry));
1014        int error;
1015
1016        trace_xfs_setattr(ip);
1017
1018        error = xfs_vn_change_ok(dentry, iattr);
1019        if (error)
1020                return error;
1021        return xfs_setattr_size(ip, iattr);
1022}
1023
1024STATIC int
1025xfs_vn_setattr(
1026        struct dentry           *dentry,
1027        struct iattr            *iattr)
1028{
1029        int                     error;
1030
1031        if (iattr->ia_valid & ATTR_SIZE) {
1032                struct inode            *inode = d_inode(dentry);
1033                struct xfs_inode        *ip = XFS_I(inode);
1034                uint                    iolock;
1035
1036                iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
1037
1038                xfs_ilock(ip, iolock);
1039                error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP, true);
1040                if (!error)
1041                        error = xfs_vn_setattr_size(dentry, iattr);
1042                xfs_iunlock(ip, iolock);
1043        } else {
1044                error = xfs_vn_setattr_nonsize(dentry, iattr);
1045        }
1046
1047        return error;
1048}
1049
1050STATIC int
1051xfs_vn_update_time(
1052        struct inode            *inode,
1053        struct timespec         *now,
1054        int                     flags)
1055{
1056        struct xfs_inode        *ip = XFS_I(inode);
1057        struct xfs_mount        *mp = ip->i_mount;
1058        struct xfs_trans        *tp;
1059        int                     error;
1060
1061        trace_xfs_update_time(ip);
1062
1063        error = xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp);
1064        if (error)
1065                return error;
1066
1067        xfs_ilock(ip, XFS_ILOCK_EXCL);
1068        if (flags & S_CTIME)
1069                inode->i_ctime = *now;
1070        if (flags & S_MTIME)
1071                inode->i_mtime = *now;
1072        if (flags & S_ATIME)
1073                inode->i_atime = *now;
1074
1075        xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1076        xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
1077        return xfs_trans_commit(tp);
1078}
1079
1080STATIC int
1081xfs_vn_fiemap(
1082        struct inode            *inode,
1083        struct fiemap_extent_info *fieinfo,
1084        u64                     start,
1085        u64                     length)
1086{
1087        int                     error;
1088
1089        xfs_ilock(XFS_I(inode), XFS_IOLOCK_SHARED);
1090        if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
1091                fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR;
1092                error = iomap_fiemap(inode, fieinfo, start, length,
1093                                &xfs_xattr_iomap_ops);
1094        } else {
1095                error = iomap_fiemap(inode, fieinfo, start, length,
1096                                &xfs_iomap_ops);
1097        }
1098        xfs_iunlock(XFS_I(inode), XFS_IOLOCK_SHARED);
1099
1100        return error;
1101}
1102
1103STATIC int
1104xfs_vn_tmpfile(
1105        struct inode    *dir,
1106        struct dentry   *dentry,
1107        umode_t         mode)
1108{
1109        return xfs_generic_create(dir, dentry, mode, 0, true);
1110}
1111
1112static const struct inode_operations xfs_inode_operations = {
1113        .get_acl                = xfs_get_acl,
1114        .getattr                = xfs_vn_getattr,
1115        .setattr                = xfs_vn_setattr,
1116        .setxattr               = generic_setxattr,
1117        .getxattr               = generic_getxattr,
1118        .removexattr            = generic_removexattr,
1119        .listxattr              = xfs_vn_listxattr,
1120        .fiemap                 = xfs_vn_fiemap,
1121        .update_time            = xfs_vn_update_time,
1122};
1123
1124static const struct inode_operations_wrapper xfs_dir_inode_operations = {
1125        .ops = {
1126        .create                 = xfs_vn_create,
1127        .lookup                 = xfs_vn_lookup,
1128        .link                   = xfs_vn_link,
1129        .unlink                 = xfs_vn_unlink,
1130        .symlink                = xfs_vn_symlink,
1131        .mkdir                  = xfs_vn_mkdir,
1132        /*
1133         * Yes, XFS uses the same method for rmdir and unlink.
1134         *
1135         * There are some subtile differences deeper in the code,
1136         * but we use S_ISDIR to check for those.
1137         */
1138        .rmdir                  = xfs_vn_unlink,
1139        .mknod                  = xfs_vn_mknod,
1140        .rename                 = xfs_vn_rename_old,
1141        .get_acl                = xfs_get_acl,
1142        .getattr                = xfs_vn_getattr,
1143        .setattr                = xfs_vn_setattr,
1144        .setxattr               = generic_setxattr,
1145        .getxattr               = generic_getxattr,
1146        .removexattr            = generic_removexattr,
1147        .listxattr              = xfs_vn_listxattr,
1148        .update_time            = xfs_vn_update_time,
1149        },
1150        .rename2                = xfs_vn_rename,
1151        .tmpfile                = xfs_vn_tmpfile,
1152};
1153
1154static const struct inode_operations_wrapper xfs_dir_ci_inode_operations = {
1155        .ops = {
1156        .create                 = xfs_vn_create,
1157        .lookup                 = xfs_vn_ci_lookup,
1158        .link                   = xfs_vn_link,
1159        .unlink                 = xfs_vn_unlink,
1160        .symlink                = xfs_vn_symlink,
1161        .mkdir                  = xfs_vn_mkdir,
1162        /*
1163         * Yes, XFS uses the same method for rmdir and unlink.
1164         *
1165         * There are some subtile differences deeper in the code,
1166         * but we use S_ISDIR to check for those.
1167         */
1168        .rmdir                  = xfs_vn_unlink,
1169        .mknod                  = xfs_vn_mknod,
1170        .rename                 = xfs_vn_rename_old,
1171        .get_acl                = xfs_get_acl,
1172        .getattr                = xfs_vn_getattr,
1173        .setattr                = xfs_vn_setattr,
1174        .setxattr               = generic_setxattr,
1175        .getxattr               = generic_getxattr,
1176        .removexattr            = generic_removexattr,
1177        .listxattr              = xfs_vn_listxattr,
1178        .update_time            = xfs_vn_update_time,
1179        },
1180        .rename2                = xfs_vn_rename,
1181        .tmpfile                = xfs_vn_tmpfile,
1182};
1183
1184static const struct inode_operations xfs_symlink_inode_operations = {
1185        .readlink               = generic_readlink,
1186        .follow_link            = xfs_vn_follow_link,
1187        .put_link               = xfs_vn_put_link,
1188        .get_acl                = xfs_get_acl,
1189        .getattr                = xfs_vn_getattr,
1190        .setattr                = xfs_vn_setattr,
1191        .setxattr               = generic_setxattr,
1192        .getxattr               = generic_getxattr,
1193        .removexattr            = generic_removexattr,
1194        .listxattr              = xfs_vn_listxattr,
1195        .update_time            = xfs_vn_update_time,
1196};
1197
1198/* Figure out if this file actually supports DAX. */
1199static bool
1200xfs_inode_supports_dax(
1201        struct xfs_inode        *ip)
1202{
1203        struct xfs_mount        *mp = ip->i_mount;
1204
1205        /* Only supported on regular files. */
1206        if (!S_ISREG(VFS_I(ip)->i_mode))
1207                return false;
1208
1209        /* DAX mount option must be set. */
1210        if (!(mp->m_flags & XFS_MOUNT_DAX))
1211                return false;
1212
1213        /* Block size must match page size */
1214        if (mp->m_sb.sb_blocksize != PAGE_SIZE)
1215                return false;
1216
1217        /* Device has to support DAX too. */
1218        return xfs_find_daxdev_for_inode(VFS_I(ip)) != NULL;
1219}
1220
1221STATIC void
1222xfs_diflags_to_iflags(
1223        struct inode            *inode,
1224        struct xfs_inode        *ip)
1225{
1226        uint16_t                flags = ip->i_d.di_flags;
1227
1228        inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC |
1229                            S_NOATIME | S_DAX);
1230
1231        if (flags & XFS_DIFLAG_IMMUTABLE)
1232                inode->i_flags |= S_IMMUTABLE;
1233        if (flags & XFS_DIFLAG_APPEND)
1234                inode->i_flags |= S_APPEND;
1235        if (flags & XFS_DIFLAG_SYNC)
1236                inode->i_flags |= S_SYNC;
1237        if (flags & XFS_DIFLAG_NOATIME)
1238                inode->i_flags |= S_NOATIME;
1239        if (xfs_inode_supports_dax(ip))
1240                inode->i_flags |= S_DAX;
1241}
1242
1243/*
1244 * Initialize the Linux inode.
1245 *
1246 * When reading existing inodes from disk this is called directly from xfs_iget,
1247 * when creating a new inode it is called from xfs_ialloc after setting up the
1248 * inode. These callers have different criteria for clearing XFS_INEW, so leave
1249 * it up to the caller to deal with unlocking the inode appropriately.
1250 */
1251void
1252xfs_setup_inode(
1253        struct xfs_inode        *ip)
1254{
1255        struct inode            *inode = &ip->i_vnode;
1256        gfp_t                   gfp_mask;
1257
1258        inode->i_ino = ip->i_ino;
1259        inode->i_state = I_NEW;
1260
1261        inode_sb_list_add(inode);
1262        /* make the inode look hashed for the writeback code */
1263        hlist_add_fake(&inode->i_hash);
1264
1265        inode->i_uid    = xfs_uid_to_kuid(ip->i_d.di_uid);
1266        inode->i_gid    = xfs_gid_to_kgid(ip->i_d.di_gid);
1267
1268        i_size_write(inode, ip->i_d.di_size);
1269        xfs_diflags_to_iflags(inode, ip);
1270
1271        if (S_ISDIR(inode->i_mode)) {
1272                lockdep_set_class(&ip->i_lock.mr_lock, &xfs_dir_ilock_class);
1273                ip->d_ops = ip->i_mount->m_dir_inode_ops;
1274        } else {
1275                ip->d_ops = ip->i_mount->m_nondir_inode_ops;
1276                lockdep_set_class(&ip->i_lock.mr_lock, &xfs_nondir_ilock_class);
1277        }
1278
1279        /*
1280         * Ensure all page cache allocations are done from GFP_NOFS context to
1281         * prevent direct reclaim recursion back into the filesystem and blowing
1282         * stacks or deadlocking.
1283         */
1284        gfp_mask = mapping_gfp_mask(inode->i_mapping);
1285        mapping_set_gfp_mask(inode->i_mapping, (gfp_mask & ~(__GFP_FS)));
1286
1287        /*
1288         * If there is no attribute fork no ACL can exist on this inode,
1289         * and it can't have any file capabilities attached to it either.
1290         */
1291        if (!XFS_IFORK_Q(ip)) {
1292                inode_has_no_xattr(inode);
1293                cache_no_acl(inode);
1294        }
1295}
1296
1297void
1298xfs_setup_iops(
1299        struct xfs_inode        *ip)
1300{
1301        struct inode            *inode = &ip->i_vnode;
1302
1303        switch (inode->i_mode & S_IFMT) {
1304        case S_IFREG:
1305                inode->i_op = &xfs_inode_operations;
1306                inode->i_fop = &xfs_file_operations.kabi_fops;
1307                if (IS_DAX(inode))
1308                        inode->i_mapping->a_ops = &xfs_dax_aops;
1309                else
1310                        inode->i_mapping->a_ops = &xfs_address_space_operations;
1311                break;
1312        case S_IFDIR:
1313                if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb)) {
1314                        inode->i_op = &xfs_dir_ci_inode_operations.ops;
1315                        inode->i_flags |= S_IOPS_WRAPPER;
1316                } else {
1317                        inode->i_op = &xfs_dir_inode_operations.ops;
1318                        inode->i_flags |= S_IOPS_WRAPPER;
1319                }
1320                inode->i_fop = &xfs_dir_file_operations;
1321                break;
1322        case S_IFLNK:
1323                inode->i_op = &xfs_symlink_inode_operations;
1324                if (!(ip->i_df.if_flags & XFS_IFINLINE))
1325                        inode->i_mapping->a_ops = &xfs_address_space_operations;
1326                break;
1327        default:
1328                inode->i_op = &xfs_inode_operations;
1329                init_special_inode(inode, inode->i_mode, inode->i_rdev);
1330                break;
1331        }
1332}
1333