David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Bob Peterson | ca39060 | 2008-01-28 11:15:57 -0600 | [diff] [blame] | 3 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * This copyrighted material is made available to anyone wishing to use, |
| 6 | * modify, copy, or redistribute it subject to the terms and conditions |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/completion.h> |
| 14 | #include <linux/buffer_head.h> |
| 15 | #include <linux/posix_acl.h> |
| 16 | #include <linux/sort.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 17 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 18 | #include <linux/crc32.h> |
Ryan O'Hara | fcb47e0 | 2006-10-03 11:57:35 -0400 | [diff] [blame] | 19 | #include <linux/security.h> |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 20 | #include <linux/time.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 21 | |
| 22 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 23 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 24 | #include "acl.h" |
| 25 | #include "bmap.h" |
| 26 | #include "dir.h" |
Steven Whitehouse | 307cf6e | 2009-08-26 18:51:04 +0100 | [diff] [blame] | 27 | #include "xattr.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 28 | #include "glock.h" |
| 29 | #include "glops.h" |
| 30 | #include "inode.h" |
| 31 | #include "log.h" |
| 32 | #include "meta_io.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 33 | #include "quota.h" |
| 34 | #include "rgrp.h" |
| 35 | #include "trans.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 36 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 37 | |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 38 | struct gfs2_inum_range_host { |
| 39 | u64 ir_start; |
| 40 | u64 ir_length; |
| 41 | }; |
| 42 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 43 | static int iget_test(struct inode *inode, void *opaque) |
| 44 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 45 | struct gfs2_inode *ip = GFS2_I(inode); |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 46 | u64 *no_addr = opaque; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 47 | |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 48 | if (ip->i_no_addr == *no_addr) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 49 | return 1; |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 54 | static int iget_set(struct inode *inode, void *opaque) |
| 55 | { |
| 56 | struct gfs2_inode *ip = GFS2_I(inode); |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 57 | u64 *no_addr = opaque; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 58 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 59 | inode->i_ino = (unsigned long)*no_addr; |
| 60 | ip->i_no_addr = *no_addr; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 64 | struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 65 | { |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 66 | unsigned long hash = (unsigned long)no_addr; |
| 67 | return ilookup5(sb, hash, iget_test, &no_addr); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 70 | static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 71 | { |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 72 | unsigned long hash = (unsigned long)no_addr; |
| 73 | return iget5_locked(sb, hash, iget_test, iget_set, &no_addr); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Benjamin Marzinski | 7a9f53b | 2007-09-18 13:33:18 -0500 | [diff] [blame] | 76 | struct gfs2_skip_data { |
| 77 | u64 no_addr; |
| 78 | int skipped; |
| 79 | }; |
| 80 | |
| 81 | static int iget_skip_test(struct inode *inode, void *opaque) |
| 82 | { |
| 83 | struct gfs2_inode *ip = GFS2_I(inode); |
| 84 | struct gfs2_skip_data *data = opaque; |
| 85 | |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 86 | if (ip->i_no_addr == data->no_addr) { |
Al Viro | a4ffdde | 2010-06-02 17:38:30 -0400 | [diff] [blame] | 87 | if (inode->i_state & (I_FREEING|I_WILL_FREE)){ |
Benjamin Marzinski | 7a9f53b | 2007-09-18 13:33:18 -0500 | [diff] [blame] | 88 | data->skipped = 1; |
| 89 | return 0; |
| 90 | } |
| 91 | return 1; |
| 92 | } |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static int iget_skip_set(struct inode *inode, void *opaque) |
| 97 | { |
| 98 | struct gfs2_inode *ip = GFS2_I(inode); |
| 99 | struct gfs2_skip_data *data = opaque; |
| 100 | |
| 101 | if (data->skipped) |
| 102 | return 1; |
| 103 | inode->i_ino = (unsigned long)(data->no_addr); |
| 104 | ip->i_no_addr = data->no_addr; |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static struct inode *gfs2_iget_skip(struct super_block *sb, |
| 109 | u64 no_addr) |
| 110 | { |
| 111 | struct gfs2_skip_data data; |
| 112 | unsigned long hash = (unsigned long)no_addr; |
| 113 | |
| 114 | data.no_addr = no_addr; |
| 115 | data.skipped = 0; |
| 116 | return iget5_locked(sb, hash, iget_skip_test, iget_skip_set, &data); |
| 117 | } |
| 118 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 119 | /** |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 120 | * GFS2 lookup code fills in vfs inode contents based on info obtained |
| 121 | * from directory entry inside gfs2_inode_lookup(). This has caused issues |
| 122 | * with NFS code path since its get_dentry routine doesn't have the relevant |
| 123 | * directory entry when gfs2_inode_lookup() is invoked. Part of the code |
| 124 | * segment inside gfs2_inode_lookup code needs to get moved around. |
| 125 | * |
Christoph Hellwig | eaff807 | 2009-12-17 14:25:01 +0100 | [diff] [blame] | 126 | * Clears I_NEW as well. |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 127 | **/ |
| 128 | |
| 129 | void gfs2_set_iop(struct inode *inode) |
| 130 | { |
Wendy Cheng | c97bfe4 | 2007-11-29 17:56:51 -0500 | [diff] [blame] | 131 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 132 | umode_t mode = inode->i_mode; |
| 133 | |
| 134 | if (S_ISREG(mode)) { |
| 135 | inode->i_op = &gfs2_file_iops; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 136 | if (gfs2_localflocks(sdp)) |
Christoph Hellwig | 10d2198 | 2009-04-07 19:42:17 +0200 | [diff] [blame] | 137 | inode->i_fop = &gfs2_file_fops_nolock; |
Wendy Cheng | c97bfe4 | 2007-11-29 17:56:51 -0500 | [diff] [blame] | 138 | else |
Christoph Hellwig | 10d2198 | 2009-04-07 19:42:17 +0200 | [diff] [blame] | 139 | inode->i_fop = &gfs2_file_fops; |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 140 | } else if (S_ISDIR(mode)) { |
| 141 | inode->i_op = &gfs2_dir_iops; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 142 | if (gfs2_localflocks(sdp)) |
Christoph Hellwig | 10d2198 | 2009-04-07 19:42:17 +0200 | [diff] [blame] | 143 | inode->i_fop = &gfs2_dir_fops_nolock; |
Wendy Cheng | c97bfe4 | 2007-11-29 17:56:51 -0500 | [diff] [blame] | 144 | else |
Christoph Hellwig | 10d2198 | 2009-04-07 19:42:17 +0200 | [diff] [blame] | 145 | inode->i_fop = &gfs2_dir_fops; |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 146 | } else if (S_ISLNK(mode)) { |
| 147 | inode->i_op = &gfs2_symlink_iops; |
| 148 | } else { |
Denis Cheng | d83225d | 2008-02-26 15:25:03 +0800 | [diff] [blame] | 149 | inode->i_op = &gfs2_file_iops; |
Denis Cheng | 43a33c5 | 2008-02-26 15:25:04 +0800 | [diff] [blame] | 150 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | unlock_new_inode(inode); |
| 154 | } |
| 155 | |
| 156 | /** |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 157 | * gfs2_inode_lookup - Lookup an inode |
| 158 | * @sb: The super block |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 159 | * @no_addr: The inode number |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 160 | * @type: The type of the inode |
| 161 | * |
| 162 | * Returns: A VFS inode, or an error |
| 163 | */ |
| 164 | |
Bob Peterson | 091806e | 2008-04-29 12:35:48 -0500 | [diff] [blame] | 165 | struct inode *gfs2_inode_lookup(struct super_block *sb, |
Wendy Cheng | bb9bcf0 | 2007-06-27 17:07:08 -0400 | [diff] [blame] | 166 | unsigned int type, |
| 167 | u64 no_addr, |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 168 | u64 no_formal_ino) |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 169 | { |
Benjamin Marzinski | 7a9f53b | 2007-09-18 13:33:18 -0500 | [diff] [blame] | 170 | struct inode *inode; |
| 171 | struct gfs2_inode *ip; |
Bob Peterson | b1becbd | 2010-06-17 16:45:37 -0400 | [diff] [blame] | 172 | struct gfs2_glock *io_gl = NULL; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 173 | int error; |
| 174 | |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 175 | inode = gfs2_iget(sb, no_addr); |
Benjamin Marzinski | 7a9f53b | 2007-09-18 13:33:18 -0500 | [diff] [blame] | 176 | ip = GFS2_I(inode); |
| 177 | |
Steven Whitehouse | 26d83de | 2006-10-30 16:59:08 -0500 | [diff] [blame] | 178 | if (!inode) |
| 179 | return ERR_PTR(-ENOBUFS); |
| 180 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 181 | if (inode->i_state & I_NEW) { |
| 182 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
Wendy Cheng | bb9bcf0 | 2007-06-27 17:07:08 -0400 | [diff] [blame] | 183 | ip->i_no_formal_ino = no_formal_ino; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 184 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 185 | error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 186 | if (unlikely(error)) |
| 187 | goto fail; |
| 188 | ip->i_gl->gl_object = ip; |
| 189 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 190 | error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 191 | if (unlikely(error)) |
| 192 | goto fail_put; |
| 193 | |
Steven Whitehouse | bfded27 | 2006-11-01 16:05:38 -0500 | [diff] [blame] | 194 | set_bit(GIF_INVALID, &ip->i_flags); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 195 | error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh); |
| 196 | if (unlikely(error)) |
| 197 | goto fail_iopen; |
Abhijith Das | d93cfa9 | 2007-06-11 08:22:32 +0100 | [diff] [blame] | 198 | ip->i_iopen_gh.gh_gl->gl_object = ip; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 199 | |
| 200 | gfs2_glock_put(io_gl); |
Bob Peterson | b1becbd | 2010-06-17 16:45:37 -0400 | [diff] [blame] | 201 | io_gl = NULL; |
Steven Whitehouse | c8cdf47 | 2007-06-08 10:05:33 +0100 | [diff] [blame] | 202 | |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 203 | if ((type == DT_UNKNOWN) && (no_formal_ino == 0)) |
| 204 | goto gfs2_nfsbypass; |
| 205 | |
| 206 | inode->i_mode = DT2IF(type); |
| 207 | |
Steven Whitehouse | c8cdf47 | 2007-06-08 10:05:33 +0100 | [diff] [blame] | 208 | /* |
| 209 | * We must read the inode in order to work out its type in |
| 210 | * this case. Note that this doesn't happen often as we normally |
| 211 | * know the type beforehand. This code path only occurs during |
| 212 | * unlinked inode recovery (where it is safe to do this glock, |
| 213 | * which is not true in the general case). |
| 214 | */ |
Steven Whitehouse | c8cdf47 | 2007-06-08 10:05:33 +0100 | [diff] [blame] | 215 | if (type == DT_UNKNOWN) { |
| 216 | struct gfs2_holder gh; |
| 217 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
| 218 | if (unlikely(error)) |
| 219 | goto fail_glock; |
| 220 | /* Inode is now uptodate */ |
Steven Whitehouse | c8cdf47 | 2007-06-08 10:05:33 +0100 | [diff] [blame] | 221 | gfs2_glock_dq_uninit(&gh); |
| 222 | } |
| 223 | |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 224 | gfs2_set_iop(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 225 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 226 | |
Wendy Cheng | 35dcc52 | 2007-06-27 17:07:53 -0400 | [diff] [blame] | 227 | gfs2_nfsbypass: |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 228 | return inode; |
Steven Whitehouse | c8cdf47 | 2007-06-08 10:05:33 +0100 | [diff] [blame] | 229 | fail_glock: |
| 230 | gfs2_glock_dq(&ip->i_iopen_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 231 | fail_iopen: |
Bob Peterson | b1becbd | 2010-06-17 16:45:37 -0400 | [diff] [blame] | 232 | if (io_gl) |
| 233 | gfs2_glock_put(io_gl); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 234 | fail_put: |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 235 | if (inode->i_state & I_NEW) |
| 236 | ip->i_gl->gl_object = NULL; |
| 237 | gfs2_glock_put(ip->i_gl); |
| 238 | fail: |
| 239 | if (inode->i_state & I_NEW) |
| 240 | iget_failed(inode); |
| 241 | else |
| 242 | iput(inode); |
| 243 | return ERR_PTR(error); |
| 244 | } |
| 245 | |
| 246 | /** |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 247 | * gfs2_process_unlinked_inode - Lookup an unlinked inode for reclamation |
| 248 | * and try to reclaim it by doing iput. |
| 249 | * |
| 250 | * This function assumes no rgrp locks are currently held. |
| 251 | * |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 252 | * @sb: The super block |
| 253 | * no_addr: The inode number |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 254 | * |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 255 | */ |
| 256 | |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 257 | void gfs2_process_unlinked_inode(struct super_block *sb, u64 no_addr) |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 258 | { |
| 259 | struct gfs2_sbd *sdp; |
| 260 | struct gfs2_inode *ip; |
Bob Peterson | b1becbd | 2010-06-17 16:45:37 -0400 | [diff] [blame] | 261 | struct gfs2_glock *io_gl = NULL; |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 262 | int error; |
| 263 | struct gfs2_holder gh; |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 264 | struct inode *inode; |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 265 | |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 266 | inode = gfs2_iget_skip(sb, no_addr); |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 267 | |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 268 | if (!inode) |
| 269 | return; |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 270 | |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 271 | /* If it's not a new inode, someone's using it, so leave it alone. */ |
| 272 | if (!(inode->i_state & I_NEW)) { |
| 273 | iput(inode); |
| 274 | return; |
| 275 | } |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 276 | |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 277 | ip = GFS2_I(inode); |
| 278 | sdp = GFS2_SB(inode); |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 279 | ip->i_no_formal_ino = -1; |
| 280 | |
| 281 | error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); |
| 282 | if (unlikely(error)) |
| 283 | goto fail; |
| 284 | ip->i_gl->gl_object = ip; |
| 285 | |
| 286 | error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); |
| 287 | if (unlikely(error)) |
| 288 | goto fail_put; |
| 289 | |
| 290 | set_bit(GIF_INVALID, &ip->i_flags); |
| 291 | error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, LM_FLAG_TRY | GL_EXACT, |
| 292 | &ip->i_iopen_gh); |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 293 | if (unlikely(error)) |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 294 | goto fail_iopen; |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 295 | |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 296 | ip->i_iopen_gh.gh_gl->gl_object = ip; |
| 297 | gfs2_glock_put(io_gl); |
Bob Peterson | b1becbd | 2010-06-17 16:45:37 -0400 | [diff] [blame] | 298 | io_gl = NULL; |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 299 | |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 300 | inode->i_mode = DT2IF(DT_UNKNOWN); |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * We must read the inode in order to work out its type in |
| 304 | * this case. Note that this doesn't happen often as we normally |
| 305 | * know the type beforehand. This code path only occurs during |
| 306 | * unlinked inode recovery (where it is safe to do this glock, |
| 307 | * which is not true in the general case). |
| 308 | */ |
| 309 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, LM_FLAG_TRY, |
| 310 | &gh); |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 311 | if (unlikely(error)) |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 312 | goto fail_glock; |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 313 | |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 314 | /* Inode is now uptodate */ |
| 315 | gfs2_glock_dq_uninit(&gh); |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 316 | gfs2_set_iop(inode); |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 317 | |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 318 | /* The iput will cause it to be deleted. */ |
| 319 | iput(inode); |
| 320 | return; |
| 321 | |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 322 | fail_glock: |
| 323 | gfs2_glock_dq(&ip->i_iopen_gh); |
| 324 | fail_iopen: |
Bob Peterson | b1becbd | 2010-06-17 16:45:37 -0400 | [diff] [blame] | 325 | if (io_gl) |
| 326 | gfs2_glock_put(io_gl); |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 327 | fail_put: |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 328 | ip->i_gl->gl_object = NULL; |
| 329 | gfs2_glock_put(ip->i_gl); |
| 330 | fail: |
Bob Peterson | ed4878e | 2010-05-20 23:30:11 -0400 | [diff] [blame] | 331 | iget_failed(inode); |
| 332 | return; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Steven Whitehouse | af339c0 | 2006-11-01 10:34:15 -0500 | [diff] [blame] | 335 | static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) |
Steven Whitehouse | ea744d0 | 2006-10-31 15:28:00 -0500 | [diff] [blame] | 336 | { |
Steven Whitehouse | ea744d0 | 2006-10-31 15:28:00 -0500 | [diff] [blame] | 337 | const struct gfs2_dinode *str = buf; |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 338 | struct timespec atime; |
Steven Whitehouse | 9a00450 | 2008-02-01 09:23:44 +0000 | [diff] [blame] | 339 | u16 height, depth; |
Steven Whitehouse | ea744d0 | 2006-10-31 15:28:00 -0500 | [diff] [blame] | 340 | |
Steven Whitehouse | ecc30c7 | 2008-01-28 10:37:35 +0000 | [diff] [blame] | 341 | if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr))) |
| 342 | goto corrupt; |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 343 | ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino); |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 344 | ip->i_inode.i_mode = be32_to_cpu(str->di_mode); |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 345 | ip->i_inode.i_rdev = 0; |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 346 | switch (ip->i_inode.i_mode & S_IFMT) { |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 347 | case S_IFBLK: |
| 348 | case S_IFCHR: |
| 349 | ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major), |
| 350 | be32_to_cpu(str->di_minor)); |
| 351 | break; |
| 352 | }; |
| 353 | |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 354 | ip->i_inode.i_uid = be32_to_cpu(str->di_uid); |
| 355 | ip->i_inode.i_gid = be32_to_cpu(str->di_gid); |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 356 | /* |
| 357 | * We will need to review setting the nlink count here in the |
| 358 | * light of the forthcoming ro bind mount work. This is a reminder |
| 359 | * to do that. |
| 360 | */ |
| 361 | ip->i_inode.i_nlink = be32_to_cpu(str->di_nlink); |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 362 | i_size_write(&ip->i_inode, be64_to_cpu(str->di_size)); |
Steven Whitehouse | 77658aa | 2008-02-12 14:17:27 +0000 | [diff] [blame] | 363 | gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks)); |
Steven Whitehouse | 719ee34 | 2008-09-18 13:53:59 +0100 | [diff] [blame] | 364 | atime.tv_sec = be64_to_cpu(str->di_atime); |
| 365 | atime.tv_nsec = be32_to_cpu(str->di_atime_nsec); |
| 366 | if (timespec_compare(&ip->i_inode.i_atime, &atime) < 0) |
| 367 | ip->i_inode.i_atime = atime; |
Steven Whitehouse | 1a7b1ee | 2006-11-01 14:35:17 -0500 | [diff] [blame] | 368 | ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime); |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 369 | ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec); |
Steven Whitehouse | 1a7b1ee | 2006-11-01 14:35:17 -0500 | [diff] [blame] | 370 | ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime); |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 371 | ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec); |
Steven Whitehouse | ea744d0 | 2006-10-31 15:28:00 -0500 | [diff] [blame] | 372 | |
Steven Whitehouse | ce276b0 | 2008-02-06 09:25:45 +0000 | [diff] [blame] | 373 | ip->i_goal = be64_to_cpu(str->di_goal_meta); |
Steven Whitehouse | bcf0b5b | 2008-11-03 13:39:46 +0000 | [diff] [blame] | 374 | ip->i_generation = be64_to_cpu(str->di_generation); |
Steven Whitehouse | ea744d0 | 2006-10-31 15:28:00 -0500 | [diff] [blame] | 375 | |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 376 | ip->i_diskflags = be32_to_cpu(str->di_flags); |
Steven Whitehouse | 6b124d8 | 2006-11-08 12:51:06 -0500 | [diff] [blame] | 377 | gfs2_set_inode_flags(&ip->i_inode); |
Steven Whitehouse | ecc30c7 | 2008-01-28 10:37:35 +0000 | [diff] [blame] | 378 | height = be16_to_cpu(str->di_height); |
| 379 | if (unlikely(height > GFS2_MAX_META_HEIGHT)) |
| 380 | goto corrupt; |
| 381 | ip->i_height = (u8)height; |
Steven Whitehouse | ea744d0 | 2006-10-31 15:28:00 -0500 | [diff] [blame] | 382 | |
Steven Whitehouse | 9a00450 | 2008-02-01 09:23:44 +0000 | [diff] [blame] | 383 | depth = be16_to_cpu(str->di_depth); |
| 384 | if (unlikely(depth > GFS2_DIR_MAX_DEPTH)) |
| 385 | goto corrupt; |
| 386 | ip->i_depth = (u8)depth; |
Steven Whitehouse | ad6203f | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 387 | ip->i_entries = be32_to_cpu(str->di_entries); |
Steven Whitehouse | ea744d0 | 2006-10-31 15:28:00 -0500 | [diff] [blame] | 388 | |
Steven Whitehouse | 3767ac2 | 2008-11-03 14:28:42 +0000 | [diff] [blame] | 389 | ip->i_eattr = be64_to_cpu(str->di_eattr); |
Steven Whitehouse | 5561093 | 2007-10-17 08:47:38 +0100 | [diff] [blame] | 390 | if (S_ISREG(ip->i_inode.i_mode)) |
| 391 | gfs2_set_aops(&ip->i_inode); |
| 392 | |
Steven Whitehouse | af339c0 | 2006-11-01 10:34:15 -0500 | [diff] [blame] | 393 | return 0; |
Steven Whitehouse | ecc30c7 | 2008-01-28 10:37:35 +0000 | [diff] [blame] | 394 | corrupt: |
| 395 | if (gfs2_consist_inode(ip)) |
| 396 | gfs2_dinode_print(ip); |
| 397 | return -EIO; |
Steven Whitehouse | ea744d0 | 2006-10-31 15:28:00 -0500 | [diff] [blame] | 398 | } |
| 399 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 400 | /** |
| 401 | * gfs2_inode_refresh - Refresh the incore copy of the dinode |
| 402 | * @ip: The GFS2 inode |
| 403 | * |
| 404 | * Returns: errno |
| 405 | */ |
| 406 | |
| 407 | int gfs2_inode_refresh(struct gfs2_inode *ip) |
| 408 | { |
| 409 | struct buffer_head *dibh; |
| 410 | int error; |
| 411 | |
| 412 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 413 | if (error) |
| 414 | return error; |
| 415 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 416 | if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 417 | brelse(dibh); |
| 418 | return -EIO; |
| 419 | } |
| 420 | |
Steven Whitehouse | af339c0 | 2006-11-01 10:34:15 -0500 | [diff] [blame] | 421 | error = gfs2_dinode_in(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 422 | brelse(dibh); |
Steven Whitehouse | bfded27 | 2006-11-01 16:05:38 -0500 | [diff] [blame] | 423 | clear_bit(GIF_INVALID, &ip->i_flags); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 424 | |
Steven Whitehouse | af339c0 | 2006-11-01 10:34:15 -0500 | [diff] [blame] | 425 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 428 | int gfs2_dinode_dealloc(struct gfs2_inode *ip) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 429 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 430 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 431 | struct gfs2_alloc *al; |
| 432 | struct gfs2_rgrpd *rgd; |
| 433 | int error; |
| 434 | |
Steven Whitehouse | 77658aa | 2008-02-12 14:17:27 +0000 | [diff] [blame] | 435 | if (gfs2_get_inode_blocks(&ip->i_inode) != 1) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 436 | if (gfs2_consist_inode(ip)) |
Steven Whitehouse | 4cc14f0 | 2006-10-31 19:00:24 -0500 | [diff] [blame] | 437 | gfs2_dinode_print(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 438 | return -EIO; |
| 439 | } |
| 440 | |
| 441 | al = gfs2_alloc_get(ip); |
Cyrill Gorcunov | 182fe5a | 2008-03-03 21:54:21 +0300 | [diff] [blame] | 442 | if (!al) |
| 443 | return -ENOMEM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 444 | |
| 445 | error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
| 446 | if (error) |
| 447 | goto out; |
| 448 | |
| 449 | error = gfs2_rindex_hold(sdp, &al->al_ri_gh); |
| 450 | if (error) |
| 451 | goto out_qs; |
| 452 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 453 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 454 | if (!rgd) { |
| 455 | gfs2_consist_inode(ip); |
| 456 | error = -EIO; |
| 457 | goto out_rindex_relse; |
| 458 | } |
| 459 | |
| 460 | error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, |
| 461 | &al->al_rgd_gh); |
| 462 | if (error) |
| 463 | goto out_rindex_relse; |
| 464 | |
Steven Whitehouse | 420b9e5 | 2006-07-31 15:42:17 -0400 | [diff] [blame] | 465 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 466 | if (error) |
| 467 | goto out_rg_gunlock; |
| 468 | |
Steven Whitehouse | 2bcd610 | 2007-11-08 14:25:12 +0000 | [diff] [blame] | 469 | set_bit(GLF_DIRTY, &ip->i_gl->gl_flags); |
| 470 | set_bit(GLF_LFLUSH, &ip->i_gl->gl_flags); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 471 | |
| 472 | gfs2_free_di(rgd, ip); |
| 473 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 474 | gfs2_trans_end(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 475 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 476 | out_rg_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 477 | gfs2_glock_dq_uninit(&al->al_rgd_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 478 | out_rindex_relse: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 479 | gfs2_glock_dq_uninit(&al->al_ri_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 480 | out_qs: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 481 | gfs2_quota_unhold(ip); |
Steven Whitehouse | 3632752 | 2006-04-28 10:46:21 -0400 | [diff] [blame] | 482 | out: |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 483 | gfs2_alloc_put(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 484 | return error; |
| 485 | } |
| 486 | |
| 487 | /** |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame] | 488 | * gfs2_change_nlink - Change nlink count on inode |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 489 | * @ip: The GFS2 inode |
| 490 | * @diff: The change in the nlink count required |
| 491 | * |
| 492 | * Returns: errno |
| 493 | */ |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame] | 494 | int gfs2_change_nlink(struct gfs2_inode *ip, int diff) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 495 | { |
| 496 | struct buffer_head *dibh; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 497 | u32 nlink; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 498 | int error; |
| 499 | |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 500 | BUG_ON(diff != 1 && diff != -1); |
| 501 | nlink = ip->i_inode.i_nlink + diff; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 502 | |
| 503 | /* If we are reducing the nlink count, but the new value ends up being |
| 504 | bigger than the old one, we must have underflowed. */ |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 505 | if (diff < 0 && nlink > ip->i_inode.i_nlink) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 506 | if (gfs2_consist_inode(ip)) |
Steven Whitehouse | 4cc14f0 | 2006-10-31 19:00:24 -0500 | [diff] [blame] | 507 | gfs2_dinode_print(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 508 | return -EIO; |
| 509 | } |
| 510 | |
| 511 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 512 | if (error) |
| 513 | return error; |
| 514 | |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 515 | if (diff > 0) |
| 516 | inc_nlink(&ip->i_inode); |
| 517 | else |
| 518 | drop_nlink(&ip->i_inode); |
| 519 | |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 520 | ip->i_inode.i_ctime = CURRENT_TIME; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 521 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 522 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 523 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 524 | brelse(dibh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 525 | mark_inode_dirty(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 526 | |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame] | 527 | if (ip->i_inode.i_nlink == 0) |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 528 | gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */ |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame] | 529 | |
S. Wendy Cheng | 5509826 | 2007-01-18 15:56:34 -0500 | [diff] [blame] | 530 | return error; |
| 531 | } |
| 532 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 533 | struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) |
| 534 | { |
| 535 | struct qstr qstr; |
Russell Cattelan | 6c93fd1 | 2007-01-08 17:47:51 -0600 | [diff] [blame] | 536 | struct inode *inode; |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 537 | gfs2_str2qstr(&qstr, name); |
Al Viro | a569c71 | 2008-07-23 14:42:05 -0400 | [diff] [blame] | 538 | inode = gfs2_lookupi(dip, &qstr, 1); |
Russell Cattelan | 6c93fd1 | 2007-01-08 17:47:51 -0600 | [diff] [blame] | 539 | /* gfs2_lookupi has inconsistent callers: vfs |
| 540 | * related routines expect NULL for no entry found, |
| 541 | * gfs2_lookup_simple callers expect ENOENT |
| 542 | * and do not check for NULL. |
| 543 | */ |
| 544 | if (inode == NULL) |
| 545 | return ERR_PTR(-ENOENT); |
| 546 | else |
| 547 | return inode; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 551 | /** |
| 552 | * gfs2_lookupi - Look up a filename in a directory and return its inode |
| 553 | * @d_gh: An initialized holder for the directory glock |
| 554 | * @name: The name of the inode to look for |
| 555 | * @is_root: If 1, ignore the caller's permissions |
| 556 | * @i_gh: An uninitialized holder for the new inode glock |
| 557 | * |
Steven Whitehouse | d7c103d | 2007-01-25 17:14:59 +0000 | [diff] [blame] | 558 | * This can be called via the VFS filldir function when NFS is doing |
| 559 | * a readdirplus and the inode which its intending to stat isn't |
| 560 | * already in cache. In this case we must not take the directory glock |
| 561 | * again, since the readdir call will have already taken that lock. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 562 | * |
| 563 | * Returns: errno |
| 564 | */ |
| 565 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 566 | struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, |
Al Viro | a569c71 | 2008-07-23 14:42:05 -0400 | [diff] [blame] | 567 | int is_root) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 568 | { |
Steven Whitehouse | c9fd430 | 2006-03-01 15:31:02 -0500 | [diff] [blame] | 569 | struct super_block *sb = dir->i_sb; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 570 | struct gfs2_inode *dip = GFS2_I(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 571 | struct gfs2_holder d_gh; |
akpm@linux-foundation.org | 037bcbb | 2007-06-08 16:42:14 -0700 | [diff] [blame] | 572 | int error = 0; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 573 | struct inode *inode = NULL; |
Steven Whitehouse | d7c103d | 2007-01-25 17:14:59 +0000 | [diff] [blame] | 574 | int unlock = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 575 | |
| 576 | if (!name->len || name->len > GFS2_FNAMESIZE) |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 577 | return ERR_PTR(-ENAMETOOLONG); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 578 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 579 | if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) || |
| 580 | (name->len == 2 && memcmp(name->name, "..", 2) == 0 && |
| 581 | dir == sb->s_root->d_inode)) { |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 582 | igrab(dir); |
| 583 | return dir; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Steven Whitehouse | 7afd88d | 2008-02-22 16:07:18 +0000 | [diff] [blame] | 586 | if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) { |
Steven Whitehouse | d7c103d | 2007-01-25 17:14:59 +0000 | [diff] [blame] | 587 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); |
| 588 | if (error) |
| 589 | return ERR_PTR(error); |
| 590 | unlock = 1; |
| 591 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 592 | |
| 593 | if (!is_root) { |
Miklos Szeredi | f58ba88 | 2008-07-02 21:12:01 +0200 | [diff] [blame] | 594 | error = gfs2_permission(dir, MAY_EXEC); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 595 | if (error) |
| 596 | goto out; |
| 597 | } |
| 598 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 599 | inode = gfs2_dir_search(dir, name); |
| 600 | if (IS_ERR(inode)) |
| 601 | error = PTR_ERR(inode); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 602 | out: |
Steven Whitehouse | d7c103d | 2007-01-25 17:14:59 +0000 | [diff] [blame] | 603 | if (unlock) |
| 604 | gfs2_glock_dq_uninit(&d_gh); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 605 | if (error == -ENOENT) |
| 606 | return NULL; |
Steven Whitehouse | d7c103d | 2007-01-25 17:14:59 +0000 | [diff] [blame] | 607 | return inode ? inode : ERR_PTR(error); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 608 | } |
| 609 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 610 | /** |
| 611 | * create_ok - OK to create a new on-disk inode here? |
| 612 | * @dip: Directory in which dinode is to be created |
| 613 | * @name: Name of new dinode |
| 614 | * @mode: |
| 615 | * |
| 616 | * Returns: errno |
| 617 | */ |
| 618 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 619 | static int create_ok(struct gfs2_inode *dip, const struct qstr *name, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 620 | unsigned int mode) |
| 621 | { |
| 622 | int error; |
| 623 | |
Miklos Szeredi | f58ba88 | 2008-07-02 21:12:01 +0200 | [diff] [blame] | 624 | error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 625 | if (error) |
| 626 | return error; |
| 627 | |
| 628 | /* Don't create entries in an unlinked directory */ |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 629 | if (!dip->i_inode.i_nlink) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 630 | return -EPERM; |
| 631 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 632 | error = gfs2_dir_check(&dip->i_inode, name, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 633 | switch (error) { |
| 634 | case -ENOENT: |
| 635 | error = 0; |
| 636 | break; |
| 637 | case 0: |
| 638 | return -EEXIST; |
| 639 | default: |
| 640 | return error; |
| 641 | } |
| 642 | |
Steven Whitehouse | ad6203f | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 643 | if (dip->i_entries == (u32)-1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 644 | return -EFBIG; |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 645 | if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 646 | return -EMLINK; |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, |
| 652 | unsigned int *uid, unsigned int *gid) |
| 653 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 654 | if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir && |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 655 | (dip->i_inode.i_mode & S_ISUID) && dip->i_inode.i_uid) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 656 | if (S_ISDIR(*mode)) |
| 657 | *mode |= S_ISUID; |
David Howells | 3de7be3 | 2008-11-14 10:38:53 +1100 | [diff] [blame] | 658 | else if (dip->i_inode.i_uid != current_fsuid()) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 659 | *mode &= ~07111; |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 660 | *uid = dip->i_inode.i_uid; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 661 | } else |
David Howells | 3de7be3 | 2008-11-14 10:38:53 +1100 | [diff] [blame] | 662 | *uid = current_fsuid(); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 663 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 664 | if (dip->i_inode.i_mode & S_ISGID) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 665 | if (S_ISDIR(*mode)) |
| 666 | *mode |= S_ISGID; |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 667 | *gid = dip->i_inode.i_gid; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 668 | } else |
David Howells | 3de7be3 | 2008-11-14 10:38:53 +1100 | [diff] [blame] | 669 | *gid = current_fsgid(); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 672 | static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 673 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 674 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 675 | int error; |
| 676 | |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 677 | if (gfs2_alloc_get(dip) == NULL) |
| 678 | return -ENOMEM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 679 | |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 680 | dip->i_alloc->al_requested = RES_DINODE; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 681 | error = gfs2_inplace_reserve(dip); |
| 682 | if (error) |
| 683 | goto out; |
| 684 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 685 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 686 | if (error) |
| 687 | goto out_ipreserv; |
| 688 | |
Steven Whitehouse | 6050b9c | 2009-07-31 16:19:40 +0100 | [diff] [blame] | 689 | error = gfs2_alloc_di(dip, no_addr, generation); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 690 | |
| 691 | gfs2_trans_end(sdp); |
| 692 | |
Steven Whitehouse | 4340fe6 | 2006-07-11 09:46:33 -0400 | [diff] [blame] | 693 | out_ipreserv: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 694 | gfs2_inplace_release(dip); |
Steven Whitehouse | 4340fe6 | 2006-07-11 09:46:33 -0400 | [diff] [blame] | 695 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 696 | gfs2_alloc_put(dip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 697 | return error; |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * init_dinode - Fill in a new dinode structure |
| 702 | * @dip: the directory this inode is being created in |
| 703 | * @gl: The glock covering the new inode |
| 704 | * @inum: the inode number |
| 705 | * @mode: the file permissions |
| 706 | * @uid: |
| 707 | * @gid: |
| 708 | * |
| 709 | */ |
| 710 | |
| 711 | static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, |
Al Viro | 629a21e | 2006-10-13 22:51:24 -0400 | [diff] [blame] | 712 | const struct gfs2_inum_host *inum, unsigned int mode, |
Steven Whitehouse | 4340fe6 | 2006-07-11 09:46:33 -0400 | [diff] [blame] | 713 | unsigned int uid, unsigned int gid, |
Wendy Cheng | e9bd2b3 | 2007-08-24 09:15:01 -0400 | [diff] [blame] | 714 | const u64 *generation, dev_t dev, struct buffer_head **bhp) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 715 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 716 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 717 | struct gfs2_dinode *di; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 718 | struct buffer_head *dibh; |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 719 | struct timespec tv = CURRENT_TIME; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 720 | |
| 721 | dibh = gfs2_meta_new(gl, inum->no_addr); |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 722 | gfs2_trans_add_bh(gl, dibh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 723 | gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI); |
| 724 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 725 | di = (struct gfs2_dinode *)dibh->b_data; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 726 | |
Steven Whitehouse | 2442a09 | 2006-01-30 11:49:32 +0000 | [diff] [blame] | 727 | di->di_num.no_formal_ino = cpu_to_be64(inum->no_formal_ino); |
| 728 | di->di_num.no_addr = cpu_to_be64(inum->no_addr); |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 729 | di->di_mode = cpu_to_be32(mode); |
| 730 | di->di_uid = cpu_to_be32(uid); |
| 731 | di->di_gid = cpu_to_be32(gid); |
Steven Whitehouse | 294caaa | 2006-11-02 11:59:28 -0500 | [diff] [blame] | 732 | di->di_nlink = 0; |
| 733 | di->di_size = 0; |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 734 | di->di_blocks = cpu_to_be64(1); |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 735 | di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(tv.tv_sec); |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 736 | di->di_major = cpu_to_be32(MAJOR(dev)); |
| 737 | di->di_minor = cpu_to_be32(MINOR(dev)); |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 738 | di->di_goal_meta = di->di_goal_data = cpu_to_be64(inum->no_addr); |
Steven Whitehouse | 4340fe6 | 2006-07-11 09:46:33 -0400 | [diff] [blame] | 739 | di->di_generation = cpu_to_be64(*generation); |
Steven Whitehouse | 294caaa | 2006-11-02 11:59:28 -0500 | [diff] [blame] | 740 | di->di_flags = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 741 | |
| 742 | if (S_ISREG(mode)) { |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 743 | if ((dip->i_diskflags & GFS2_DIF_INHERIT_JDATA) || |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 744 | gfs2_tune_get(sdp, gt_new_files_jdata)) |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 745 | di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 746 | } else if (S_ISDIR(mode)) { |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 747 | di->di_flags |= cpu_to_be32(dip->i_diskflags & |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 748 | GFS2_DIF_INHERIT_JDATA); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 751 | di->__pad1 = 0; |
Steven Whitehouse | a9583c7 | 2006-11-01 20:09:14 -0500 | [diff] [blame] | 752 | di->di_payload_format = cpu_to_be32(S_ISDIR(mode) ? GFS2_FORMAT_DE : 0); |
Steven Whitehouse | 294caaa | 2006-11-02 11:59:28 -0500 | [diff] [blame] | 753 | di->di_height = 0; |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 754 | di->__pad2 = 0; |
| 755 | di->__pad3 = 0; |
Steven Whitehouse | 294caaa | 2006-11-02 11:59:28 -0500 | [diff] [blame] | 756 | di->di_depth = 0; |
| 757 | di->di_entries = 0; |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 758 | memset(&di->__pad4, 0, sizeof(di->__pad4)); |
Steven Whitehouse | 294caaa | 2006-11-02 11:59:28 -0500 | [diff] [blame] | 759 | di->di_eattr = 0; |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 760 | di->di_atime_nsec = cpu_to_be32(tv.tv_nsec); |
| 761 | di->di_mtime_nsec = cpu_to_be32(tv.tv_nsec); |
| 762 | di->di_ctime_nsec = cpu_to_be32(tv.tv_nsec); |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 763 | memset(&di->di_reserved, 0, sizeof(di->di_reserved)); |
Wendy Cheng | e9bd2b3 | 2007-08-24 09:15:01 -0400 | [diff] [blame] | 764 | |
| 765 | set_buffer_uptodate(dibh); |
Steven Whitehouse | b96ca4f | 2006-01-18 10:57:10 +0000 | [diff] [blame] | 766 | |
Wendy Cheng | e9bd2b3 | 2007-08-24 09:15:01 -0400 | [diff] [blame] | 767 | *bhp = dibh; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, |
Al Viro | 629a21e | 2006-10-13 22:51:24 -0400 | [diff] [blame] | 771 | unsigned int mode, const struct gfs2_inum_host *inum, |
Wendy Cheng | e9bd2b3 | 2007-08-24 09:15:01 -0400 | [diff] [blame] | 772 | const u64 *generation, dev_t dev, struct buffer_head **bhp) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 773 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 774 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 775 | unsigned int uid, gid; |
| 776 | int error; |
| 777 | |
| 778 | munge_mode_uid_gid(dip, &mode, &uid, &gid); |
Cyrill Gorcunov | 182fe5a | 2008-03-03 21:54:21 +0300 | [diff] [blame] | 779 | if (!gfs2_alloc_get(dip)) |
| 780 | return -ENOMEM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 781 | |
| 782 | error = gfs2_quota_lock(dip, uid, gid); |
| 783 | if (error) |
| 784 | goto out; |
| 785 | |
| 786 | error = gfs2_quota_check(dip, uid, gid); |
| 787 | if (error) |
| 788 | goto out_quota; |
| 789 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 790 | error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 791 | if (error) |
| 792 | goto out_quota; |
| 793 | |
Wendy Cheng | e9bd2b3 | 2007-08-24 09:15:01 -0400 | [diff] [blame] | 794 | init_dinode(dip, gl, inum, mode, uid, gid, generation, dev, bhp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 795 | gfs2_quota_change(dip, +1, uid, gid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 796 | gfs2_trans_end(sdp); |
| 797 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 798 | out_quota: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 799 | gfs2_quota_unlock(dip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 800 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 801 | gfs2_alloc_put(dip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 802 | return error; |
| 803 | } |
| 804 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 805 | static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, |
| 806 | struct gfs2_inode *ip) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 807 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 808 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 809 | struct gfs2_alloc *al; |
| 810 | int alloc_required; |
| 811 | struct buffer_head *dibh; |
| 812 | int error; |
| 813 | |
| 814 | al = gfs2_alloc_get(dip); |
Cyrill Gorcunov | 182fe5a | 2008-03-03 21:54:21 +0300 | [diff] [blame] | 815 | if (!al) |
| 816 | return -ENOMEM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 817 | |
| 818 | error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
| 819 | if (error) |
| 820 | goto fail; |
| 821 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 822 | error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 823 | if (alloc_required < 0) |
Bob Peterson | 1b8177e | 2008-01-19 21:50:24 -0600 | [diff] [blame] | 824 | goto fail_quota_locks; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 825 | if (alloc_required) { |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 826 | error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 827 | if (error) |
| 828 | goto fail_quota_locks; |
| 829 | |
| 830 | al->al_requested = sdp->sd_max_dirres; |
| 831 | |
| 832 | error = gfs2_inplace_reserve(dip); |
| 833 | if (error) |
| 834 | goto fail_quota_locks; |
| 835 | |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 836 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 837 | al->al_rgd->rd_length + |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 838 | 2 * RES_DINODE + |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 839 | RES_STATFS + RES_QUOTA, 0); |
| 840 | if (error) |
| 841 | goto fail_ipreserv; |
| 842 | } else { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 843 | error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 844 | if (error) |
| 845 | goto fail_quota_locks; |
| 846 | } |
| 847 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 848 | error = gfs2_dir_add(&dip->i_inode, name, ip, IF2DT(ip->i_inode.i_mode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 849 | if (error) |
| 850 | goto fail_end_trans; |
| 851 | |
| 852 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 853 | if (error) |
| 854 | goto fail_end_trans; |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 855 | ip->i_inode.i_nlink = 1; |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 856 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 857 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 858 | brelse(dibh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 859 | return 0; |
| 860 | |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 861 | fail_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 862 | gfs2_trans_end(sdp); |
| 863 | |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 864 | fail_ipreserv: |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 865 | if (dip->i_alloc->al_rgd) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 866 | gfs2_inplace_release(dip); |
| 867 | |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 868 | fail_quota_locks: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 869 | gfs2_quota_unlock(dip); |
| 870 | |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 871 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 872 | gfs2_alloc_put(dip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 873 | return error; |
| 874 | } |
| 875 | |
Ryan O'Hara | fcb47e0 | 2006-10-03 11:57:35 -0400 | [diff] [blame] | 876 | static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip) |
| 877 | { |
| 878 | int err; |
| 879 | size_t len; |
| 880 | void *value; |
| 881 | char *name; |
Ryan O'Hara | fcb47e0 | 2006-10-03 11:57:35 -0400 | [diff] [blame] | 882 | |
| 883 | err = security_inode_init_security(&ip->i_inode, &dip->i_inode, |
| 884 | &name, &value, &len); |
| 885 | |
| 886 | if (err) { |
| 887 | if (err == -EOPNOTSUPP) |
| 888 | return 0; |
| 889 | return err; |
| 890 | } |
| 891 | |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 892 | err = __gfs2_xattr_set(&ip->i_inode, name, value, len, 0, |
| 893 | GFS2_EATYPE_SECURITY); |
Ryan O'Hara | fcb47e0 | 2006-10-03 11:57:35 -0400 | [diff] [blame] | 894 | kfree(value); |
| 895 | kfree(name); |
| 896 | |
| 897 | return err; |
| 898 | } |
| 899 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 900 | /** |
| 901 | * gfs2_createi - Create a new inode |
| 902 | * @ghs: An array of two holders |
| 903 | * @name: The name of the new file |
| 904 | * @mode: the permissions on the new inode |
| 905 | * |
| 906 | * @ghs[0] is an initialized holder for the directory |
| 907 | * @ghs[1] is the holder for the inode lock |
| 908 | * |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 909 | * If the return value is not NULL, the glocks on both the directory and the new |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 910 | * file are held. A transaction has been started and an inplace reservation |
| 911 | * is held, as well. |
| 912 | * |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 913 | * Returns: An inode |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 914 | */ |
| 915 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 916 | struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 917 | unsigned int mode, dev_t dev) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 918 | { |
Steven Whitehouse | e1cc860 | 2007-06-07 11:47:52 +0100 | [diff] [blame] | 919 | struct inode *inode = NULL; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 920 | struct gfs2_inode *dip = ghs->gh_gl->gl_object; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 921 | struct inode *dir = &dip->i_inode; |
| 922 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 923 | struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 }; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 924 | int error; |
Steven Whitehouse | 4340fe6 | 2006-07-11 09:46:33 -0400 | [diff] [blame] | 925 | u64 generation; |
Steven Whitehouse | f91a0d3 | 2007-10-15 16:29:05 +0100 | [diff] [blame] | 926 | struct buffer_head *bh = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 927 | |
| 928 | if (!name->len || name->len > GFS2_FNAMESIZE) |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 929 | return ERR_PTR(-ENAMETOOLONG); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 930 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 931 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); |
| 932 | error = gfs2_glock_nq(ghs); |
| 933 | if (error) |
| 934 | goto fail; |
| 935 | |
| 936 | error = create_ok(dip, name, mode); |
| 937 | if (error) |
| 938 | goto fail_gunlock; |
| 939 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 940 | error = alloc_dinode(dip, &inum.no_addr, &generation); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 941 | if (error) |
| 942 | goto fail_gunlock; |
Steven Whitehouse | 8d8291a | 2009-08-27 15:51:07 +0100 | [diff] [blame] | 943 | inum.no_formal_ino = generation; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 944 | |
Steven Whitehouse | 28626e2 | 2006-11-22 11:13:21 -0500 | [diff] [blame] | 945 | error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops, |
| 946 | LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1); |
| 947 | if (error) |
| 948 | goto fail_gunlock; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 949 | |
Wendy Cheng | e9bd2b3 | 2007-08-24 09:15:01 -0400 | [diff] [blame] | 950 | error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation, dev, &bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 951 | if (error) |
| 952 | goto fail_gunlock2; |
| 953 | |
Steven Whitehouse | 8d8291a | 2009-08-27 15:51:07 +0100 | [diff] [blame] | 954 | inode = gfs2_inode_lookup(dir->i_sb, IF2DT(mode), inum.no_addr, |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 955 | inum.no_formal_ino); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 956 | if (IS_ERR(inode)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 957 | goto fail_gunlock2; |
| 958 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 959 | error = gfs2_inode_refresh(GFS2_I(inode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 960 | if (error) |
Steven Whitehouse | e1cc860 | 2007-06-07 11:47:52 +0100 | [diff] [blame] | 961 | goto fail_gunlock2; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 962 | |
Steven Whitehouse | 479c427 | 2009-10-02 12:00:00 +0100 | [diff] [blame] | 963 | error = gfs2_acl_create(dip, inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 964 | if (error) |
Steven Whitehouse | e1cc860 | 2007-06-07 11:47:52 +0100 | [diff] [blame] | 965 | goto fail_gunlock2; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 966 | |
Ryan O'Hara | fcb47e0 | 2006-10-03 11:57:35 -0400 | [diff] [blame] | 967 | error = gfs2_security_init(dip, GFS2_I(inode)); |
| 968 | if (error) |
Steven Whitehouse | e1cc860 | 2007-06-07 11:47:52 +0100 | [diff] [blame] | 969 | goto fail_gunlock2; |
Ryan O'Hara | fcb47e0 | 2006-10-03 11:57:35 -0400 | [diff] [blame] | 970 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 971 | error = link_dinode(dip, name, GFS2_I(inode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 972 | if (error) |
Steven Whitehouse | e1cc860 | 2007-06-07 11:47:52 +0100 | [diff] [blame] | 973 | goto fail_gunlock2; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 974 | |
Steven Whitehouse | f91a0d3 | 2007-10-15 16:29:05 +0100 | [diff] [blame] | 975 | if (bh) |
| 976 | brelse(bh); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 977 | return inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 978 | |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 979 | fail_gunlock2: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 980 | gfs2_glock_dq_uninit(ghs + 1); |
Julien Brunel | bd1eb88 | 2008-09-01 10:51:22 +0200 | [diff] [blame] | 981 | if (inode && !IS_ERR(inode)) |
Steven Whitehouse | e1cc860 | 2007-06-07 11:47:52 +0100 | [diff] [blame] | 982 | iput(inode); |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 983 | fail_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 984 | gfs2_glock_dq(ghs); |
Steven Whitehouse | 320dd10 | 2006-05-18 16:25:27 -0400 | [diff] [blame] | 985 | fail: |
Steven Whitehouse | f91a0d3 | 2007-10-15 16:29:05 +0100 | [diff] [blame] | 986 | if (bh) |
| 987 | brelse(bh); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 988 | return ERR_PTR(error); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Steven Whitehouse | 536baf0 | 2009-05-22 10:48:59 +0100 | [diff] [blame] | 991 | static int __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 992 | { |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 993 | struct inode *inode = &ip->i_inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 994 | struct buffer_head *dibh; |
| 995 | int error; |
| 996 | |
| 997 | error = gfs2_meta_inode_buffer(ip, &dibh); |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 998 | if (error) |
| 999 | return error; |
| 1000 | |
| 1001 | if ((attr->ia_valid & ATTR_SIZE) && |
| 1002 | attr->ia_size != i_size_read(inode)) { |
| 1003 | error = vmtruncate(inode, attr->ia_size); |
| 1004 | if (error) |
| 1005 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1006 | } |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 1007 | |
| 1008 | setattr_copy(inode, attr); |
| 1009 | mark_inode_dirty(inode); |
| 1010 | |
| 1011 | gfs2_assert_warn(GFS2_SB(inode), !error); |
| 1012 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
| 1013 | gfs2_dinode_out(ip, dibh->b_data); |
| 1014 | brelse(dibh); |
| 1015 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * gfs2_setattr_simple - |
| 1020 | * @ip: |
| 1021 | * @attr: |
| 1022 | * |
| 1023 | * Called with a reference on the vnode. |
| 1024 | * |
| 1025 | * Returns: errno |
| 1026 | */ |
| 1027 | |
| 1028 | int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) |
| 1029 | { |
| 1030 | int error; |
| 1031 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 1032 | if (current->journal_info) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1033 | return __gfs2_setattr_simple(ip, attr); |
| 1034 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1035 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1036 | if (error) |
| 1037 | return error; |
| 1038 | |
| 1039 | error = __gfs2_setattr_simple(ip, attr); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1040 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1041 | return error; |
| 1042 | } |
| 1043 | |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1044 | void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf) |
| 1045 | { |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1046 | struct gfs2_dinode *str = buf; |
| 1047 | |
| 1048 | str->di_header.mh_magic = cpu_to_be32(GFS2_MAGIC); |
| 1049 | str->di_header.mh_type = cpu_to_be32(GFS2_METATYPE_DI); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1050 | str->di_header.mh_format = cpu_to_be32(GFS2_FORMAT_DI); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1051 | str->di_num.no_addr = cpu_to_be64(ip->i_no_addr); |
| 1052 | str->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino); |
| 1053 | str->di_mode = cpu_to_be32(ip->i_inode.i_mode); |
| 1054 | str->di_uid = cpu_to_be32(ip->i_inode.i_uid); |
| 1055 | str->di_gid = cpu_to_be32(ip->i_inode.i_gid); |
| 1056 | str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink); |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 1057 | str->di_size = cpu_to_be64(i_size_read(&ip->i_inode)); |
Steven Whitehouse | 77658aa | 2008-02-12 14:17:27 +0000 | [diff] [blame] | 1058 | str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode)); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1059 | str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec); |
| 1060 | str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec); |
| 1061 | str->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec); |
| 1062 | |
Steven Whitehouse | ce276b0 | 2008-02-06 09:25:45 +0000 | [diff] [blame] | 1063 | str->di_goal_meta = cpu_to_be64(ip->i_goal); |
| 1064 | str->di_goal_data = cpu_to_be64(ip->i_goal); |
Steven Whitehouse | bcf0b5b | 2008-11-03 13:39:46 +0000 | [diff] [blame] | 1065 | str->di_generation = cpu_to_be64(ip->i_generation); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1066 | |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 1067 | str->di_flags = cpu_to_be32(ip->i_diskflags); |
Steven Whitehouse | ecc30c7 | 2008-01-28 10:37:35 +0000 | [diff] [blame] | 1068 | str->di_height = cpu_to_be16(ip->i_height); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1069 | str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) && |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 1070 | !(ip->i_diskflags & GFS2_DIF_EXHASH) ? |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1071 | GFS2_FORMAT_DE : 0); |
Steven Whitehouse | 9a00450 | 2008-02-01 09:23:44 +0000 | [diff] [blame] | 1072 | str->di_depth = cpu_to_be16(ip->i_depth); |
Steven Whitehouse | ad6203f | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 1073 | str->di_entries = cpu_to_be32(ip->i_entries); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1074 | |
Steven Whitehouse | 3767ac2 | 2008-11-03 14:28:42 +0000 | [diff] [blame] | 1075 | str->di_eattr = cpu_to_be64(ip->i_eattr); |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 1076 | str->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec); |
| 1077 | str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec); |
| 1078 | str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | void gfs2_dinode_print(const struct gfs2_inode *ip) |
| 1082 | { |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1083 | printk(KERN_INFO " no_formal_ino = %llu\n", |
| 1084 | (unsigned long long)ip->i_no_formal_ino); |
| 1085 | printk(KERN_INFO " no_addr = %llu\n", |
| 1086 | (unsigned long long)ip->i_no_addr); |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 1087 | printk(KERN_INFO " i_size = %llu\n", |
| 1088 | (unsigned long long)i_size_read(&ip->i_inode)); |
Steven Whitehouse | 77658aa | 2008-02-12 14:17:27 +0000 | [diff] [blame] | 1089 | printk(KERN_INFO " blocks = %llu\n", |
| 1090 | (unsigned long long)gfs2_get_inode_blocks(&ip->i_inode)); |
Steven Whitehouse | ce276b0 | 2008-02-06 09:25:45 +0000 | [diff] [blame] | 1091 | printk(KERN_INFO " i_goal = %llu\n", |
| 1092 | (unsigned long long)ip->i_goal); |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 1093 | printk(KERN_INFO " i_diskflags = 0x%.8X\n", ip->i_diskflags); |
Bob Peterson | ca39060 | 2008-01-28 11:15:57 -0600 | [diff] [blame] | 1094 | printk(KERN_INFO " i_height = %u\n", ip->i_height); |
Steven Whitehouse | 9a00450 | 2008-02-01 09:23:44 +0000 | [diff] [blame] | 1095 | printk(KERN_INFO " i_depth = %u\n", ip->i_depth); |
Steven Whitehouse | ad6203f | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 1096 | printk(KERN_INFO " i_entries = %u\n", ip->i_entries); |
Steven Whitehouse | 3767ac2 | 2008-11-03 14:28:42 +0000 | [diff] [blame] | 1097 | printk(KERN_INFO " i_eattr = %llu\n", |
| 1098 | (unsigned long long)ip->i_eattr); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1099 | } |
| 1100 | |