Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- |
| 2 | * vim: noexpandtab sw=8 ts=8 sts=0: |
| 3 | * |
| 4 | * namei.c |
| 5 | * |
| 6 | * Create and rename file, directory, symlinks |
| 7 | * |
| 8 | * Copyright (C) 2002, 2004 Oracle. All rights reserved. |
| 9 | * |
| 10 | * Portions of this code from linux/fs/ext3/dir.c |
| 11 | * |
| 12 | * Copyright (C) 1992, 1993, 1994, 1995 |
| 13 | * Remy Card (card@masi.ibp.fr) |
| 14 | * Laboratoire MASI - Institut Blaise pascal |
| 15 | * Universite Pierre et Marie Curie (Paris VI) |
| 16 | * |
| 17 | * from |
| 18 | * |
| 19 | * linux/fs/minix/dir.c |
| 20 | * |
| 21 | * Copyright (C) 1991, 1992 Linux Torvalds |
| 22 | * |
| 23 | * This program is free software; you can redistribute it and/or |
| 24 | * modify it under the terms of the GNU General Public |
| 25 | * License as published by the Free Software Foundation; either |
| 26 | * version 2 of the License, or (at your option) any later version. |
| 27 | * |
| 28 | * This program is distributed in the hope that it will be useful, |
| 29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 31 | * General Public License for more details. |
| 32 | * |
| 33 | * You should have received a copy of the GNU General Public |
| 34 | * License along with this program; if not, write to the |
| 35 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 36 | * Boston, MA 021110-1307, USA. |
| 37 | */ |
| 38 | |
| 39 | #include <linux/fs.h> |
| 40 | #include <linux/types.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/highmem.h> |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 43 | #include <linux/quotaops.h> |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 44 | |
| 45 | #define MLOG_MASK_PREFIX ML_NAMEI |
| 46 | #include <cluster/masklog.h> |
| 47 | |
| 48 | #include "ocfs2.h" |
| 49 | |
| 50 | #include "alloc.h" |
| 51 | #include "dcache.h" |
| 52 | #include "dir.h" |
| 53 | #include "dlmglue.h" |
| 54 | #include "extent_map.h" |
| 55 | #include "file.h" |
| 56 | #include "inode.h" |
| 57 | #include "journal.h" |
| 58 | #include "namei.h" |
| 59 | #include "suballoc.h" |
Mark Fasheh | aa95887 | 2006-04-21 13:49:02 -0700 | [diff] [blame] | 60 | #include "super.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 61 | #include "symlink.h" |
| 62 | #include "sysfile.h" |
| 63 | #include "uptodate.h" |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 64 | #include "xattr.h" |
Tiger Yang | 89c38bd | 2008-11-14 11:17:41 +0800 | [diff] [blame] | 65 | #include "acl.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 66 | |
| 67 | #include "buffer_head_io.h" |
| 68 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 69 | static int ocfs2_mknod_locked(struct ocfs2_super *osb, |
| 70 | struct inode *dir, |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 71 | struct inode *inode, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 72 | dev_t dev, |
| 73 | struct buffer_head **new_fe_bh, |
| 74 | struct buffer_head *parent_fe_bh, |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 75 | handle_t *handle, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 76 | struct ocfs2_alloc_context *inode_ac); |
| 77 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 78 | static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb, |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 79 | struct inode **ret_orphan_dir, |
Tao Ma | 19bd341 | 2009-08-18 11:44:10 +0800 | [diff] [blame] | 80 | u64 blkno, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 81 | char *name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 82 | struct ocfs2_dir_lookup_result *lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 83 | |
| 84 | static int ocfs2_orphan_add(struct ocfs2_super *osb, |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 85 | handle_t *handle, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 86 | struct inode *inode, |
| 87 | struct ocfs2_dinode *fe, |
| 88 | char *name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 89 | struct ocfs2_dir_lookup_result *lookup, |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 90 | struct inode *orphan_dir_inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 91 | |
| 92 | static int ocfs2_create_symlink_data(struct ocfs2_super *osb, |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 93 | handle_t *handle, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 94 | struct inode *inode, |
| 95 | const char *symname); |
| 96 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 97 | /* An orphan dir name is an 8 byte value, printed as a hex string */ |
| 98 | #define OCFS2_ORPHAN_NAMELEN ((int)(2 * sizeof(u64))) |
| 99 | |
| 100 | static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry, |
| 101 | struct nameidata *nd) |
| 102 | { |
| 103 | int status; |
| 104 | u64 blkno; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 105 | struct inode *inode = NULL; |
| 106 | struct dentry *ret; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 107 | struct ocfs2_inode_info *oi; |
| 108 | |
| 109 | mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry, |
| 110 | dentry->d_name.len, dentry->d_name.name); |
| 111 | |
| 112 | if (dentry->d_name.len > OCFS2_MAX_FILENAME_LEN) { |
| 113 | ret = ERR_PTR(-ENAMETOOLONG); |
| 114 | goto bail; |
| 115 | } |
| 116 | |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 117 | mlog(0, "find name %.*s in directory %llu\n", dentry->d_name.len, |
| 118 | dentry->d_name.name, (unsigned long long)OCFS2_I(dir)->ip_blkno); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 119 | |
Jan Kara | cb25797 | 2009-06-04 15:26:50 +0200 | [diff] [blame] | 120 | status = ocfs2_inode_lock_nested(dir, NULL, 0, OI_LS_PARENT); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 121 | if (status < 0) { |
| 122 | if (status != -ENOENT) |
| 123 | mlog_errno(status); |
| 124 | ret = ERR_PTR(status); |
| 125 | goto bail; |
| 126 | } |
| 127 | |
Mark Fasheh | be94d11 | 2007-09-11 15:22:06 -0700 | [diff] [blame] | 128 | status = ocfs2_lookup_ino_from_name(dir, dentry->d_name.name, |
| 129 | dentry->d_name.len, &blkno); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 130 | if (status < 0) |
| 131 | goto bail_add; |
| 132 | |
Jan Kara | 5fa0613 | 2008-01-11 00:11:45 +0100 | [diff] [blame] | 133 | inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 134 | if (IS_ERR(inode)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 135 | ret = ERR_PTR(-EACCES); |
| 136 | goto bail_unlock; |
| 137 | } |
| 138 | |
| 139 | oi = OCFS2_I(inode); |
| 140 | /* Clear any orphaned state... If we were able to look up the |
| 141 | * inode from a directory, it certainly can't be orphaned. We |
| 142 | * might have the bad state from a node which intended to |
| 143 | * orphan this inode but crashed before it could commit the |
| 144 | * unlink. */ |
| 145 | spin_lock(&oi->ip_lock); |
| 146 | oi->ip_flags &= ~OCFS2_INODE_MAYBE_ORPHANED; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 147 | spin_unlock(&oi->ip_lock); |
| 148 | |
| 149 | bail_add: |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 150 | dentry->d_op = &ocfs2_dentry_ops; |
| 151 | ret = d_splice_alias(inode, dentry); |
| 152 | |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 153 | if (inode) { |
| 154 | /* |
| 155 | * If d_splice_alias() finds a DCACHE_DISCONNECTED |
| 156 | * dentry, it will d_move() it on top of ourse. The |
| 157 | * return value will indicate this however, so in |
| 158 | * those cases, we switch them around for the locking |
| 159 | * code. |
| 160 | * |
| 161 | * NOTE: This dentry already has ->d_op set from |
| 162 | * ocfs2_get_parent() and ocfs2_get_dentry() |
| 163 | */ |
| 164 | if (ret) |
| 165 | dentry = ret; |
| 166 | |
| 167 | status = ocfs2_dentry_attach_lock(dentry, inode, |
Mark Fasheh | 0027dd5 | 2006-09-21 16:51:28 -0700 | [diff] [blame] | 168 | OCFS2_I(dir)->ip_blkno); |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 169 | if (status) { |
| 170 | mlog_errno(status); |
| 171 | ret = ERR_PTR(status); |
| 172 | goto bail_unlock; |
| 173 | } |
| 174 | } |
| 175 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 176 | bail_unlock: |
| 177 | /* Don't drop the cluster lock until *after* the d_add -- |
| 178 | * unlink on another node will message us to remove that |
| 179 | * dentry under this lock so otherwise we can race this with |
Mark Fasheh | 34d024f | 2007-09-24 15:56:19 -0700 | [diff] [blame] | 180 | * the downconvert thread and have a stale dentry. */ |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 181 | ocfs2_inode_unlock(dir, 0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 182 | |
| 183 | bail: |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 184 | |
| 185 | mlog_exit_ptr(ret); |
| 186 | |
| 187 | return ret; |
| 188 | } |
| 189 | |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 190 | static struct inode *ocfs2_get_init_inode(struct inode *dir, int mode) |
| 191 | { |
| 192 | struct inode *inode; |
| 193 | |
| 194 | inode = new_inode(dir->i_sb); |
| 195 | if (!inode) { |
| 196 | mlog(ML_ERROR, "new_inode failed!\n"); |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | /* populate as many fields early on as possible - many of |
| 201 | * these are used by the support functions here and in |
| 202 | * callers. */ |
| 203 | if (S_ISDIR(mode)) |
| 204 | inode->i_nlink = 2; |
| 205 | else |
| 206 | inode->i_nlink = 1; |
| 207 | inode->i_uid = current_fsuid(); |
| 208 | if (dir->i_mode & S_ISGID) { |
| 209 | inode->i_gid = dir->i_gid; |
| 210 | if (S_ISDIR(mode)) |
| 211 | mode |= S_ISGID; |
| 212 | } else |
| 213 | inode->i_gid = current_fsgid(); |
| 214 | inode->i_mode = mode; |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 215 | dquot_initialize(inode); |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 216 | return inode; |
| 217 | } |
| 218 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 219 | static int ocfs2_mknod(struct inode *dir, |
| 220 | struct dentry *dentry, |
| 221 | int mode, |
| 222 | dev_t dev) |
| 223 | { |
| 224 | int status = 0; |
| 225 | struct buffer_head *parent_fe_bh = NULL; |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 226 | handle_t *handle = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 227 | struct ocfs2_super *osb; |
| 228 | struct ocfs2_dinode *dirfe; |
| 229 | struct buffer_head *new_fe_bh = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 230 | struct inode *inode = NULL; |
| 231 | struct ocfs2_alloc_context *inode_ac = NULL; |
| 232 | struct ocfs2_alloc_context *data_ac = NULL; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 233 | struct ocfs2_alloc_context *meta_ac = NULL; |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 234 | int want_clusters = 0; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 235 | int want_meta = 0; |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 236 | int xattr_credits = 0; |
| 237 | struct ocfs2_security_xattr_info si = { |
| 238 | .enable = 1, |
| 239 | }; |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 240 | int did_quota_inode = 0; |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 241 | struct ocfs2_dir_lookup_result lookup = { NULL, }; |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 242 | sigset_t oldset; |
| 243 | int did_block_signals = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 244 | |
| 245 | mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode, |
| 246 | (unsigned long)dev, dentry->d_name.len, |
| 247 | dentry->d_name.name); |
| 248 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 249 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 250 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 251 | /* get our super block */ |
| 252 | osb = OCFS2_SB(dir->i_sb); |
| 253 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 254 | status = ocfs2_inode_lock(dir, &parent_fe_bh, 1); |
Mark Fasheh | e3a8213 | 2006-10-05 16:04:17 -0700 | [diff] [blame] | 255 | if (status < 0) { |
| 256 | if (status != -ENOENT) |
| 257 | mlog_errno(status); |
| 258 | return status; |
| 259 | } |
| 260 | |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 261 | if (S_ISDIR(mode) && (dir->i_nlink >= ocfs2_link_max(osb))) { |
Mark Fasheh | a663e30 | 2006-08-09 11:45:07 -0700 | [diff] [blame] | 262 | status = -EMLINK; |
| 263 | goto leave; |
| 264 | } |
| 265 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 266 | dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data; |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 267 | if (!ocfs2_read_links_count(dirfe)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 268 | /* can't make a file in a deleted directory. */ |
| 269 | status = -ENOENT; |
| 270 | goto leave; |
| 271 | } |
| 272 | |
| 273 | status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name, |
| 274 | dentry->d_name.len); |
| 275 | if (status) |
| 276 | goto leave; |
| 277 | |
| 278 | /* get a spot inside the dir. */ |
| 279 | status = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh, |
| 280 | dentry->d_name.name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 281 | dentry->d_name.len, &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 282 | if (status < 0) { |
| 283 | mlog_errno(status); |
| 284 | goto leave; |
| 285 | } |
| 286 | |
| 287 | /* reserve an inode spot */ |
Mark Fasheh | da5cbf2 | 2006-10-06 18:34:35 -0700 | [diff] [blame] | 288 | status = ocfs2_reserve_new_inode(osb, &inode_ac); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 289 | if (status < 0) { |
| 290 | if (status != -ENOSPC) |
| 291 | mlog_errno(status); |
| 292 | goto leave; |
| 293 | } |
| 294 | |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 295 | inode = ocfs2_get_init_inode(dir, mode); |
| 296 | if (!inode) { |
| 297 | status = -ENOMEM; |
| 298 | mlog_errno(status); |
| 299 | goto leave; |
| 300 | } |
| 301 | |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 302 | /* get security xattr */ |
| 303 | status = ocfs2_init_security_get(inode, dir, &si); |
| 304 | if (status) { |
| 305 | if (status == -EOPNOTSUPP) |
| 306 | si.enable = 0; |
| 307 | else { |
| 308 | mlog_errno(status); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 309 | goto leave; |
| 310 | } |
| 311 | } |
| 312 | |
Tiger Yang | 89c38bd | 2008-11-14 11:17:41 +0800 | [diff] [blame] | 313 | /* calculate meta data/clusters for setting security and acl xattr */ |
| 314 | status = ocfs2_calc_xattr_init(dir, parent_fe_bh, mode, |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 315 | &si, &want_clusters, |
| 316 | &xattr_credits, &want_meta); |
Tiger Yang | 89c38bd | 2008-11-14 11:17:41 +0800 | [diff] [blame] | 317 | if (status < 0) { |
| 318 | mlog_errno(status); |
| 319 | goto leave; |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /* Reserve a cluster if creating an extent based directory. */ |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 323 | if (S_ISDIR(mode) && !ocfs2_supports_inline_data(osb)) { |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 324 | want_clusters += 1; |
| 325 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 326 | /* Dir indexing requires extra space as well */ |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 327 | if (ocfs2_supports_indexed_dirs(osb)) |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 328 | want_meta++; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | status = ocfs2_reserve_new_metadata_blocks(osb, want_meta, &meta_ac); |
| 332 | if (status < 0) { |
| 333 | if (status != -ENOSPC) |
| 334 | mlog_errno(status); |
| 335 | goto leave; |
| 336 | } |
| 337 | |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 338 | status = ocfs2_reserve_clusters(osb, want_clusters, &data_ac); |
| 339 | if (status < 0) { |
| 340 | if (status != -ENOSPC) |
| 341 | mlog_errno(status); |
| 342 | goto leave; |
| 343 | } |
| 344 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 345 | handle = ocfs2_start_trans(osb, ocfs2_mknod_credits(osb->sb, |
| 346 | S_ISDIR(mode), |
| 347 | xattr_credits)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 348 | if (IS_ERR(handle)) { |
| 349 | status = PTR_ERR(handle); |
| 350 | handle = NULL; |
| 351 | mlog_errno(status); |
| 352 | goto leave; |
| 353 | } |
| 354 | |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 355 | /* Starting to change things, restart is no longer possible. */ |
| 356 | ocfs2_block_signals(&oldset); |
| 357 | did_block_signals = 1; |
| 358 | |
Christoph Hellwig | 63936dd | 2010-03-03 09:05:01 -0500 | [diff] [blame] | 359 | status = dquot_alloc_inode(inode); |
| 360 | if (status) |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 361 | goto leave; |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 362 | did_quota_inode = 1; |
| 363 | |
Tao Ma | 19bd341 | 2009-08-18 11:44:10 +0800 | [diff] [blame] | 364 | mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, |
| 365 | inode->i_mode, (unsigned long)dev, dentry->d_name.len, |
| 366 | dentry->d_name.name); |
| 367 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 368 | /* do the real work now. */ |
Tao Ma | 19bd341 | 2009-08-18 11:44:10 +0800 | [diff] [blame] | 369 | status = ocfs2_mknod_locked(osb, dir, inode, dev, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 370 | &new_fe_bh, parent_fe_bh, handle, |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 371 | inode_ac); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 372 | if (status < 0) { |
| 373 | mlog_errno(status); |
| 374 | goto leave; |
| 375 | } |
| 376 | |
| 377 | if (S_ISDIR(mode)) { |
| 378 | status = ocfs2_fill_new_dir(osb, handle, dir, inode, |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 379 | new_fe_bh, data_ac, meta_ac); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 380 | if (status < 0) { |
| 381 | mlog_errno(status); |
| 382 | goto leave; |
| 383 | } |
| 384 | |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 385 | status = ocfs2_journal_access_di(handle, INODE_CACHE(dir), |
| 386 | parent_fe_bh, |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 387 | OCFS2_JOURNAL_ACCESS_WRITE); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 388 | if (status < 0) { |
| 389 | mlog_errno(status); |
| 390 | goto leave; |
| 391 | } |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 392 | ocfs2_add_links_count(dirfe, 1); |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 393 | ocfs2_journal_dirty(handle, parent_fe_bh); |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 394 | inc_nlink(dir); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Tiger Yang | 89c38bd | 2008-11-14 11:17:41 +0800 | [diff] [blame] | 397 | status = ocfs2_init_acl(handle, inode, dir, new_fe_bh, parent_fe_bh, |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 398 | meta_ac, data_ac); |
Tiger Yang | 89c38bd | 2008-11-14 11:17:41 +0800 | [diff] [blame] | 399 | if (status < 0) { |
| 400 | mlog_errno(status); |
| 401 | goto leave; |
| 402 | } |
| 403 | |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 404 | if (si.enable) { |
| 405 | status = ocfs2_init_security_set(handle, inode, new_fe_bh, &si, |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 406 | meta_ac, data_ac); |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 407 | if (status < 0) { |
| 408 | mlog_errno(status); |
| 409 | goto leave; |
| 410 | } |
| 411 | } |
| 412 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 413 | status = ocfs2_add_entry(handle, dentry, inode, |
| 414 | OCFS2_I(inode)->ip_blkno, parent_fe_bh, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 415 | &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 416 | if (status < 0) { |
| 417 | mlog_errno(status); |
| 418 | goto leave; |
| 419 | } |
| 420 | |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 421 | status = ocfs2_dentry_attach_lock(dentry, inode, |
Mark Fasheh | 0027dd5 | 2006-09-21 16:51:28 -0700 | [diff] [blame] | 422 | OCFS2_I(dir)->ip_blkno); |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 423 | if (status) { |
| 424 | mlog_errno(status); |
| 425 | goto leave; |
| 426 | } |
| 427 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 428 | insert_inode_hash(inode); |
| 429 | dentry->d_op = &ocfs2_dentry_ops; |
| 430 | d_instantiate(dentry, inode); |
| 431 | status = 0; |
| 432 | leave: |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 433 | if (status < 0 && did_quota_inode) |
Christoph Hellwig | 63936dd | 2010-03-03 09:05:01 -0500 | [diff] [blame] | 434 | dquot_free_inode(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 435 | if (handle) |
Mark Fasheh | 02dc1af | 2006-10-09 16:48:10 -0700 | [diff] [blame] | 436 | ocfs2_commit_trans(osb, handle); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 437 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 438 | ocfs2_inode_unlock(dir, 1); |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 439 | if (did_block_signals) |
| 440 | ocfs2_unblock_signals(&oldset); |
Mark Fasheh | e3a8213 | 2006-10-05 16:04:17 -0700 | [diff] [blame] | 441 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 442 | if (status == -ENOSPC) |
| 443 | mlog(0, "Disk is full\n"); |
| 444 | |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 445 | brelse(new_fe_bh); |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 446 | brelse(parent_fe_bh); |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 447 | kfree(si.name); |
| 448 | kfree(si.value); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 449 | |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 450 | ocfs2_free_dir_lookup_result(&lookup); |
| 451 | |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 452 | if ((status < 0) && inode) { |
| 453 | clear_nlink(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 454 | iput(inode); |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 455 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 456 | |
| 457 | if (inode_ac) |
| 458 | ocfs2_free_alloc_context(inode_ac); |
| 459 | |
| 460 | if (data_ac) |
| 461 | ocfs2_free_alloc_context(data_ac); |
| 462 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 463 | if (meta_ac) |
| 464 | ocfs2_free_alloc_context(meta_ac); |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 465 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 466 | mlog_exit(status); |
| 467 | |
| 468 | return status; |
| 469 | } |
| 470 | |
| 471 | static int ocfs2_mknod_locked(struct ocfs2_super *osb, |
| 472 | struct inode *dir, |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 473 | struct inode *inode, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 474 | dev_t dev, |
| 475 | struct buffer_head **new_fe_bh, |
| 476 | struct buffer_head *parent_fe_bh, |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 477 | handle_t *handle, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 478 | struct ocfs2_alloc_context *inode_ac) |
| 479 | { |
| 480 | int status = 0; |
| 481 | struct ocfs2_dinode *fe = NULL; |
| 482 | struct ocfs2_extent_list *fel; |
| 483 | u64 fe_blkno = 0; |
| 484 | u16 suballoc_bit; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 485 | u16 feat; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 486 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 487 | *new_fe_bh = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 488 | |
Tao Ma | 1382115 | 2009-02-25 00:53:23 +0800 | [diff] [blame] | 489 | status = ocfs2_claim_new_inode(osb, handle, dir, parent_fe_bh, |
| 490 | inode_ac, &suballoc_bit, &fe_blkno); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 491 | if (status < 0) { |
| 492 | mlog_errno(status); |
| 493 | goto leave; |
| 494 | } |
| 495 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 496 | /* populate as many fields early on as possible - many of |
| 497 | * these are used by the support functions here and in |
| 498 | * callers. */ |
| 499 | inode->i_ino = ino_from_blkno(osb->sb, fe_blkno); |
| 500 | OCFS2_I(inode)->ip_blkno = fe_blkno; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 501 | spin_lock(&osb->osb_lock); |
| 502 | inode->i_generation = osb->s_next_generation++; |
| 503 | spin_unlock(&osb->osb_lock); |
| 504 | |
| 505 | *new_fe_bh = sb_getblk(osb->sb, fe_blkno); |
| 506 | if (!*new_fe_bh) { |
| 507 | status = -EIO; |
| 508 | mlog_errno(status); |
| 509 | goto leave; |
| 510 | } |
Joel Becker | 8cb471e | 2009-02-10 20:00:41 -0800 | [diff] [blame] | 511 | ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), *new_fe_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 512 | |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 513 | status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), |
| 514 | *new_fe_bh, |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 515 | OCFS2_JOURNAL_ACCESS_CREATE); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 516 | if (status < 0) { |
| 517 | mlog_errno(status); |
| 518 | goto leave; |
| 519 | } |
| 520 | |
| 521 | fe = (struct ocfs2_dinode *) (*new_fe_bh)->b_data; |
| 522 | memset(fe, 0, osb->sb->s_blocksize); |
| 523 | |
| 524 | fe->i_generation = cpu_to_le32(inode->i_generation); |
| 525 | fe->i_fs_generation = cpu_to_le32(osb->fs_generation); |
| 526 | fe->i_blkno = cpu_to_le64(fe_blkno); |
| 527 | fe->i_suballoc_bit = cpu_to_le16(suballoc_bit); |
Tao Ma | 4d0ddb2 | 2008-03-05 16:11:46 +0800 | [diff] [blame] | 528 | fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot); |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 529 | fe->i_uid = cpu_to_le32(inode->i_uid); |
| 530 | fe->i_gid = cpu_to_le32(inode->i_gid); |
| 531 | fe->i_mode = cpu_to_le16(inode->i_mode); |
| 532 | if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 533 | fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev)); |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 534 | |
| 535 | ocfs2_set_links_count(fe, inode->i_nlink); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 536 | |
| 537 | fe->i_last_eb_blk = 0; |
| 538 | strcpy(fe->i_signature, OCFS2_INODE_SIGNATURE); |
| 539 | le32_add_cpu(&fe->i_flags, OCFS2_VALID_FL); |
| 540 | fe->i_atime = fe->i_ctime = fe->i_mtime = |
| 541 | cpu_to_le64(CURRENT_TIME.tv_sec); |
| 542 | fe->i_mtime_nsec = fe->i_ctime_nsec = fe->i_atime_nsec = |
| 543 | cpu_to_le32(CURRENT_TIME.tv_nsec); |
| 544 | fe->i_dtime = 0; |
| 545 | |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 546 | /* |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 547 | * If supported, directories start with inline data. If inline |
| 548 | * isn't supported, but indexing is, we start them as indexed. |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 549 | */ |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 550 | feat = le16_to_cpu(fe->i_dyn_features); |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 551 | if (S_ISDIR(inode->i_mode) && ocfs2_supports_inline_data(osb)) { |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 552 | fe->i_dyn_features = cpu_to_le16(feat | OCFS2_INLINE_DATA_FL); |
| 553 | |
Tiger Yang | d9ae49d | 2009-03-05 11:06:15 +0800 | [diff] [blame] | 554 | fe->id2.i_data.id_count = cpu_to_le16( |
| 555 | ocfs2_max_inline_data_with_xattr(osb->sb, fe)); |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 556 | } else { |
| 557 | fel = &fe->id2.i_list; |
| 558 | fel->l_tree_depth = 0; |
| 559 | fel->l_next_free_rec = 0; |
| 560 | fel->l_count = cpu_to_le16(ocfs2_extent_recs_per_inode(osb->sb)); |
| 561 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 562 | |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 563 | ocfs2_journal_dirty(handle, *new_fe_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 564 | |
Joel Becker | b657c95 | 2008-11-13 14:49:11 -0800 | [diff] [blame] | 565 | ocfs2_populate_inode(inode, fe, 1); |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 566 | ocfs2_ci_set_new(osb, INODE_CACHE(inode)); |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 567 | if (!ocfs2_mount_local(osb)) { |
| 568 | status = ocfs2_create_new_inode_locks(inode); |
| 569 | if (status < 0) |
| 570 | mlog_errno(status); |
| 571 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 572 | |
| 573 | status = 0; /* error in ocfs2_create_new_inode_locks is not |
| 574 | * critical */ |
| 575 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 576 | leave: |
| 577 | if (status < 0) { |
| 578 | if (*new_fe_bh) { |
| 579 | brelse(*new_fe_bh); |
| 580 | *new_fe_bh = NULL; |
| 581 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | mlog_exit(status); |
| 585 | return status; |
| 586 | } |
| 587 | |
| 588 | static int ocfs2_mkdir(struct inode *dir, |
| 589 | struct dentry *dentry, |
| 590 | int mode) |
| 591 | { |
| 592 | int ret; |
| 593 | |
| 594 | mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, mode, |
| 595 | dentry->d_name.len, dentry->d_name.name); |
| 596 | ret = ocfs2_mknod(dir, dentry, mode | S_IFDIR, 0); |
| 597 | mlog_exit(ret); |
| 598 | |
| 599 | return ret; |
| 600 | } |
| 601 | |
| 602 | static int ocfs2_create(struct inode *dir, |
| 603 | struct dentry *dentry, |
| 604 | int mode, |
| 605 | struct nameidata *nd) |
| 606 | { |
| 607 | int ret; |
| 608 | |
| 609 | mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, mode, |
| 610 | dentry->d_name.len, dentry->d_name.name); |
| 611 | ret = ocfs2_mknod(dir, dentry, mode | S_IFREG, 0); |
| 612 | mlog_exit(ret); |
| 613 | |
| 614 | return ret; |
| 615 | } |
| 616 | |
| 617 | static int ocfs2_link(struct dentry *old_dentry, |
| 618 | struct inode *dir, |
| 619 | struct dentry *dentry) |
| 620 | { |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 621 | handle_t *handle; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 622 | struct inode *inode = old_dentry->d_inode; |
| 623 | int err; |
| 624 | struct buffer_head *fe_bh = NULL; |
| 625 | struct buffer_head *parent_fe_bh = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 626 | struct ocfs2_dinode *fe = NULL; |
| 627 | struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 628 | struct ocfs2_dir_lookup_result lookup = { NULL, }; |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 629 | sigset_t oldset; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 630 | |
| 631 | mlog_entry("(inode=%lu, old='%.*s' new='%.*s')\n", inode->i_ino, |
| 632 | old_dentry->d_name.len, old_dentry->d_name.name, |
| 633 | dentry->d_name.len, dentry->d_name.name); |
| 634 | |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 635 | if (S_ISDIR(inode->i_mode)) |
| 636 | return -EPERM; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 637 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 638 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 639 | |
Jan Kara | cb25797 | 2009-06-04 15:26:50 +0200 | [diff] [blame] | 640 | err = ocfs2_inode_lock_nested(dir, &parent_fe_bh, 1, OI_LS_PARENT); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 641 | if (err < 0) { |
| 642 | if (err != -ENOENT) |
| 643 | mlog_errno(err); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 644 | return err; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 645 | } |
| 646 | |
Tiger Yang | 0f62de2 | 2006-08-31 20:39:47 -0700 | [diff] [blame] | 647 | if (!dir->i_nlink) { |
| 648 | err = -ENOENT; |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 649 | goto out; |
Tiger Yang | 0f62de2 | 2006-08-31 20:39:47 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 652 | err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name, |
| 653 | dentry->d_name.len); |
| 654 | if (err) |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 655 | goto out; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 656 | |
| 657 | err = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh, |
| 658 | dentry->d_name.name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 659 | dentry->d_name.len, &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 660 | if (err < 0) { |
| 661 | mlog_errno(err); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 662 | goto out; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 665 | err = ocfs2_inode_lock(inode, &fe_bh, 1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 666 | if (err < 0) { |
| 667 | if (err != -ENOENT) |
| 668 | mlog_errno(err); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 669 | goto out; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | fe = (struct ocfs2_dinode *) fe_bh->b_data; |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 673 | if (ocfs2_read_links_count(fe) >= ocfs2_link_max(osb)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 674 | err = -EMLINK; |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 675 | goto out_unlock_inode; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 678 | handle = ocfs2_start_trans(osb, ocfs2_link_credits(osb->sb)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 679 | if (IS_ERR(handle)) { |
| 680 | err = PTR_ERR(handle); |
| 681 | handle = NULL; |
| 682 | mlog_errno(err); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 683 | goto out_unlock_inode; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 684 | } |
| 685 | |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 686 | /* Starting to change things, restart is no longer possible. */ |
| 687 | ocfs2_block_signals(&oldset); |
| 688 | |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 689 | err = ocfs2_journal_access_di(handle, INODE_CACHE(inode), fe_bh, |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 690 | OCFS2_JOURNAL_ACCESS_WRITE); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 691 | if (err < 0) { |
| 692 | mlog_errno(err); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 693 | goto out_commit; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 694 | } |
| 695 | |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 696 | inc_nlink(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 697 | inode->i_ctime = CURRENT_TIME; |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 698 | ocfs2_set_links_count(fe, inode->i_nlink); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 699 | fe->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec); |
| 700 | fe->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec); |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 701 | ocfs2_journal_dirty(handle, fe_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 702 | |
| 703 | err = ocfs2_add_entry(handle, dentry, inode, |
| 704 | OCFS2_I(inode)->ip_blkno, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 705 | parent_fe_bh, &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 706 | if (err) { |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 707 | ocfs2_add_links_count(fe, -1); |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 708 | drop_nlink(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 709 | mlog_errno(err); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 710 | goto out_commit; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 711 | } |
| 712 | |
Mark Fasheh | 0027dd5 | 2006-09-21 16:51:28 -0700 | [diff] [blame] | 713 | err = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno); |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 714 | if (err) { |
| 715 | mlog_errno(err); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 716 | goto out_commit; |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 719 | atomic_inc(&inode->i_count); |
| 720 | dentry->d_op = &ocfs2_dentry_ops; |
| 721 | d_instantiate(dentry, inode); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 722 | |
| 723 | out_commit: |
Mark Fasheh | 02dc1af | 2006-10-09 16:48:10 -0700 | [diff] [blame] | 724 | ocfs2_commit_trans(osb, handle); |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 725 | ocfs2_unblock_signals(&oldset); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 726 | out_unlock_inode: |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 727 | ocfs2_inode_unlock(inode, 1); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 728 | |
| 729 | out: |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 730 | ocfs2_inode_unlock(dir, 1); |
Mark Fasheh | 123a964 | 2006-10-05 16:48:23 -0700 | [diff] [blame] | 731 | |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 732 | brelse(fe_bh); |
| 733 | brelse(parent_fe_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 734 | |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 735 | ocfs2_free_dir_lookup_result(&lookup); |
| 736 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 737 | mlog_exit(err); |
| 738 | |
| 739 | return err; |
| 740 | } |
| 741 | |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 742 | /* |
| 743 | * Takes and drops an exclusive lock on the given dentry. This will |
| 744 | * force other nodes to drop it. |
| 745 | */ |
| 746 | static int ocfs2_remote_dentry_delete(struct dentry *dentry) |
| 747 | { |
| 748 | int ret; |
| 749 | |
| 750 | ret = ocfs2_dentry_lock(dentry, 1); |
| 751 | if (ret) |
| 752 | mlog_errno(ret); |
| 753 | else |
| 754 | ocfs2_dentry_unlock(dentry, 1); |
| 755 | |
| 756 | return ret; |
| 757 | } |
| 758 | |
Mark Fasheh | 17ff785 | 2006-09-30 23:29:05 -0700 | [diff] [blame] | 759 | static inline int inode_is_unlinkable(struct inode *inode) |
| 760 | { |
| 761 | if (S_ISDIR(inode->i_mode)) { |
| 762 | if (inode->i_nlink == 2) |
| 763 | return 1; |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | if (inode->i_nlink == 1) |
| 768 | return 1; |
| 769 | return 0; |
| 770 | } |
| 771 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 772 | static int ocfs2_unlink(struct inode *dir, |
| 773 | struct dentry *dentry) |
| 774 | { |
| 775 | int status; |
Mark Fasheh | 30a4f5e | 2006-10-06 11:49:45 -0700 | [diff] [blame] | 776 | int child_locked = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 777 | struct inode *inode = dentry->d_inode; |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 778 | struct inode *orphan_dir = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 779 | struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); |
| 780 | u64 blkno; |
| 781 | struct ocfs2_dinode *fe = NULL; |
| 782 | struct buffer_head *fe_bh = NULL; |
| 783 | struct buffer_head *parent_node_bh = NULL; |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 784 | handle_t *handle = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 785 | char orphan_name[OCFS2_ORPHAN_NAMELEN + 1]; |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 786 | struct ocfs2_dir_lookup_result lookup = { NULL, }; |
| 787 | struct ocfs2_dir_lookup_result orphan_insert = { NULL, }; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 788 | |
| 789 | mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry, |
| 790 | dentry->d_name.len, dentry->d_name.name); |
| 791 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 792 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 793 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 794 | BUG_ON(dentry->d_parent->d_inode != dir); |
| 795 | |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 796 | mlog(0, "ino = %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 797 | |
| 798 | if (inode == osb->root_inode) { |
| 799 | mlog(0, "Cannot delete the root directory\n"); |
Mark Fasheh | 30a4f5e | 2006-10-06 11:49:45 -0700 | [diff] [blame] | 800 | return -EPERM; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 801 | } |
| 802 | |
Jan Kara | cb25797 | 2009-06-04 15:26:50 +0200 | [diff] [blame] | 803 | status = ocfs2_inode_lock_nested(dir, &parent_node_bh, 1, |
| 804 | OI_LS_PARENT); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 805 | if (status < 0) { |
| 806 | if (status != -ENOENT) |
| 807 | mlog_errno(status); |
Mark Fasheh | 30a4f5e | 2006-10-06 11:49:45 -0700 | [diff] [blame] | 808 | return status; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | status = ocfs2_find_files_on_disk(dentry->d_name.name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 812 | dentry->d_name.len, &blkno, dir, |
| 813 | &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 814 | if (status < 0) { |
| 815 | if (status != -ENOENT) |
| 816 | mlog_errno(status); |
| 817 | goto leave; |
| 818 | } |
| 819 | |
| 820 | if (OCFS2_I(inode)->ip_blkno != blkno) { |
| 821 | status = -ENOENT; |
| 822 | |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 823 | mlog(0, "ip_blkno %llu != dirent blkno %llu ip_flags = %x\n", |
| 824 | (unsigned long long)OCFS2_I(inode)->ip_blkno, |
| 825 | (unsigned long long)blkno, OCFS2_I(inode)->ip_flags); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 826 | goto leave; |
| 827 | } |
| 828 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 829 | status = ocfs2_inode_lock(inode, &fe_bh, 1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 830 | if (status < 0) { |
| 831 | if (status != -ENOENT) |
| 832 | mlog_errno(status); |
| 833 | goto leave; |
| 834 | } |
Mark Fasheh | 30a4f5e | 2006-10-06 11:49:45 -0700 | [diff] [blame] | 835 | child_locked = 1; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 836 | |
| 837 | if (S_ISDIR(inode->i_mode)) { |
Mark Fasheh | b80b549 | 2009-02-18 11:41:38 -0800 | [diff] [blame] | 838 | if (inode->i_nlink != 2 || !ocfs2_empty_dir(inode)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 839 | status = -ENOTEMPTY; |
| 840 | goto leave; |
| 841 | } |
| 842 | } |
| 843 | |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 844 | status = ocfs2_remote_dentry_delete(dentry); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 845 | if (status < 0) { |
Mark Fasheh | 34d024f | 2007-09-24 15:56:19 -0700 | [diff] [blame] | 846 | /* This remote delete should succeed under all normal |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 847 | * circumstances. */ |
| 848 | mlog_errno(status); |
| 849 | goto leave; |
| 850 | } |
| 851 | |
Mark Fasheh | 17ff785 | 2006-09-30 23:29:05 -0700 | [diff] [blame] | 852 | if (inode_is_unlinkable(inode)) { |
Tao Ma | 19bd341 | 2009-08-18 11:44:10 +0800 | [diff] [blame] | 853 | status = ocfs2_prepare_orphan_dir(osb, &orphan_dir, |
| 854 | OCFS2_I(inode)->ip_blkno, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 855 | orphan_name, &orphan_insert); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 856 | if (status < 0) { |
| 857 | mlog_errno(status); |
| 858 | goto leave; |
| 859 | } |
| 860 | } |
| 861 | |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 862 | handle = ocfs2_start_trans(osb, ocfs2_unlink_credits(osb->sb)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 863 | if (IS_ERR(handle)) { |
| 864 | status = PTR_ERR(handle); |
| 865 | handle = NULL; |
| 866 | mlog_errno(status); |
| 867 | goto leave; |
| 868 | } |
| 869 | |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 870 | status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), fe_bh, |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 871 | OCFS2_JOURNAL_ACCESS_WRITE); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 872 | if (status < 0) { |
| 873 | mlog_errno(status); |
| 874 | goto leave; |
| 875 | } |
| 876 | |
| 877 | fe = (struct ocfs2_dinode *) fe_bh->b_data; |
| 878 | |
Mark Fasheh | 17ff785 | 2006-09-30 23:29:05 -0700 | [diff] [blame] | 879 | if (inode_is_unlinkable(inode)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 880 | status = ocfs2_orphan_add(osb, handle, inode, fe, orphan_name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 881 | &orphan_insert, orphan_dir); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 882 | if (status < 0) { |
| 883 | mlog_errno(status); |
| 884 | goto leave; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | /* delete the name from the parent dir */ |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 889 | status = ocfs2_delete_entry(handle, dir, &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 890 | if (status < 0) { |
| 891 | mlog_errno(status); |
| 892 | goto leave; |
| 893 | } |
| 894 | |
Mark Fasheh | 17ff785 | 2006-09-30 23:29:05 -0700 | [diff] [blame] | 895 | if (S_ISDIR(inode->i_mode)) |
| 896 | drop_nlink(inode); |
| 897 | drop_nlink(inode); |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 898 | ocfs2_set_links_count(fe, inode->i_nlink); |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 899 | ocfs2_journal_dirty(handle, fe_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 900 | |
Mark Fasheh | 592282c | 2007-01-02 17:59:40 -0800 | [diff] [blame] | 901 | dir->i_ctime = dir->i_mtime = CURRENT_TIME; |
| 902 | if (S_ISDIR(inode->i_mode)) |
Mark Fasheh | 17ff785 | 2006-09-30 23:29:05 -0700 | [diff] [blame] | 903 | drop_nlink(dir); |
Mark Fasheh | 592282c | 2007-01-02 17:59:40 -0800 | [diff] [blame] | 904 | |
| 905 | status = ocfs2_mark_inode_dirty(handle, dir, parent_node_bh); |
| 906 | if (status < 0) { |
| 907 | mlog_errno(status); |
| 908 | if (S_ISDIR(inode->i_mode)) |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 909 | inc_nlink(dir); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | leave: |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 913 | if (handle) |
Mark Fasheh | 02dc1af | 2006-10-09 16:48:10 -0700 | [diff] [blame] | 914 | ocfs2_commit_trans(osb, handle); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 915 | |
Mark Fasheh | 30a4f5e | 2006-10-06 11:49:45 -0700 | [diff] [blame] | 916 | if (child_locked) |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 917 | ocfs2_inode_unlock(inode, 1); |
Mark Fasheh | 30a4f5e | 2006-10-06 11:49:45 -0700 | [diff] [blame] | 918 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 919 | ocfs2_inode_unlock(dir, 1); |
Mark Fasheh | 30a4f5e | 2006-10-06 11:49:45 -0700 | [diff] [blame] | 920 | |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 921 | if (orphan_dir) { |
| 922 | /* This was locked for us in ocfs2_prepare_orphan_dir() */ |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 923 | ocfs2_inode_unlock(orphan_dir, 1); |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 924 | mutex_unlock(&orphan_dir->i_mutex); |
| 925 | iput(orphan_dir); |
| 926 | } |
| 927 | |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 928 | brelse(fe_bh); |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 929 | brelse(parent_node_bh); |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 930 | |
| 931 | ocfs2_free_dir_lookup_result(&orphan_insert); |
| 932 | ocfs2_free_dir_lookup_result(&lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 933 | |
| 934 | mlog_exit(status); |
| 935 | |
| 936 | return status; |
| 937 | } |
| 938 | |
| 939 | /* |
| 940 | * The only place this should be used is rename! |
| 941 | * if they have the same id, then the 1st one is the only one locked. |
| 942 | */ |
| 943 | static int ocfs2_double_lock(struct ocfs2_super *osb, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 944 | struct buffer_head **bh1, |
| 945 | struct inode *inode1, |
| 946 | struct buffer_head **bh2, |
| 947 | struct inode *inode2) |
| 948 | { |
| 949 | int status; |
| 950 | struct ocfs2_inode_info *oi1 = OCFS2_I(inode1); |
| 951 | struct ocfs2_inode_info *oi2 = OCFS2_I(inode2); |
| 952 | struct buffer_head **tmpbh; |
| 953 | struct inode *tmpinode; |
| 954 | |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 955 | mlog_entry("(inode1 = %llu, inode2 = %llu)\n", |
| 956 | (unsigned long long)oi1->ip_blkno, |
| 957 | (unsigned long long)oi2->ip_blkno); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 958 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 959 | if (*bh1) |
| 960 | *bh1 = NULL; |
| 961 | if (*bh2) |
| 962 | *bh2 = NULL; |
| 963 | |
| 964 | /* we always want to lock the one with the lower lockid first. */ |
| 965 | if (oi1->ip_blkno != oi2->ip_blkno) { |
| 966 | if (oi1->ip_blkno < oi2->ip_blkno) { |
| 967 | /* switch id1 and id2 around */ |
| 968 | mlog(0, "switching them around...\n"); |
| 969 | tmpbh = bh2; |
| 970 | bh2 = bh1; |
| 971 | bh1 = tmpbh; |
| 972 | |
| 973 | tmpinode = inode2; |
| 974 | inode2 = inode1; |
| 975 | inode1 = tmpinode; |
| 976 | } |
| 977 | /* lock id2 */ |
Jan Kara | cb25797 | 2009-06-04 15:26:50 +0200 | [diff] [blame] | 978 | status = ocfs2_inode_lock_nested(inode2, bh2, 1, |
| 979 | OI_LS_RENAME1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 980 | if (status < 0) { |
| 981 | if (status != -ENOENT) |
| 982 | mlog_errno(status); |
| 983 | goto bail; |
| 984 | } |
| 985 | } |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 986 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 987 | /* lock id1 */ |
Jan Kara | cb25797 | 2009-06-04 15:26:50 +0200 | [diff] [blame] | 988 | status = ocfs2_inode_lock_nested(inode1, bh1, 1, OI_LS_RENAME2); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 989 | if (status < 0) { |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 990 | /* |
| 991 | * An error return must mean that no cluster locks |
| 992 | * were held on function exit. |
| 993 | */ |
| 994 | if (oi1->ip_blkno != oi2->ip_blkno) |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 995 | ocfs2_inode_unlock(inode2, 1); |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 996 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 997 | if (status != -ENOENT) |
| 998 | mlog_errno(status); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 999 | } |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1000 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1001 | bail: |
| 1002 | mlog_exit(status); |
| 1003 | return status; |
| 1004 | } |
| 1005 | |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1006 | static void ocfs2_double_unlock(struct inode *inode1, struct inode *inode2) |
| 1007 | { |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1008 | ocfs2_inode_unlock(inode1, 1); |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1009 | |
| 1010 | if (inode1 != inode2) |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1011 | ocfs2_inode_unlock(inode2, 1); |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1014 | static int ocfs2_rename(struct inode *old_dir, |
| 1015 | struct dentry *old_dentry, |
| 1016 | struct inode *new_dir, |
| 1017 | struct dentry *new_dentry) |
| 1018 | { |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1019 | int status = 0, rename_lock = 0, parents_locked = 0, target_exists = 0; |
| 1020 | int old_child_locked = 0, new_child_locked = 0, update_dot_dot = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1021 | struct inode *old_inode = old_dentry->d_inode; |
| 1022 | struct inode *new_inode = new_dentry->d_inode; |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1023 | struct inode *orphan_dir = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1024 | struct ocfs2_dinode *newfe = NULL; |
| 1025 | char orphan_name[OCFS2_ORPHAN_NAMELEN + 1]; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1026 | struct buffer_head *newfe_bh = NULL; |
Mark Fasheh | 592282c | 2007-01-02 17:59:40 -0800 | [diff] [blame] | 1027 | struct buffer_head *old_inode_bh = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1028 | struct ocfs2_super *osb = NULL; |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 1029 | u64 newfe_blkno, old_de_ino; |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 1030 | handle_t *handle = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1031 | struct buffer_head *old_dir_bh = NULL; |
| 1032 | struct buffer_head *new_dir_bh = NULL; |
Mark Fasheh | 592282c | 2007-01-02 17:59:40 -0800 | [diff] [blame] | 1033 | nlink_t old_dir_nlink = old_dir->i_nlink; |
Sunil Mushran | 480214d | 2007-08-06 15:11:56 -0700 | [diff] [blame] | 1034 | struct ocfs2_dinode *old_di; |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1035 | struct ocfs2_dir_lookup_result old_inode_dot_dot_res = { NULL, }; |
| 1036 | struct ocfs2_dir_lookup_result target_lookup_res = { NULL, }; |
| 1037 | struct ocfs2_dir_lookup_result old_entry_lookup = { NULL, }; |
| 1038 | struct ocfs2_dir_lookup_result orphan_insert = { NULL, }; |
| 1039 | struct ocfs2_dir_lookup_result target_insert = { NULL, }; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1040 | |
| 1041 | /* At some point it might be nice to break this function up a |
| 1042 | * bit. */ |
| 1043 | |
| 1044 | mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p, from='%.*s' to='%.*s')\n", |
| 1045 | old_dir, old_dentry, new_dir, new_dentry, |
| 1046 | old_dentry->d_name.len, old_dentry->d_name.name, |
| 1047 | new_dentry->d_name.len, new_dentry->d_name.name); |
| 1048 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1049 | dquot_initialize(old_dir); |
| 1050 | dquot_initialize(new_dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1051 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1052 | osb = OCFS2_SB(old_dir->i_sb); |
| 1053 | |
| 1054 | if (new_inode) { |
| 1055 | if (!igrab(new_inode)) |
| 1056 | BUG(); |
| 1057 | } |
| 1058 | |
Uwe Kleine-König | 1b3c371 | 2007-02-17 19:23:03 +0100 | [diff] [blame] | 1059 | /* Assume a directory hierarchy thusly: |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1060 | * a/b/c |
| 1061 | * a/d |
| 1062 | * a,b,c, and d are all directories. |
| 1063 | * |
| 1064 | * from cwd of 'a' on both nodes: |
| 1065 | * node1: mv b/c d |
| 1066 | * node2: mv d b/c |
| 1067 | * |
| 1068 | * And that's why, just like the VFS, we need a file system |
| 1069 | * rename lock. */ |
Jan Kara | 5dabd69 | 2008-02-21 18:00:00 +0100 | [diff] [blame] | 1070 | if (old_dir != new_dir && S_ISDIR(old_inode->i_mode)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1071 | status = ocfs2_rename_lock(osb); |
| 1072 | if (status < 0) { |
| 1073 | mlog_errno(status); |
| 1074 | goto bail; |
| 1075 | } |
| 1076 | rename_lock = 1; |
| 1077 | } |
| 1078 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1079 | /* if old and new are the same, this'll just do one lock. */ |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1080 | status = ocfs2_double_lock(osb, &old_dir_bh, old_dir, |
| 1081 | &new_dir_bh, new_dir); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1082 | if (status < 0) { |
| 1083 | mlog_errno(status); |
| 1084 | goto bail; |
| 1085 | } |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1086 | parents_locked = 1; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1087 | |
| 1088 | /* make sure both dirs have bhs |
| 1089 | * get an extra ref on old_dir_bh if old==new */ |
| 1090 | if (!new_dir_bh) { |
| 1091 | if (old_dir_bh) { |
| 1092 | new_dir_bh = old_dir_bh; |
| 1093 | get_bh(new_dir_bh); |
| 1094 | } else { |
| 1095 | mlog(ML_ERROR, "no old_dir_bh!\n"); |
| 1096 | status = -EIO; |
| 1097 | goto bail; |
| 1098 | } |
| 1099 | } |
| 1100 | |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 1101 | /* |
Mark Fasheh | 592282c | 2007-01-02 17:59:40 -0800 | [diff] [blame] | 1102 | * Aside from allowing a meta data update, the locking here |
Mark Fasheh | 34d024f | 2007-09-24 15:56:19 -0700 | [diff] [blame] | 1103 | * also ensures that the downconvert thread on other nodes |
| 1104 | * won't have to concurrently downconvert the inode and the |
| 1105 | * dentry locks. |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 1106 | */ |
Jan Kara | cb25797 | 2009-06-04 15:26:50 +0200 | [diff] [blame] | 1107 | status = ocfs2_inode_lock_nested(old_inode, &old_inode_bh, 1, |
| 1108 | OI_LS_PARENT); |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 1109 | if (status < 0) { |
| 1110 | if (status != -ENOENT) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1111 | mlog_errno(status); |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 1112 | goto bail; |
| 1113 | } |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1114 | old_child_locked = 1; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1115 | |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 1116 | status = ocfs2_remote_dentry_delete(old_dentry); |
| 1117 | if (status < 0) { |
| 1118 | mlog_errno(status); |
| 1119 | goto bail; |
| 1120 | } |
| 1121 | |
| 1122 | if (S_ISDIR(old_inode->i_mode)) { |
Mark Fasheh | 38760e2 | 2007-09-11 17:21:56 -0700 | [diff] [blame] | 1123 | u64 old_inode_parent; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1124 | |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1125 | update_dot_dot = 1; |
Mark Fasheh | 38760e2 | 2007-09-11 17:21:56 -0700 | [diff] [blame] | 1126 | status = ocfs2_find_files_on_disk("..", 2, &old_inode_parent, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1127 | old_inode, |
| 1128 | &old_inode_dot_dot_res); |
Mark Fasheh | 38760e2 | 2007-09-11 17:21:56 -0700 | [diff] [blame] | 1129 | if (status) { |
| 1130 | status = -EIO; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1131 | goto bail; |
Mark Fasheh | 38760e2 | 2007-09-11 17:21:56 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | if (old_inode_parent != OCFS2_I(old_dir)->ip_blkno) { |
| 1135 | status = -EIO; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1136 | goto bail; |
Mark Fasheh | 38760e2 | 2007-09-11 17:21:56 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | if (!new_inode && new_dir != old_dir && |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 1140 | new_dir->i_nlink >= ocfs2_link_max(osb)) { |
Mark Fasheh | 38760e2 | 2007-09-11 17:21:56 -0700 | [diff] [blame] | 1141 | status = -EMLINK; |
| 1142 | goto bail; |
| 1143 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1144 | } |
| 1145 | |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 1146 | status = ocfs2_lookup_ino_from_name(old_dir, old_dentry->d_name.name, |
| 1147 | old_dentry->d_name.len, |
| 1148 | &old_de_ino); |
| 1149 | if (status) { |
| 1150 | status = -ENOENT; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1151 | goto bail; |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 1152 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1153 | |
| 1154 | /* |
| 1155 | * Check for inode number is _not_ due to possible IO errors. |
| 1156 | * We might rmdir the source, keep it as pwd of some process |
| 1157 | * and merrily kill the link to whatever was created under the |
| 1158 | * same name. Goodbye sticky bit ;-< |
| 1159 | */ |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 1160 | if (old_de_ino != OCFS2_I(old_inode)->ip_blkno) { |
| 1161 | status = -ENOENT; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1162 | goto bail; |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 1163 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1164 | |
| 1165 | /* check if the target already exists (in which case we need |
| 1166 | * to delete it */ |
| 1167 | status = ocfs2_find_files_on_disk(new_dentry->d_name.name, |
| 1168 | new_dentry->d_name.len, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1169 | &newfe_blkno, new_dir, |
| 1170 | &target_lookup_res); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1171 | /* The only error we allow here is -ENOENT because the new |
| 1172 | * file not existing is perfectly valid. */ |
| 1173 | if ((status < 0) && (status != -ENOENT)) { |
| 1174 | /* If we cannot find the file specified we should just */ |
| 1175 | /* return the error... */ |
| 1176 | mlog_errno(status); |
| 1177 | goto bail; |
| 1178 | } |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1179 | if (status == 0) |
| 1180 | target_exists = 1; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1181 | |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1182 | if (!target_exists && new_inode) { |
Srinivas Eeda | e325a88 | 2007-10-31 16:49:43 -0700 | [diff] [blame] | 1183 | /* |
| 1184 | * Target was unlinked by another node while we were |
| 1185 | * waiting to get to ocfs2_rename(). There isn't |
| 1186 | * anything we can do here to help the situation, so |
| 1187 | * bubble up the appropriate error. |
| 1188 | */ |
| 1189 | status = -ENOENT; |
| 1190 | goto bail; |
| 1191 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1192 | |
| 1193 | /* In case we need to overwrite an existing file, we blow it |
| 1194 | * away first */ |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1195 | if (target_exists) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1196 | /* VFS didn't think there existed an inode here, but |
| 1197 | * someone else in the cluster must have raced our |
| 1198 | * rename to create one. Today we error cleanly, in |
| 1199 | * the future we should consider calling iget to build |
| 1200 | * a new struct inode for this entry. */ |
| 1201 | if (!new_inode) { |
| 1202 | status = -EACCES; |
| 1203 | |
| 1204 | mlog(0, "We found an inode for name %.*s but VFS " |
| 1205 | "didn't give us one.\n", new_dentry->d_name.len, |
| 1206 | new_dentry->d_name.name); |
| 1207 | goto bail; |
| 1208 | } |
| 1209 | |
| 1210 | if (OCFS2_I(new_inode)->ip_blkno != newfe_blkno) { |
| 1211 | status = -EACCES; |
| 1212 | |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1213 | mlog(0, "Inode %llu and dir %llu disagree. flags = %x\n", |
| 1214 | (unsigned long long)OCFS2_I(new_inode)->ip_blkno, |
| 1215 | (unsigned long long)newfe_blkno, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1216 | OCFS2_I(new_inode)->ip_flags); |
| 1217 | goto bail; |
| 1218 | } |
| 1219 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1220 | status = ocfs2_inode_lock(new_inode, &newfe_bh, 1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1221 | if (status < 0) { |
| 1222 | if (status != -ENOENT) |
| 1223 | mlog_errno(status); |
| 1224 | goto bail; |
| 1225 | } |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1226 | new_child_locked = 1; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1227 | |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 1228 | status = ocfs2_remote_dentry_delete(new_dentry); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1229 | if (status < 0) { |
| 1230 | mlog_errno(status); |
| 1231 | goto bail; |
| 1232 | } |
| 1233 | |
| 1234 | newfe = (struct ocfs2_dinode *) newfe_bh->b_data; |
| 1235 | |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1236 | mlog(0, "aha rename over existing... new_blkno=%llu " |
| 1237 | "newfebh=%p bhblocknr=%llu\n", |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1238 | (unsigned long long)newfe_blkno, newfe_bh, newfe_bh ? |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1239 | (unsigned long long)newfe_bh->b_blocknr : 0ULL); |
| 1240 | |
| 1241 | if (S_ISDIR(new_inode->i_mode) || (new_inode->i_nlink == 1)) { |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1242 | status = ocfs2_prepare_orphan_dir(osb, &orphan_dir, |
Tao Ma | 19bd341 | 2009-08-18 11:44:10 +0800 | [diff] [blame] | 1243 | OCFS2_I(new_inode)->ip_blkno, |
| 1244 | orphan_name, &orphan_insert); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1245 | if (status < 0) { |
| 1246 | mlog_errno(status); |
| 1247 | goto bail; |
| 1248 | } |
| 1249 | } |
| 1250 | } else { |
| 1251 | BUG_ON(new_dentry->d_parent->d_inode != new_dir); |
| 1252 | |
| 1253 | status = ocfs2_check_dir_for_entry(new_dir, |
| 1254 | new_dentry->d_name.name, |
| 1255 | new_dentry->d_name.len); |
| 1256 | if (status) |
| 1257 | goto bail; |
| 1258 | |
| 1259 | status = ocfs2_prepare_dir_for_insert(osb, new_dir, new_dir_bh, |
| 1260 | new_dentry->d_name.name, |
| 1261 | new_dentry->d_name.len, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1262 | &target_insert); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1263 | if (status < 0) { |
| 1264 | mlog_errno(status); |
| 1265 | goto bail; |
| 1266 | } |
| 1267 | } |
| 1268 | |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 1269 | handle = ocfs2_start_trans(osb, ocfs2_rename_credits(osb->sb)); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1270 | if (IS_ERR(handle)) { |
| 1271 | status = PTR_ERR(handle); |
| 1272 | handle = NULL; |
| 1273 | mlog_errno(status); |
| 1274 | goto bail; |
| 1275 | } |
| 1276 | |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1277 | if (target_exists) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1278 | if (S_ISDIR(new_inode->i_mode)) { |
Mark Fasheh | b80b549 | 2009-02-18 11:41:38 -0800 | [diff] [blame] | 1279 | if (new_inode->i_nlink != 2 || |
| 1280 | !ocfs2_empty_dir(new_inode)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1281 | status = -ENOTEMPTY; |
| 1282 | goto bail; |
| 1283 | } |
| 1284 | } |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 1285 | status = ocfs2_journal_access_di(handle, INODE_CACHE(new_inode), |
| 1286 | newfe_bh, |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 1287 | OCFS2_JOURNAL_ACCESS_WRITE); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1288 | if (status < 0) { |
| 1289 | mlog_errno(status); |
| 1290 | goto bail; |
| 1291 | } |
| 1292 | |
| 1293 | if (S_ISDIR(new_inode->i_mode) || |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 1294 | (ocfs2_read_links_count(newfe) == 1)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1295 | status = ocfs2_orphan_add(osb, handle, new_inode, |
| 1296 | newfe, orphan_name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1297 | &orphan_insert, orphan_dir); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1298 | if (status < 0) { |
| 1299 | mlog_errno(status); |
| 1300 | goto bail; |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | /* change the dirent to point to the correct inode */ |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1305 | status = ocfs2_update_entry(new_dir, handle, &target_lookup_res, |
| 1306 | old_inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1307 | if (status < 0) { |
| 1308 | mlog_errno(status); |
| 1309 | goto bail; |
| 1310 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1311 | new_dir->i_version++; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1312 | |
| 1313 | if (S_ISDIR(new_inode->i_mode)) |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 1314 | ocfs2_set_links_count(newfe, 0); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1315 | else |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 1316 | ocfs2_add_links_count(newfe, -1); |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 1317 | ocfs2_journal_dirty(handle, newfe_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1318 | } else { |
| 1319 | /* if the name was not found in new_dir, add it now */ |
| 1320 | status = ocfs2_add_entry(handle, new_dentry, old_inode, |
| 1321 | OCFS2_I(old_inode)->ip_blkno, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1322 | new_dir_bh, &target_insert); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | old_inode->i_ctime = CURRENT_TIME; |
| 1326 | mark_inode_dirty(old_inode); |
Sunil Mushran | 480214d | 2007-08-06 15:11:56 -0700 | [diff] [blame] | 1327 | |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 1328 | status = ocfs2_journal_access_di(handle, INODE_CACHE(old_inode), |
| 1329 | old_inode_bh, |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 1330 | OCFS2_JOURNAL_ACCESS_WRITE); |
Sunil Mushran | 480214d | 2007-08-06 15:11:56 -0700 | [diff] [blame] | 1331 | if (status >= 0) { |
| 1332 | old_di = (struct ocfs2_dinode *) old_inode_bh->b_data; |
| 1333 | |
| 1334 | old_di->i_ctime = cpu_to_le64(old_inode->i_ctime.tv_sec); |
| 1335 | old_di->i_ctime_nsec = cpu_to_le32(old_inode->i_ctime.tv_nsec); |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 1336 | ocfs2_journal_dirty(handle, old_inode_bh); |
Sunil Mushran | 480214d | 2007-08-06 15:11:56 -0700 | [diff] [blame] | 1337 | } else |
| 1338 | mlog_errno(status); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1339 | |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 1340 | /* |
| 1341 | * Now that the name has been added to new_dir, remove the old name. |
| 1342 | * |
| 1343 | * We don't keep any directory entry context around until now |
| 1344 | * because the insert might have changed the type of directory |
| 1345 | * we're dealing with. |
| 1346 | */ |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1347 | status = ocfs2_find_entry(old_dentry->d_name.name, |
| 1348 | old_dentry->d_name.len, old_dir, |
| 1349 | &old_entry_lookup); |
| 1350 | if (status) |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 1351 | goto bail; |
Mark Fasheh | 5b6a3a2 | 2007-09-13 16:33:54 -0700 | [diff] [blame] | 1352 | |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1353 | status = ocfs2_delete_entry(handle, old_dir, &old_entry_lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1354 | if (status < 0) { |
| 1355 | mlog_errno(status); |
| 1356 | goto bail; |
| 1357 | } |
| 1358 | |
| 1359 | if (new_inode) { |
| 1360 | new_inode->i_nlink--; |
| 1361 | new_inode->i_ctime = CURRENT_TIME; |
| 1362 | } |
| 1363 | old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME; |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1364 | |
| 1365 | if (update_dot_dot) { |
| 1366 | status = ocfs2_update_entry(old_inode, handle, |
| 1367 | &old_inode_dot_dot_res, new_dir); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1368 | old_dir->i_nlink--; |
| 1369 | if (new_inode) { |
| 1370 | new_inode->i_nlink--; |
| 1371 | } else { |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1372 | inc_nlink(new_dir); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1373 | mark_inode_dirty(new_dir); |
| 1374 | } |
| 1375 | } |
| 1376 | mark_inode_dirty(old_dir); |
Mark Fasheh | 592282c | 2007-01-02 17:59:40 -0800 | [diff] [blame] | 1377 | ocfs2_mark_inode_dirty(handle, old_dir, old_dir_bh); |
| 1378 | if (new_inode) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1379 | mark_inode_dirty(new_inode); |
Mark Fasheh | 592282c | 2007-01-02 17:59:40 -0800 | [diff] [blame] | 1380 | ocfs2_mark_inode_dirty(handle, new_inode, newfe_bh); |
| 1381 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1382 | |
Mark Fasheh | 592282c | 2007-01-02 17:59:40 -0800 | [diff] [blame] | 1383 | if (old_dir != new_dir) { |
| 1384 | /* Keep the same times on both directories.*/ |
| 1385 | new_dir->i_ctime = new_dir->i_mtime = old_dir->i_ctime; |
| 1386 | |
| 1387 | /* |
| 1388 | * This will also pick up the i_nlink change from the |
| 1389 | * block above. |
| 1390 | */ |
| 1391 | ocfs2_mark_inode_dirty(handle, new_dir, new_dir_bh); |
| 1392 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1393 | |
| 1394 | if (old_dir_nlink != old_dir->i_nlink) { |
| 1395 | if (!old_dir_bh) { |
| 1396 | mlog(ML_ERROR, "need to change nlink for old dir " |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1397 | "%llu from %d to %d but bh is NULL!\n", |
| 1398 | (unsigned long long)OCFS2_I(old_dir)->ip_blkno, |
| 1399 | (int)old_dir_nlink, old_dir->i_nlink); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1400 | } else { |
| 1401 | struct ocfs2_dinode *fe; |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 1402 | status = ocfs2_journal_access_di(handle, |
| 1403 | INODE_CACHE(old_dir), |
| 1404 | old_dir_bh, |
| 1405 | OCFS2_JOURNAL_ACCESS_WRITE); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1406 | fe = (struct ocfs2_dinode *) old_dir_bh->b_data; |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 1407 | ocfs2_set_links_count(fe, old_dir->i_nlink); |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 1408 | ocfs2_journal_dirty(handle, old_dir_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1409 | } |
| 1410 | } |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 1411 | ocfs2_dentry_move(old_dentry, new_dentry, old_dir, new_dir); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1412 | status = 0; |
| 1413 | bail: |
| 1414 | if (rename_lock) |
| 1415 | ocfs2_rename_unlock(osb); |
| 1416 | |
| 1417 | if (handle) |
Mark Fasheh | 02dc1af | 2006-10-09 16:48:10 -0700 | [diff] [blame] | 1418 | ocfs2_commit_trans(osb, handle); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1419 | |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1420 | if (parents_locked) |
| 1421 | ocfs2_double_unlock(old_dir, new_dir); |
| 1422 | |
| 1423 | if (old_child_locked) |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1424 | ocfs2_inode_unlock(old_inode, 1); |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1425 | |
| 1426 | if (new_child_locked) |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1427 | ocfs2_inode_unlock(new_inode, 1); |
Mark Fasheh | 8d5596c | 2006-10-06 15:04:51 -0700 | [diff] [blame] | 1428 | |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1429 | if (orphan_dir) { |
| 1430 | /* This was locked for us in ocfs2_prepare_orphan_dir() */ |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1431 | ocfs2_inode_unlock(orphan_dir, 1); |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1432 | mutex_unlock(&orphan_dir->i_mutex); |
| 1433 | iput(orphan_dir); |
| 1434 | } |
| 1435 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1436 | if (new_inode) |
| 1437 | sync_mapping_buffers(old_inode->i_mapping); |
| 1438 | |
| 1439 | if (new_inode) |
| 1440 | iput(new_inode); |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1441 | |
| 1442 | ocfs2_free_dir_lookup_result(&target_lookup_res); |
| 1443 | ocfs2_free_dir_lookup_result(&old_entry_lookup); |
| 1444 | ocfs2_free_dir_lookup_result(&old_inode_dot_dot_res); |
| 1445 | ocfs2_free_dir_lookup_result(&orphan_insert); |
| 1446 | ocfs2_free_dir_lookup_result(&target_insert); |
| 1447 | |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 1448 | brelse(newfe_bh); |
| 1449 | brelse(old_inode_bh); |
| 1450 | brelse(old_dir_bh); |
| 1451 | brelse(new_dir_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1452 | |
| 1453 | mlog_exit(status); |
| 1454 | |
| 1455 | return status; |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * we expect i_size = strlen(symname). Copy symname into the file |
| 1460 | * data, including the null terminator. |
| 1461 | */ |
| 1462 | static int ocfs2_create_symlink_data(struct ocfs2_super *osb, |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 1463 | handle_t *handle, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1464 | struct inode *inode, |
| 1465 | const char *symname) |
| 1466 | { |
| 1467 | struct buffer_head **bhs = NULL; |
| 1468 | const char *c; |
| 1469 | struct super_block *sb = osb->sb; |
Mark Fasheh | 4f902c3 | 2007-03-09 16:26:50 -0800 | [diff] [blame] | 1470 | u64 p_blkno, p_blocks; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1471 | int virtual, blocks, status, i, bytes_left; |
| 1472 | |
| 1473 | bytes_left = i_size_read(inode) + 1; |
| 1474 | /* we can't trust i_blocks because we're actually going to |
| 1475 | * write i_size + 1 bytes. */ |
| 1476 | blocks = (bytes_left + sb->s_blocksize - 1) >> sb->s_blocksize_bits; |
| 1477 | |
Andrew Morton | 5515eff | 2006-03-26 01:37:53 -0800 | [diff] [blame] | 1478 | mlog_entry("i_blocks = %llu, i_size = %llu, blocks = %d\n", |
| 1479 | (unsigned long long)inode->i_blocks, |
| 1480 | i_size_read(inode), blocks); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1481 | |
| 1482 | /* Sanity check -- make sure we're going to fit. */ |
| 1483 | if (bytes_left > |
| 1484 | ocfs2_clusters_to_bytes(sb, OCFS2_I(inode)->ip_clusters)) { |
| 1485 | status = -EIO; |
| 1486 | mlog_errno(status); |
| 1487 | goto bail; |
| 1488 | } |
| 1489 | |
| 1490 | bhs = kcalloc(blocks, sizeof(struct buffer_head *), GFP_KERNEL); |
| 1491 | if (!bhs) { |
| 1492 | status = -ENOMEM; |
| 1493 | mlog_errno(status); |
| 1494 | goto bail; |
| 1495 | } |
| 1496 | |
Mark Fasheh | 49cb8d2 | 2007-03-09 16:21:46 -0800 | [diff] [blame] | 1497 | status = ocfs2_extent_map_get_blocks(inode, 0, &p_blkno, &p_blocks, |
| 1498 | NULL); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1499 | if (status < 0) { |
| 1500 | mlog_errno(status); |
| 1501 | goto bail; |
| 1502 | } |
| 1503 | |
| 1504 | /* links can never be larger than one cluster so we know this |
| 1505 | * is all going to be contiguous, but do a sanity check |
| 1506 | * anyway. */ |
| 1507 | if ((p_blocks << sb->s_blocksize_bits) < bytes_left) { |
| 1508 | status = -EIO; |
| 1509 | mlog_errno(status); |
| 1510 | goto bail; |
| 1511 | } |
| 1512 | |
| 1513 | virtual = 0; |
| 1514 | while(bytes_left > 0) { |
| 1515 | c = &symname[virtual * sb->s_blocksize]; |
| 1516 | |
| 1517 | bhs[virtual] = sb_getblk(sb, p_blkno); |
| 1518 | if (!bhs[virtual]) { |
| 1519 | status = -ENOMEM; |
| 1520 | mlog_errno(status); |
| 1521 | goto bail; |
| 1522 | } |
Joel Becker | 8cb471e | 2009-02-10 20:00:41 -0800 | [diff] [blame] | 1523 | ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), |
| 1524 | bhs[virtual]); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1525 | |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 1526 | status = ocfs2_journal_access(handle, INODE_CACHE(inode), |
| 1527 | bhs[virtual], |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1528 | OCFS2_JOURNAL_ACCESS_CREATE); |
| 1529 | if (status < 0) { |
| 1530 | mlog_errno(status); |
| 1531 | goto bail; |
| 1532 | } |
| 1533 | |
| 1534 | memset(bhs[virtual]->b_data, 0, sb->s_blocksize); |
| 1535 | |
| 1536 | memcpy(bhs[virtual]->b_data, c, |
| 1537 | (bytes_left > sb->s_blocksize) ? sb->s_blocksize : |
| 1538 | bytes_left); |
| 1539 | |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 1540 | ocfs2_journal_dirty(handle, bhs[virtual]); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1541 | |
| 1542 | virtual++; |
| 1543 | p_blkno++; |
| 1544 | bytes_left -= sb->s_blocksize; |
| 1545 | } |
| 1546 | |
| 1547 | status = 0; |
| 1548 | bail: |
| 1549 | |
| 1550 | if (bhs) { |
| 1551 | for(i = 0; i < blocks; i++) |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 1552 | brelse(bhs[i]); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1553 | kfree(bhs); |
| 1554 | } |
| 1555 | |
| 1556 | mlog_exit(status); |
| 1557 | return status; |
| 1558 | } |
| 1559 | |
| 1560 | static int ocfs2_symlink(struct inode *dir, |
| 1561 | struct dentry *dentry, |
| 1562 | const char *symname) |
| 1563 | { |
| 1564 | int status, l, credits; |
| 1565 | u64 newsize; |
| 1566 | struct ocfs2_super *osb = NULL; |
| 1567 | struct inode *inode = NULL; |
| 1568 | struct super_block *sb; |
| 1569 | struct buffer_head *new_fe_bh = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1570 | struct buffer_head *parent_fe_bh = NULL; |
| 1571 | struct ocfs2_dinode *fe = NULL; |
| 1572 | struct ocfs2_dinode *dirfe; |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 1573 | handle_t *handle = NULL; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1574 | struct ocfs2_alloc_context *inode_ac = NULL; |
| 1575 | struct ocfs2_alloc_context *data_ac = NULL; |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 1576 | struct ocfs2_alloc_context *xattr_ac = NULL; |
| 1577 | int want_clusters = 0; |
| 1578 | int xattr_credits = 0; |
| 1579 | struct ocfs2_security_xattr_info si = { |
| 1580 | .enable = 1, |
| 1581 | }; |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 1582 | int did_quota = 0, did_quota_inode = 0; |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1583 | struct ocfs2_dir_lookup_result lookup = { NULL, }; |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 1584 | sigset_t oldset; |
| 1585 | int did_block_signals = 0; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1586 | |
| 1587 | mlog_entry("(0x%p, 0x%p, symname='%s' actual='%.*s')\n", dir, |
| 1588 | dentry, symname, dentry->d_name.len, dentry->d_name.name); |
| 1589 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1590 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1591 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1592 | sb = dir->i_sb; |
| 1593 | osb = OCFS2_SB(sb); |
| 1594 | |
| 1595 | l = strlen(symname) + 1; |
| 1596 | |
| 1597 | credits = ocfs2_calc_symlink_credits(sb); |
| 1598 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1599 | /* lock the parent directory */ |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1600 | status = ocfs2_inode_lock(dir, &parent_fe_bh, 1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1601 | if (status < 0) { |
| 1602 | if (status != -ENOENT) |
| 1603 | mlog_errno(status); |
Mark Fasheh | 6d8fc40 | 2006-10-06 11:54:33 -0700 | [diff] [blame] | 1604 | return status; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data; |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 1608 | if (!ocfs2_read_links_count(dirfe)) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1609 | /* can't make a file in a deleted directory. */ |
| 1610 | status = -ENOENT; |
| 1611 | goto bail; |
| 1612 | } |
| 1613 | |
| 1614 | status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name, |
| 1615 | dentry->d_name.len); |
| 1616 | if (status) |
| 1617 | goto bail; |
| 1618 | |
| 1619 | status = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh, |
| 1620 | dentry->d_name.name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1621 | dentry->d_name.len, &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1622 | if (status < 0) { |
| 1623 | mlog_errno(status); |
| 1624 | goto bail; |
| 1625 | } |
| 1626 | |
Mark Fasheh | da5cbf2 | 2006-10-06 18:34:35 -0700 | [diff] [blame] | 1627 | status = ocfs2_reserve_new_inode(osb, &inode_ac); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1628 | if (status < 0) { |
| 1629 | if (status != -ENOSPC) |
| 1630 | mlog_errno(status); |
| 1631 | goto bail; |
| 1632 | } |
| 1633 | |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 1634 | inode = ocfs2_get_init_inode(dir, S_IFLNK | S_IRWXUGO); |
| 1635 | if (!inode) { |
| 1636 | status = -ENOMEM; |
| 1637 | mlog_errno(status); |
| 1638 | goto bail; |
| 1639 | } |
| 1640 | |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 1641 | /* get security xattr */ |
| 1642 | status = ocfs2_init_security_get(inode, dir, &si); |
| 1643 | if (status) { |
| 1644 | if (status == -EOPNOTSUPP) |
| 1645 | si.enable = 0; |
| 1646 | else { |
| 1647 | mlog_errno(status); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1648 | goto bail; |
| 1649 | } |
| 1650 | } |
| 1651 | |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 1652 | /* calculate meta data/clusters for setting security xattr */ |
| 1653 | if (si.enable) { |
| 1654 | status = ocfs2_calc_security_init(dir, &si, &want_clusters, |
| 1655 | &xattr_credits, &xattr_ac); |
| 1656 | if (status < 0) { |
| 1657 | mlog_errno(status); |
| 1658 | goto bail; |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | /* don't reserve bitmap space for fast symlinks. */ |
| 1663 | if (l > ocfs2_fast_symlink_chars(sb)) |
| 1664 | want_clusters += 1; |
| 1665 | |
| 1666 | status = ocfs2_reserve_clusters(osb, want_clusters, &data_ac); |
| 1667 | if (status < 0) { |
| 1668 | if (status != -ENOSPC) |
| 1669 | mlog_errno(status); |
| 1670 | goto bail; |
| 1671 | } |
| 1672 | |
| 1673 | handle = ocfs2_start_trans(osb, credits + xattr_credits); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1674 | if (IS_ERR(handle)) { |
| 1675 | status = PTR_ERR(handle); |
| 1676 | handle = NULL; |
| 1677 | mlog_errno(status); |
| 1678 | goto bail; |
| 1679 | } |
| 1680 | |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 1681 | /* Starting to change things, restart is no longer possible. */ |
| 1682 | ocfs2_block_signals(&oldset); |
| 1683 | did_block_signals = 1; |
| 1684 | |
Christoph Hellwig | 63936dd | 2010-03-03 09:05:01 -0500 | [diff] [blame] | 1685 | status = dquot_alloc_inode(inode); |
| 1686 | if (status) |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 1687 | goto bail; |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 1688 | did_quota_inode = 1; |
| 1689 | |
Tao Ma | 19bd341 | 2009-08-18 11:44:10 +0800 | [diff] [blame] | 1690 | mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, |
| 1691 | inode->i_mode, dentry->d_name.len, |
| 1692 | dentry->d_name.name); |
| 1693 | |
| 1694 | status = ocfs2_mknod_locked(osb, dir, inode, |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 1695 | 0, &new_fe_bh, parent_fe_bh, handle, |
| 1696 | inode_ac); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1697 | if (status < 0) { |
| 1698 | mlog_errno(status); |
| 1699 | goto bail; |
| 1700 | } |
| 1701 | |
| 1702 | fe = (struct ocfs2_dinode *) new_fe_bh->b_data; |
| 1703 | inode->i_rdev = 0; |
| 1704 | newsize = l - 1; |
| 1705 | if (l > ocfs2_fast_symlink_chars(sb)) { |
Mark Fasheh | dcd0538 | 2007-01-16 11:32:23 -0800 | [diff] [blame] | 1706 | u32 offset = 0; |
| 1707 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1708 | inode->i_op = &ocfs2_symlink_inode_operations; |
Christoph Hellwig | 5dd4056 | 2010-03-03 09:05:00 -0500 | [diff] [blame] | 1709 | status = dquot_alloc_space_nodirty(inode, |
| 1710 | ocfs2_clusters_to_bytes(osb->sb, 1)); |
| 1711 | if (status) |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 1712 | goto bail; |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 1713 | did_quota = 1; |
Tao Ma | 0eb8d47e | 2008-08-18 17:38:45 +0800 | [diff] [blame] | 1714 | status = ocfs2_add_inode_data(osb, inode, &offset, 1, 0, |
| 1715 | new_fe_bh, |
| 1716 | handle, data_ac, NULL, |
| 1717 | NULL); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1718 | if (status < 0) { |
| 1719 | if (status != -ENOSPC && status != -EINTR) { |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1720 | mlog(ML_ERROR, |
| 1721 | "Failed to extend file to %llu\n", |
| 1722 | (unsigned long long)newsize); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1723 | mlog_errno(status); |
| 1724 | status = -ENOSPC; |
| 1725 | } |
| 1726 | goto bail; |
| 1727 | } |
| 1728 | i_size_write(inode, newsize); |
Mark Fasheh | 8110b07 | 2007-03-22 16:53:23 -0700 | [diff] [blame] | 1729 | inode->i_blocks = ocfs2_inode_sector_count(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1730 | } else { |
| 1731 | inode->i_op = &ocfs2_fast_symlink_inode_operations; |
| 1732 | memcpy((char *) fe->id2.i_symlink, symname, l); |
| 1733 | i_size_write(inode, newsize); |
| 1734 | inode->i_blocks = 0; |
| 1735 | } |
| 1736 | |
| 1737 | status = ocfs2_mark_inode_dirty(handle, inode, new_fe_bh); |
| 1738 | if (status < 0) { |
| 1739 | mlog_errno(status); |
| 1740 | goto bail; |
| 1741 | } |
| 1742 | |
| 1743 | if (!ocfs2_inode_is_fast_symlink(inode)) { |
| 1744 | status = ocfs2_create_symlink_data(osb, handle, inode, |
| 1745 | symname); |
| 1746 | if (status < 0) { |
| 1747 | mlog_errno(status); |
| 1748 | goto bail; |
| 1749 | } |
| 1750 | } |
| 1751 | |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 1752 | if (si.enable) { |
| 1753 | status = ocfs2_init_security_set(handle, inode, new_fe_bh, &si, |
| 1754 | xattr_ac, data_ac); |
| 1755 | if (status < 0) { |
| 1756 | mlog_errno(status); |
| 1757 | goto bail; |
| 1758 | } |
| 1759 | } |
| 1760 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1761 | status = ocfs2_add_entry(handle, dentry, inode, |
| 1762 | le64_to_cpu(fe->i_blkno), parent_fe_bh, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1763 | &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1764 | if (status < 0) { |
| 1765 | mlog_errno(status); |
| 1766 | goto bail; |
| 1767 | } |
| 1768 | |
Mark Fasheh | 0027dd5 | 2006-09-21 16:51:28 -0700 | [diff] [blame] | 1769 | status = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno); |
Mark Fasheh | 379dfe9 | 2006-09-08 14:21:03 -0700 | [diff] [blame] | 1770 | if (status) { |
| 1771 | mlog_errno(status); |
| 1772 | goto bail; |
| 1773 | } |
| 1774 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1775 | insert_inode_hash(inode); |
| 1776 | dentry->d_op = &ocfs2_dentry_ops; |
| 1777 | d_instantiate(dentry, inode); |
| 1778 | bail: |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 1779 | if (status < 0 && did_quota) |
Christoph Hellwig | 5dd4056 | 2010-03-03 09:05:00 -0500 | [diff] [blame] | 1780 | dquot_free_space_nodirty(inode, |
Jan Kara | a90714c | 2008-10-09 19:38:40 +0200 | [diff] [blame] | 1781 | ocfs2_clusters_to_bytes(osb->sb, 1)); |
| 1782 | if (status < 0 && did_quota_inode) |
Christoph Hellwig | 63936dd | 2010-03-03 09:05:01 -0500 | [diff] [blame] | 1783 | dquot_free_inode(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1784 | if (handle) |
Mark Fasheh | 02dc1af | 2006-10-09 16:48:10 -0700 | [diff] [blame] | 1785 | ocfs2_commit_trans(osb, handle); |
Mark Fasheh | 6d8fc40 | 2006-10-06 11:54:33 -0700 | [diff] [blame] | 1786 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1787 | ocfs2_inode_unlock(dir, 1); |
Joel Becker | 547ba7c | 2010-05-10 11:56:52 -0700 | [diff] [blame^] | 1788 | if (did_block_signals) |
| 1789 | ocfs2_unblock_signals(&oldset); |
Mark Fasheh | 6d8fc40 | 2006-10-06 11:54:33 -0700 | [diff] [blame] | 1790 | |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 1791 | brelse(new_fe_bh); |
| 1792 | brelse(parent_fe_bh); |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 1793 | kfree(si.name); |
| 1794 | kfree(si.value); |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1795 | ocfs2_free_dir_lookup_result(&lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1796 | if (inode_ac) |
| 1797 | ocfs2_free_alloc_context(inode_ac); |
| 1798 | if (data_ac) |
| 1799 | ocfs2_free_alloc_context(data_ac); |
Tiger Yang | 534eadd | 2008-11-14 11:16:41 +0800 | [diff] [blame] | 1800 | if (xattr_ac) |
| 1801 | ocfs2_free_alloc_context(xattr_ac); |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 1802 | if ((status < 0) && inode) { |
| 1803 | clear_nlink(inode); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1804 | iput(inode); |
Tiger Yang | f5d3620 | 2008-11-14 11:15:44 +0800 | [diff] [blame] | 1805 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1806 | |
| 1807 | mlog_exit(status); |
| 1808 | |
| 1809 | return status; |
| 1810 | } |
| 1811 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1812 | static int ocfs2_blkno_stringify(u64 blkno, char *name) |
| 1813 | { |
| 1814 | int status, namelen; |
| 1815 | |
| 1816 | mlog_entry_void(); |
| 1817 | |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1818 | namelen = snprintf(name, OCFS2_ORPHAN_NAMELEN + 1, "%016llx", |
| 1819 | (long long)blkno); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1820 | if (namelen <= 0) { |
| 1821 | if (namelen) |
| 1822 | status = namelen; |
| 1823 | else |
| 1824 | status = -EINVAL; |
| 1825 | mlog_errno(status); |
| 1826 | goto bail; |
| 1827 | } |
| 1828 | if (namelen != OCFS2_ORPHAN_NAMELEN) { |
| 1829 | status = -EINVAL; |
| 1830 | mlog_errno(status); |
| 1831 | goto bail; |
| 1832 | } |
| 1833 | |
| 1834 | mlog(0, "built filename '%s' for orphan dir (len=%d)\n", name, |
| 1835 | namelen); |
| 1836 | |
| 1837 | status = 0; |
| 1838 | bail: |
| 1839 | mlog_exit(status); |
| 1840 | return status; |
| 1841 | } |
| 1842 | |
| 1843 | static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb, |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1844 | struct inode **ret_orphan_dir, |
Tao Ma | 19bd341 | 2009-08-18 11:44:10 +0800 | [diff] [blame] | 1845 | u64 blkno, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1846 | char *name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1847 | struct ocfs2_dir_lookup_result *lookup) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1848 | { |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1849 | struct inode *orphan_dir_inode; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1850 | struct buffer_head *orphan_dir_bh = NULL; |
| 1851 | int status = 0; |
| 1852 | |
Tao Ma | 19bd341 | 2009-08-18 11:44:10 +0800 | [diff] [blame] | 1853 | status = ocfs2_blkno_stringify(blkno, name); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1854 | if (status < 0) { |
| 1855 | mlog_errno(status); |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1856 | return status; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | orphan_dir_inode = ocfs2_get_system_file_inode(osb, |
| 1860 | ORPHAN_DIR_SYSTEM_INODE, |
| 1861 | osb->slot_num); |
| 1862 | if (!orphan_dir_inode) { |
| 1863 | status = -ENOENT; |
| 1864 | mlog_errno(status); |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1865 | return status; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1866 | } |
| 1867 | |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1868 | mutex_lock(&orphan_dir_inode->i_mutex); |
| 1869 | |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1870 | status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1871 | if (status < 0) { |
| 1872 | mlog_errno(status); |
| 1873 | goto leave; |
| 1874 | } |
| 1875 | |
| 1876 | status = ocfs2_prepare_dir_for_insert(osb, orphan_dir_inode, |
| 1877 | orphan_dir_bh, name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1878 | OCFS2_ORPHAN_NAMELEN, lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1879 | if (status < 0) { |
Mark Fasheh | e63aecb6 | 2007-10-18 15:30:42 -0700 | [diff] [blame] | 1880 | ocfs2_inode_unlock(orphan_dir_inode, 1); |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1881 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1882 | mlog_errno(status); |
| 1883 | goto leave; |
| 1884 | } |
| 1885 | |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1886 | *ret_orphan_dir = orphan_dir_inode; |
| 1887 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1888 | leave: |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1889 | if (status) { |
| 1890 | mutex_unlock(&orphan_dir_inode->i_mutex); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1891 | iput(orphan_dir_inode); |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1892 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1893 | |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 1894 | brelse(orphan_dir_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1895 | |
| 1896 | mlog_exit(status); |
| 1897 | return status; |
| 1898 | } |
| 1899 | |
| 1900 | static int ocfs2_orphan_add(struct ocfs2_super *osb, |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 1901 | handle_t *handle, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1902 | struct inode *inode, |
| 1903 | struct ocfs2_dinode *fe, |
| 1904 | char *name, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1905 | struct ocfs2_dir_lookup_result *lookup, |
Mark Fasheh | 5098c27 | 2006-10-05 18:12:57 -0700 | [diff] [blame] | 1906 | struct inode *orphan_dir_inode) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1907 | { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1908 | struct buffer_head *orphan_dir_bh = NULL; |
| 1909 | int status = 0; |
| 1910 | struct ocfs2_dinode *orphan_fe; |
| 1911 | |
| 1912 | mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino); |
| 1913 | |
Joel Becker | b657c95 | 2008-11-13 14:49:11 -0800 | [diff] [blame] | 1914 | status = ocfs2_read_inode_block(orphan_dir_inode, &orphan_dir_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1915 | if (status < 0) { |
| 1916 | mlog_errno(status); |
| 1917 | goto leave; |
| 1918 | } |
| 1919 | |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 1920 | status = ocfs2_journal_access_di(handle, |
| 1921 | INODE_CACHE(orphan_dir_inode), |
| 1922 | orphan_dir_bh, |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 1923 | OCFS2_JOURNAL_ACCESS_WRITE); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1924 | if (status < 0) { |
| 1925 | mlog_errno(status); |
| 1926 | goto leave; |
| 1927 | } |
| 1928 | |
| 1929 | /* we're a cluster, and nlink can change on disk from |
| 1930 | * underneath us... */ |
| 1931 | orphan_fe = (struct ocfs2_dinode *) orphan_dir_bh->b_data; |
| 1932 | if (S_ISDIR(inode->i_mode)) |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 1933 | ocfs2_add_links_count(orphan_fe, 1); |
| 1934 | orphan_dir_inode->i_nlink = ocfs2_read_links_count(orphan_fe); |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 1935 | ocfs2_journal_dirty(handle, orphan_dir_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1936 | |
| 1937 | status = __ocfs2_add_entry(handle, orphan_dir_inode, name, |
| 1938 | OCFS2_ORPHAN_NAMELEN, inode, |
| 1939 | OCFS2_I(inode)->ip_blkno, |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1940 | orphan_dir_bh, lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1941 | if (status < 0) { |
| 1942 | mlog_errno(status); |
| 1943 | goto leave; |
| 1944 | } |
| 1945 | |
| 1946 | le32_add_cpu(&fe->i_flags, OCFS2_ORPHANED_FL); |
| 1947 | |
| 1948 | /* Record which orphan dir our inode now resides |
| 1949 | * in. delete_inode will use this to determine which orphan |
| 1950 | * dir to lock. */ |
Tiger Yang | 5000863 | 2007-03-20 16:01:38 -0700 | [diff] [blame] | 1951 | fe->i_orphaned_slot = cpu_to_le16(osb->slot_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1952 | |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1953 | mlog(0, "Inode %llu orphaned in slot %d\n", |
| 1954 | (unsigned long long)OCFS2_I(inode)->ip_blkno, osb->slot_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1955 | |
| 1956 | leave: |
Mark Fasheh | a81cb88 | 2008-10-07 14:25:16 -0700 | [diff] [blame] | 1957 | brelse(orphan_dir_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1958 | |
| 1959 | mlog_exit(status); |
| 1960 | return status; |
| 1961 | } |
| 1962 | |
| 1963 | /* unlike orphan_add, we expect the orphan dir to already be locked here. */ |
| 1964 | int ocfs2_orphan_del(struct ocfs2_super *osb, |
Mark Fasheh | 1fabe14 | 2006-10-09 18:11:45 -0700 | [diff] [blame] | 1965 | handle_t *handle, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1966 | struct inode *orphan_dir_inode, |
| 1967 | struct inode *inode, |
| 1968 | struct buffer_head *orphan_dir_bh) |
| 1969 | { |
| 1970 | char name[OCFS2_ORPHAN_NAMELEN + 1]; |
| 1971 | struct ocfs2_dinode *orphan_fe; |
| 1972 | int status = 0; |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1973 | struct ocfs2_dir_lookup_result lookup = { NULL, }; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1974 | |
| 1975 | mlog_entry_void(); |
| 1976 | |
| 1977 | status = ocfs2_blkno_stringify(OCFS2_I(inode)->ip_blkno, name); |
| 1978 | if (status < 0) { |
| 1979 | mlog_errno(status); |
| 1980 | goto leave; |
| 1981 | } |
| 1982 | |
Mark Fasheh | b0697053 | 2006-03-03 10:24:33 -0800 | [diff] [blame] | 1983 | mlog(0, "removing '%s' from orphan dir %llu (namelen=%d)\n", |
| 1984 | name, (unsigned long long)OCFS2_I(orphan_dir_inode)->ip_blkno, |
| 1985 | OCFS2_ORPHAN_NAMELEN); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1986 | |
| 1987 | /* find it's spot in the orphan directory */ |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1988 | status = ocfs2_find_entry(name, OCFS2_ORPHAN_NAMELEN, orphan_dir_inode, |
| 1989 | &lookup); |
| 1990 | if (status) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1991 | mlog_errno(status); |
| 1992 | goto leave; |
| 1993 | } |
| 1994 | |
| 1995 | /* remove it from the orphan directory */ |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 1996 | status = ocfs2_delete_entry(handle, orphan_dir_inode, &lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1997 | if (status < 0) { |
| 1998 | mlog_errno(status); |
| 1999 | goto leave; |
| 2000 | } |
| 2001 | |
Joel Becker | 0cf2f76 | 2009-02-12 16:41:25 -0800 | [diff] [blame] | 2002 | status = ocfs2_journal_access_di(handle, |
| 2003 | INODE_CACHE(orphan_dir_inode), |
| 2004 | orphan_dir_bh, |
Joel Becker | 13723d0 | 2008-10-17 19:25:01 -0700 | [diff] [blame] | 2005 | OCFS2_JOURNAL_ACCESS_WRITE); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2006 | if (status < 0) { |
| 2007 | mlog_errno(status); |
| 2008 | goto leave; |
| 2009 | } |
| 2010 | |
| 2011 | /* do the i_nlink dance! :) */ |
| 2012 | orphan_fe = (struct ocfs2_dinode *) orphan_dir_bh->b_data; |
| 2013 | if (S_ISDIR(inode->i_mode)) |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 2014 | ocfs2_add_links_count(orphan_fe, -1); |
| 2015 | orphan_dir_inode->i_nlink = ocfs2_read_links_count(orphan_fe); |
Joel Becker | ec20cec | 2010-03-19 14:13:52 -0700 | [diff] [blame] | 2016 | ocfs2_journal_dirty(handle, orphan_dir_bh); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2017 | |
| 2018 | leave: |
Mark Fasheh | 4a12ca3 | 2008-11-12 15:43:34 -0800 | [diff] [blame] | 2019 | ocfs2_free_dir_lookup_result(&lookup); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2020 | |
| 2021 | mlog_exit(status); |
| 2022 | return status; |
| 2023 | } |
| 2024 | |
Tao Ma | bc13d34 | 2009-08-18 11:44:14 +0800 | [diff] [blame] | 2025 | int ocfs2_create_inode_in_orphan(struct inode *dir, |
| 2026 | int mode, |
| 2027 | struct inode **new_inode) |
| 2028 | { |
| 2029 | int status, did_quota_inode = 0; |
| 2030 | struct inode *inode = NULL; |
| 2031 | struct inode *orphan_dir = NULL; |
| 2032 | struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); |
| 2033 | struct ocfs2_dinode *di = NULL; |
| 2034 | handle_t *handle = NULL; |
| 2035 | char orphan_name[OCFS2_ORPHAN_NAMELEN + 1]; |
| 2036 | struct buffer_head *parent_di_bh = NULL; |
| 2037 | struct buffer_head *new_di_bh = NULL; |
| 2038 | struct ocfs2_alloc_context *inode_ac = NULL; |
| 2039 | struct ocfs2_dir_lookup_result orphan_insert = { NULL, }; |
| 2040 | |
| 2041 | status = ocfs2_inode_lock(dir, &parent_di_bh, 1); |
| 2042 | if (status < 0) { |
| 2043 | if (status != -ENOENT) |
| 2044 | mlog_errno(status); |
| 2045 | return status; |
| 2046 | } |
| 2047 | |
| 2048 | /* |
| 2049 | * We give the orphan dir the root blkno to fake an orphan name, |
| 2050 | * and allocate enough space for our insertion. |
| 2051 | */ |
| 2052 | status = ocfs2_prepare_orphan_dir(osb, &orphan_dir, |
| 2053 | osb->root_blkno, |
| 2054 | orphan_name, &orphan_insert); |
| 2055 | if (status < 0) { |
| 2056 | mlog_errno(status); |
| 2057 | goto leave; |
| 2058 | } |
| 2059 | |
| 2060 | /* reserve an inode spot */ |
| 2061 | status = ocfs2_reserve_new_inode(osb, &inode_ac); |
| 2062 | if (status < 0) { |
| 2063 | if (status != -ENOSPC) |
| 2064 | mlog_errno(status); |
| 2065 | goto leave; |
| 2066 | } |
| 2067 | |
| 2068 | inode = ocfs2_get_init_inode(dir, mode); |
| 2069 | if (!inode) { |
| 2070 | status = -ENOMEM; |
| 2071 | mlog_errno(status); |
| 2072 | goto leave; |
| 2073 | } |
| 2074 | |
| 2075 | handle = ocfs2_start_trans(osb, ocfs2_mknod_credits(osb->sb, 0, 0)); |
| 2076 | if (IS_ERR(handle)) { |
| 2077 | status = PTR_ERR(handle); |
| 2078 | handle = NULL; |
| 2079 | mlog_errno(status); |
| 2080 | goto leave; |
| 2081 | } |
| 2082 | |
Christoph Hellwig | 63936dd | 2010-03-03 09:05:01 -0500 | [diff] [blame] | 2083 | status = dquot_alloc_inode(inode); |
| 2084 | if (status) |
Tao Ma | bc13d34 | 2009-08-18 11:44:14 +0800 | [diff] [blame] | 2085 | goto leave; |
Tao Ma | bc13d34 | 2009-08-18 11:44:14 +0800 | [diff] [blame] | 2086 | did_quota_inode = 1; |
| 2087 | |
Tao Ma | 10cf1a0 | 2009-12-18 10:24:55 +0800 | [diff] [blame] | 2088 | inode->i_nlink = 0; |
Tao Ma | bc13d34 | 2009-08-18 11:44:14 +0800 | [diff] [blame] | 2089 | /* do the real work now. */ |
| 2090 | status = ocfs2_mknod_locked(osb, dir, inode, |
| 2091 | 0, &new_di_bh, parent_di_bh, handle, |
| 2092 | inode_ac); |
| 2093 | if (status < 0) { |
| 2094 | mlog_errno(status); |
| 2095 | goto leave; |
| 2096 | } |
| 2097 | |
| 2098 | status = ocfs2_blkno_stringify(OCFS2_I(inode)->ip_blkno, orphan_name); |
| 2099 | if (status < 0) { |
| 2100 | mlog_errno(status); |
| 2101 | goto leave; |
| 2102 | } |
| 2103 | |
| 2104 | di = (struct ocfs2_dinode *)new_di_bh->b_data; |
| 2105 | status = ocfs2_orphan_add(osb, handle, inode, di, orphan_name, |
| 2106 | &orphan_insert, orphan_dir); |
| 2107 | if (status < 0) { |
| 2108 | mlog_errno(status); |
| 2109 | goto leave; |
| 2110 | } |
| 2111 | |
| 2112 | /* get open lock so that only nodes can't remove it from orphan dir. */ |
| 2113 | status = ocfs2_open_lock(inode); |
| 2114 | if (status < 0) |
| 2115 | mlog_errno(status); |
| 2116 | |
Tao Ma | c7d260a | 2009-12-18 10:24:54 +0800 | [diff] [blame] | 2117 | insert_inode_hash(inode); |
Tao Ma | bc13d34 | 2009-08-18 11:44:14 +0800 | [diff] [blame] | 2118 | leave: |
| 2119 | if (status < 0 && did_quota_inode) |
Christoph Hellwig | 63936dd | 2010-03-03 09:05:01 -0500 | [diff] [blame] | 2120 | dquot_free_inode(inode); |
Tao Ma | bc13d34 | 2009-08-18 11:44:14 +0800 | [diff] [blame] | 2121 | if (handle) |
| 2122 | ocfs2_commit_trans(osb, handle); |
| 2123 | |
| 2124 | if (orphan_dir) { |
| 2125 | /* This was locked for us in ocfs2_prepare_orphan_dir() */ |
| 2126 | ocfs2_inode_unlock(orphan_dir, 1); |
| 2127 | mutex_unlock(&orphan_dir->i_mutex); |
| 2128 | iput(orphan_dir); |
| 2129 | } |
| 2130 | |
| 2131 | if (status == -ENOSPC) |
| 2132 | mlog(0, "Disk is full\n"); |
| 2133 | |
| 2134 | if ((status < 0) && inode) { |
| 2135 | clear_nlink(inode); |
| 2136 | iput(inode); |
| 2137 | } |
| 2138 | |
| 2139 | if (inode_ac) |
| 2140 | ocfs2_free_alloc_context(inode_ac); |
| 2141 | |
| 2142 | brelse(new_di_bh); |
| 2143 | |
| 2144 | if (!status) |
| 2145 | *new_inode = inode; |
| 2146 | |
| 2147 | ocfs2_free_dir_lookup_result(&orphan_insert); |
| 2148 | |
| 2149 | ocfs2_inode_unlock(dir, 1); |
| 2150 | brelse(parent_di_bh); |
| 2151 | return status; |
| 2152 | } |
| 2153 | |
| 2154 | int ocfs2_mv_orphaned_inode_to_new(struct inode *dir, |
| 2155 | struct inode *inode, |
| 2156 | struct dentry *dentry) |
| 2157 | { |
| 2158 | int status = 0; |
| 2159 | struct buffer_head *parent_di_bh = NULL; |
| 2160 | handle_t *handle = NULL; |
| 2161 | struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); |
| 2162 | struct ocfs2_dinode *dir_di, *di; |
| 2163 | struct inode *orphan_dir_inode = NULL; |
| 2164 | struct buffer_head *orphan_dir_bh = NULL; |
| 2165 | struct buffer_head *di_bh = NULL; |
| 2166 | struct ocfs2_dir_lookup_result lookup = { NULL, }; |
| 2167 | |
| 2168 | mlog_entry("(0x%p, 0x%p, %.*s')\n", dir, dentry, |
| 2169 | dentry->d_name.len, dentry->d_name.name); |
| 2170 | |
| 2171 | status = ocfs2_inode_lock(dir, &parent_di_bh, 1); |
| 2172 | if (status < 0) { |
| 2173 | if (status != -ENOENT) |
| 2174 | mlog_errno(status); |
| 2175 | return status; |
| 2176 | } |
| 2177 | |
| 2178 | dir_di = (struct ocfs2_dinode *) parent_di_bh->b_data; |
| 2179 | if (!dir_di->i_links_count) { |
| 2180 | /* can't make a file in a deleted directory. */ |
| 2181 | status = -ENOENT; |
| 2182 | goto leave; |
| 2183 | } |
| 2184 | |
| 2185 | status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name, |
| 2186 | dentry->d_name.len); |
| 2187 | if (status) |
| 2188 | goto leave; |
| 2189 | |
| 2190 | /* get a spot inside the dir. */ |
| 2191 | status = ocfs2_prepare_dir_for_insert(osb, dir, parent_di_bh, |
| 2192 | dentry->d_name.name, |
| 2193 | dentry->d_name.len, &lookup); |
| 2194 | if (status < 0) { |
| 2195 | mlog_errno(status); |
| 2196 | goto leave; |
| 2197 | } |
| 2198 | |
| 2199 | orphan_dir_inode = ocfs2_get_system_file_inode(osb, |
| 2200 | ORPHAN_DIR_SYSTEM_INODE, |
| 2201 | osb->slot_num); |
| 2202 | if (!orphan_dir_inode) { |
| 2203 | status = -EEXIST; |
| 2204 | mlog_errno(status); |
| 2205 | goto leave; |
| 2206 | } |
| 2207 | |
| 2208 | mutex_lock(&orphan_dir_inode->i_mutex); |
| 2209 | |
| 2210 | status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1); |
| 2211 | if (status < 0) { |
| 2212 | mlog_errno(status); |
| 2213 | mutex_unlock(&orphan_dir_inode->i_mutex); |
| 2214 | iput(orphan_dir_inode); |
| 2215 | goto leave; |
| 2216 | } |
| 2217 | |
| 2218 | status = ocfs2_read_inode_block(inode, &di_bh); |
| 2219 | if (status < 0) { |
| 2220 | mlog_errno(status); |
| 2221 | goto orphan_unlock; |
| 2222 | } |
| 2223 | |
| 2224 | handle = ocfs2_start_trans(osb, ocfs2_rename_credits(osb->sb)); |
| 2225 | if (IS_ERR(handle)) { |
| 2226 | status = PTR_ERR(handle); |
| 2227 | handle = NULL; |
| 2228 | mlog_errno(status); |
| 2229 | goto orphan_unlock; |
| 2230 | } |
| 2231 | |
| 2232 | status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), |
| 2233 | di_bh, OCFS2_JOURNAL_ACCESS_WRITE); |
| 2234 | if (status < 0) { |
| 2235 | mlog_errno(status); |
| 2236 | goto out_commit; |
| 2237 | } |
| 2238 | |
| 2239 | status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode, |
| 2240 | orphan_dir_bh); |
| 2241 | if (status < 0) { |
| 2242 | mlog_errno(status); |
| 2243 | goto out_commit; |
| 2244 | } |
| 2245 | |
| 2246 | di = (struct ocfs2_dinode *)di_bh->b_data; |
| 2247 | le32_add_cpu(&di->i_flags, -OCFS2_ORPHANED_FL); |
| 2248 | di->i_orphaned_slot = 0; |
Tao Ma | 10cf1a0 | 2009-12-18 10:24:55 +0800 | [diff] [blame] | 2249 | inode->i_nlink = 1; |
| 2250 | ocfs2_set_links_count(di, inode->i_nlink); |
Tao Ma | bc13d34 | 2009-08-18 11:44:14 +0800 | [diff] [blame] | 2251 | ocfs2_journal_dirty(handle, di_bh); |
| 2252 | |
| 2253 | status = ocfs2_add_entry(handle, dentry, inode, |
| 2254 | OCFS2_I(inode)->ip_blkno, parent_di_bh, |
| 2255 | &lookup); |
| 2256 | if (status < 0) { |
| 2257 | mlog_errno(status); |
| 2258 | goto out_commit; |
| 2259 | } |
| 2260 | |
| 2261 | status = ocfs2_dentry_attach_lock(dentry, inode, |
| 2262 | OCFS2_I(dir)->ip_blkno); |
| 2263 | if (status) { |
| 2264 | mlog_errno(status); |
| 2265 | goto out_commit; |
| 2266 | } |
| 2267 | |
Tao Ma | bc13d34 | 2009-08-18 11:44:14 +0800 | [diff] [blame] | 2268 | dentry->d_op = &ocfs2_dentry_ops; |
| 2269 | d_instantiate(dentry, inode); |
| 2270 | status = 0; |
| 2271 | out_commit: |
| 2272 | ocfs2_commit_trans(osb, handle); |
| 2273 | orphan_unlock: |
| 2274 | ocfs2_inode_unlock(orphan_dir_inode, 1); |
| 2275 | mutex_unlock(&orphan_dir_inode->i_mutex); |
| 2276 | iput(orphan_dir_inode); |
| 2277 | leave: |
| 2278 | |
| 2279 | ocfs2_inode_unlock(dir, 1); |
| 2280 | |
| 2281 | brelse(di_bh); |
| 2282 | brelse(parent_di_bh); |
| 2283 | brelse(orphan_dir_bh); |
| 2284 | |
| 2285 | ocfs2_free_dir_lookup_result(&lookup); |
| 2286 | |
| 2287 | mlog_exit(status); |
| 2288 | |
| 2289 | return status; |
| 2290 | } |
| 2291 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 2292 | const struct inode_operations ocfs2_dir_iops = { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2293 | .create = ocfs2_create, |
| 2294 | .lookup = ocfs2_lookup, |
| 2295 | .link = ocfs2_link, |
| 2296 | .unlink = ocfs2_unlink, |
| 2297 | .rmdir = ocfs2_unlink, |
| 2298 | .symlink = ocfs2_symlink, |
| 2299 | .mkdir = ocfs2_mkdir, |
| 2300 | .mknod = ocfs2_mknod, |
| 2301 | .rename = ocfs2_rename, |
| 2302 | .setattr = ocfs2_setattr, |
| 2303 | .getattr = ocfs2_getattr, |
Tiger Yang | d38eb8d | 2006-11-27 09:59:21 +0800 | [diff] [blame] | 2304 | .permission = ocfs2_permission, |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 2305 | .setxattr = generic_setxattr, |
| 2306 | .getxattr = generic_getxattr, |
| 2307 | .listxattr = ocfs2_listxattr, |
| 2308 | .removexattr = generic_removexattr, |
Tristan Ye | 55f4946 | 2009-12-17 18:42:16 +0800 | [diff] [blame] | 2309 | .fiemap = ocfs2_fiemap, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 2310 | }; |