xfs_inode.c (94e1b69d1abd108d306e926c3012ec89e481c0da) xfs_inode.c (92bfc6e7c4eabbbd15e7d6d49123b296d05dcfd1)
1/*
2 * Copyright (c) 2000-2006 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 unchanged lines hidden (view full) ---

18#include <linux/log2.h>
19
20#include "xfs.h"
21#include "xfs_fs.h"
22#include "xfs_types.h"
23#include "xfs_bit.h"
24#include "xfs_log.h"
25#include "xfs_inum.h"
1/*
2 * Copyright (c) 2000-2006 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 unchanged lines hidden (view full) ---

18#include <linux/log2.h>
19
20#include "xfs.h"
21#include "xfs_fs.h"
22#include "xfs_types.h"
23#include "xfs_bit.h"
24#include "xfs_log.h"
25#include "xfs_inum.h"
26#include "xfs_imap.h"
27#include "xfs_trans.h"
28#include "xfs_trans_priv.h"
29#include "xfs_sb.h"
30#include "xfs_ag.h"
31#include "xfs_dir2.h"
32#include "xfs_dmapi.h"
33#include "xfs_mount.h"
34#include "xfs_bmap_btree.h"

--- 94 unchanged lines hidden (view full) ---

129 * Find the buffer associated with the given inode map
130 * We do basic validation checks on the buffer once it has been
131 * retrieved from disk.
132 */
133STATIC int
134xfs_imap_to_bp(
135 xfs_mount_t *mp,
136 xfs_trans_t *tp,
26#include "xfs_trans.h"
27#include "xfs_trans_priv.h"
28#include "xfs_sb.h"
29#include "xfs_ag.h"
30#include "xfs_dir2.h"
31#include "xfs_dmapi.h"
32#include "xfs_mount.h"
33#include "xfs_bmap_btree.h"

--- 94 unchanged lines hidden (view full) ---

128 * Find the buffer associated with the given inode map
129 * We do basic validation checks on the buffer once it has been
130 * retrieved from disk.
131 */
132STATIC int
133xfs_imap_to_bp(
134 xfs_mount_t *mp,
135 xfs_trans_t *tp,
137 xfs_imap_t *imap,
136 struct xfs_imap *imap,
138 xfs_buf_t **bpp,
139 uint buf_flags,
140 uint imap_flags)
141{
142 int error;
143 int i;
144 int ni;
145 xfs_buf_t *bp;

--- 81 unchanged lines hidden (view full) ---

227 xfs_mount_t *mp,
228 xfs_trans_t *tp,
229 xfs_ino_t ino,
230 xfs_dinode_t **dipp,
231 xfs_buf_t **bpp,
232 int *offset,
233 uint imap_flags)
234{
137 xfs_buf_t **bpp,
138 uint buf_flags,
139 uint imap_flags)
140{
141 int error;
142 int i;
143 int ni;
144 xfs_buf_t *bp;

--- 81 unchanged lines hidden (view full) ---

226 xfs_mount_t *mp,
227 xfs_trans_t *tp,
228 xfs_ino_t ino,
229 xfs_dinode_t **dipp,
230 xfs_buf_t **bpp,
231 int *offset,
232 uint imap_flags)
233{
235 xfs_imap_t imap;
234 struct xfs_imap imap;
236 xfs_buf_t *bp;
237 int error;
238
239 imap.im_blkno = 0;
240 error = xfs_imap(mp, tp, ino, &imap, imap_flags);
241 if (error)
242 return error;
243

--- 28 unchanged lines hidden (view full) ---

272xfs_itobp(
273 xfs_mount_t *mp,
274 xfs_trans_t *tp,
275 xfs_inode_t *ip,
276 xfs_dinode_t **dipp,
277 xfs_buf_t **bpp,
278 uint buf_flags)
279{
235 xfs_buf_t *bp;
236 int error;
237
238 imap.im_blkno = 0;
239 error = xfs_imap(mp, tp, ino, &imap, imap_flags);
240 if (error)
241 return error;
242

--- 28 unchanged lines hidden (view full) ---

271xfs_itobp(
272 xfs_mount_t *mp,
273 xfs_trans_t *tp,
274 xfs_inode_t *ip,
275 xfs_dinode_t **dipp,
276 xfs_buf_t **bpp,
277 uint buf_flags)
278{
280 xfs_imap_t imap;
281 xfs_buf_t *bp;
282 int error;
283
279 xfs_buf_t *bp;
280 int error;
281
284 ASSERT(ip->i_blkno != 0);
282 ASSERT(ip->i_imap.im_blkno != 0);
285
283
286 imap.im_blkno = ip->i_blkno;
287 imap.im_len = ip->i_len;
288 imap.im_boffset = ip->i_boffset;
289
290 error = xfs_imap_to_bp(mp, tp, &imap, &bp, buf_flags, 0);
284 error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &bp, buf_flags, 0);
291 if (error)
292 return error;
293
294 if (!bp) {
295 ASSERT(buf_flags & XFS_BUF_TRYLOCK);
296 ASSERT(tp == NULL);
297 *bpp = NULL;
298 return EAGAIN;
299 }
300
285 if (error)
286 return error;
287
288 if (!bp) {
289 ASSERT(buf_flags & XFS_BUF_TRYLOCK);
290 ASSERT(tp == NULL);
291 *bpp = NULL;
292 return EAGAIN;
293 }
294
301 *dipp = (xfs_dinode_t *)xfs_buf_offset(bp, imap.im_boffset);
295 *dipp = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
302 *bpp = bp;
303 return 0;
304}
305
306/*
307 * Move inode type and inode format specific information from the
308 * on-disk inode to the in-core inode. For fifos, devs, and sockets
309 * this means set if_rdev to the proper value. For files, directories,

--- 484 unchanged lines hidden (view full) ---

794 if (!inode_init_always(mp->m_super, VFS_I(ip))) {
795 kmem_zone_free(xfs_inode_zone, ip);
796 return NULL;
797 }
798
799 /* initialise the xfs inode */
800 ip->i_ino = ino;
801 ip->i_mount = mp;
296 *bpp = bp;
297 return 0;
298}
299
300/*
301 * Move inode type and inode format specific information from the
302 * on-disk inode to the in-core inode. For fifos, devs, and sockets
303 * this means set if_rdev to the proper value. For files, directories,

--- 484 unchanged lines hidden (view full) ---

788 if (!inode_init_always(mp->m_super, VFS_I(ip))) {
789 kmem_zone_free(xfs_inode_zone, ip);
790 return NULL;
791 }
792
793 /* initialise the xfs inode */
794 ip->i_ino = ino;
795 ip->i_mount = mp;
802 ip->i_blkno = 0;
803 ip->i_len = 0;
804 ip->i_boffset =0;
796 memset(&ip->i_imap, 0, sizeof(struct xfs_imap));
805 ip->i_afp = NULL;
806 memset(&ip->i_df, 0, sizeof(xfs_ifork_t));
807 ip->i_flags = 0;
808 ip->i_update_core = 0;
809 ip->i_update_size = 0;
810 ip->i_delayed_blks = 0;
811 memset(&ip->i_d, 0, sizeof(xfs_icdinode_t));
812 ip->i_size = 0;

--- 39 unchanged lines hidden (view full) ---

852 xfs_ino_t ino,
853 xfs_inode_t **ipp,
854 xfs_daddr_t bno,
855 uint imap_flags)
856{
857 xfs_buf_t *bp;
858 xfs_dinode_t *dip;
859 xfs_inode_t *ip;
797 ip->i_afp = NULL;
798 memset(&ip->i_df, 0, sizeof(xfs_ifork_t));
799 ip->i_flags = 0;
800 ip->i_update_core = 0;
801 ip->i_update_size = 0;
802 ip->i_delayed_blks = 0;
803 memset(&ip->i_d, 0, sizeof(xfs_icdinode_t));
804 ip->i_size = 0;

--- 39 unchanged lines hidden (view full) ---

844 xfs_ino_t ino,
845 xfs_inode_t **ipp,
846 xfs_daddr_t bno,
847 uint imap_flags)
848{
849 xfs_buf_t *bp;
850 xfs_dinode_t *dip;
851 xfs_inode_t *ip;
860 xfs_imap_t imap;
861 int error;
862
863 ip = xfs_inode_alloc(mp, ino);
864 if (!ip)
865 return ENOMEM;
866
867 /*
852 int error;
853
854 ip = xfs_inode_alloc(mp, ino);
855 if (!ip)
856 return ENOMEM;
857
858 /*
868 * Get pointers to the on-disk inode and the buffer containing it.
859 * Fill in the location information in the in-core inode.
869 */
860 */
870 imap.im_blkno = bno;
871 error = xfs_imap(mp, tp, ip->i_ino, &imap, imap_flags);
861 ip->i_imap.im_blkno = bno;
862 error = xfs_imap(mp, tp, ip->i_ino, &ip->i_imap, imap_flags);
872 if (error)
873 goto out_destroy_inode;
863 if (error)
864 goto out_destroy_inode;
865 ASSERT(bno == 0 || bno == ip->i_imap.im_blkno);
874
875 /*
866
867 /*
876 * Fill in the fields in the inode that will be used to
877 * map the inode to its buffer from now on.
868 * Get pointers to the on-disk inode and the buffer containing it.
878 */
869 */
879 ip->i_blkno = imap.im_blkno;
880 ip->i_len = imap.im_len;
881 ip->i_boffset = imap.im_boffset;
882 ASSERT(bno == 0 || bno == imap.im_blkno);
883
884 error = xfs_imap_to_bp(mp, tp, &imap, &bp, XFS_BUF_LOCK, imap_flags);
870 error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &bp,
871 XFS_BUF_LOCK, imap_flags);
885 if (error)
886 goto out_destroy_inode;
872 if (error)
873 goto out_destroy_inode;
887 dip = (xfs_dinode_t *)xfs_buf_offset(bp, imap.im_boffset);
874 dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
888
889 /*
890 * If we got something that isn't an inode it means someone
891 * (nfs or dmi) has a stale handle.
892 */
893 if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC) {
894#ifdef DEBUG
895 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_iread: "

--- 971 unchanged lines hidden (view full) ---

1867 */
1868 error = xfs_itobp(mp, tp, ip, &dip, &ibp, XFS_BUF_LOCK);
1869 if (error)
1870 return error;
1871
1872 ASSERT(be32_to_cpu(dip->di_next_unlinked) == NULLAGINO);
1873 /* both on-disk, don't endian flip twice */
1874 dip->di_next_unlinked = agi->agi_unlinked[bucket_index];
875
876 /*
877 * If we got something that isn't an inode it means someone
878 * (nfs or dmi) has a stale handle.
879 */
880 if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC) {
881#ifdef DEBUG
882 xfs_fs_cmn_err(CE_ALERT, mp, "xfs_iread: "

--- 971 unchanged lines hidden (view full) ---

1854 */
1855 error = xfs_itobp(mp, tp, ip, &dip, &ibp, XFS_BUF_LOCK);
1856 if (error)
1857 return error;
1858
1859 ASSERT(be32_to_cpu(dip->di_next_unlinked) == NULLAGINO);
1860 /* both on-disk, don't endian flip twice */
1861 dip->di_next_unlinked = agi->agi_unlinked[bucket_index];
1875 offset = ip->i_boffset +
1862 offset = ip->i_imap.im_boffset +
1876 offsetof(xfs_dinode_t, di_next_unlinked);
1877 xfs_trans_inode_buf(tp, ibp);
1878 xfs_trans_log_buf(tp, ibp, offset,
1879 (offset + sizeof(xfs_agino_t) - 1));
1880 xfs_inobp_check(mp, ibp);
1881 }
1882
1883 /*

--- 69 unchanged lines hidden (view full) ---

1953 "xfs_iunlink_remove: xfs_itobp() returned an error %d on %s. Returning error.",
1954 error, mp->m_fsname);
1955 return error;
1956 }
1957 next_agino = be32_to_cpu(dip->di_next_unlinked);
1958 ASSERT(next_agino != 0);
1959 if (next_agino != NULLAGINO) {
1960 dip->di_next_unlinked = cpu_to_be32(NULLAGINO);
1863 offsetof(xfs_dinode_t, di_next_unlinked);
1864 xfs_trans_inode_buf(tp, ibp);
1865 xfs_trans_log_buf(tp, ibp, offset,
1866 (offset + sizeof(xfs_agino_t) - 1));
1867 xfs_inobp_check(mp, ibp);
1868 }
1869
1870 /*

--- 69 unchanged lines hidden (view full) ---

1940 "xfs_iunlink_remove: xfs_itobp() returned an error %d on %s. Returning error.",
1941 error, mp->m_fsname);
1942 return error;
1943 }
1944 next_agino = be32_to_cpu(dip->di_next_unlinked);
1945 ASSERT(next_agino != 0);
1946 if (next_agino != NULLAGINO) {
1947 dip->di_next_unlinked = cpu_to_be32(NULLAGINO);
1961 offset = ip->i_boffset +
1948 offset = ip->i_imap.im_boffset +
1962 offsetof(xfs_dinode_t, di_next_unlinked);
1963 xfs_trans_inode_buf(tp, ibp);
1964 xfs_trans_log_buf(tp, ibp, offset,
1965 (offset + sizeof(xfs_agino_t) - 1));
1966 xfs_inobp_check(mp, ibp);
1967 } else {
1968 xfs_trans_brelse(tp, ibp);
1969 }

--- 46 unchanged lines hidden (view full) ---

2016 error, mp->m_fsname);
2017 return error;
2018 }
2019 next_agino = be32_to_cpu(dip->di_next_unlinked);
2020 ASSERT(next_agino != 0);
2021 ASSERT(next_agino != agino);
2022 if (next_agino != NULLAGINO) {
2023 dip->di_next_unlinked = cpu_to_be32(NULLAGINO);
1949 offsetof(xfs_dinode_t, di_next_unlinked);
1950 xfs_trans_inode_buf(tp, ibp);
1951 xfs_trans_log_buf(tp, ibp, offset,
1952 (offset + sizeof(xfs_agino_t) - 1));
1953 xfs_inobp_check(mp, ibp);
1954 } else {
1955 xfs_trans_brelse(tp, ibp);
1956 }

--- 46 unchanged lines hidden (view full) ---

2003 error, mp->m_fsname);
2004 return error;
2005 }
2006 next_agino = be32_to_cpu(dip->di_next_unlinked);
2007 ASSERT(next_agino != 0);
2008 ASSERT(next_agino != agino);
2009 if (next_agino != NULLAGINO) {
2010 dip->di_next_unlinked = cpu_to_be32(NULLAGINO);
2024 offset = ip->i_boffset +
2011 offset = ip->i_imap.im_boffset +
2025 offsetof(xfs_dinode_t, di_next_unlinked);
2026 xfs_trans_inode_buf(tp, ibp);
2027 xfs_trans_log_buf(tp, ibp, offset,
2028 (offset + sizeof(xfs_agino_t) - 1));
2029 xfs_inobp_check(mp, ibp);
2030 } else {
2031 xfs_trans_brelse(tp, ibp);
2032 }

--- 1163 unchanged lines hidden (view full) ---

3196 * flush lock and do nothing.
3197 */
3198 if (xfs_inode_clean(ip)) {
3199 xfs_ifunlock(ip);
3200 return 0;
3201 }
3202
3203 /* set *dip = inode's place in the buffer */
2012 offsetof(xfs_dinode_t, di_next_unlinked);
2013 xfs_trans_inode_buf(tp, ibp);
2014 xfs_trans_log_buf(tp, ibp, offset,
2015 (offset + sizeof(xfs_agino_t) - 1));
2016 xfs_inobp_check(mp, ibp);
2017 } else {
2018 xfs_trans_brelse(tp, ibp);
2019 }

--- 1163 unchanged lines hidden (view full) ---

3183 * flush lock and do nothing.
3184 */
3185 if (xfs_inode_clean(ip)) {
3186 xfs_ifunlock(ip);
3187 return 0;
3188 }
3189
3190 /* set *dip = inode's place in the buffer */
3204 dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_boffset);
3191 dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
3205
3206 /*
3207 * Clear i_update_core before copying out the data.
3208 * This is for coordination with our timestamp updates
3209 * that don't hold the inode lock. They will always
3210 * update the timestamps BEFORE setting i_update_core,
3211 * so if we clear i_update_core after they set it we
3212 * are guaranteed to see their updates to the timestamps.

--- 1234 unchanged lines hidden ---
3192
3193 /*
3194 * Clear i_update_core before copying out the data.
3195 * This is for coordination with our timestamp updates
3196 * that don't hold the inode lock. They will always
3197 * update the timestamps BEFORE setting i_update_core,
3198 * so if we clear i_update_core after they set it we
3199 * are guaranteed to see their updates to the timestamps.

--- 1234 unchanged lines hidden ---