@@ -3054,188 +3054,6 @@ bool ext4_empty_dir(struct inode *inode)
3054
3054
return true;
3055
3055
}
3056
3056
3057
- /*
3058
- * ext4_orphan_add() links an unlinked or truncated inode into a list of
3059
- * such inodes, starting at the superblock, in case we crash before the
3060
- * file is closed/deleted, or in case the inode truncate spans multiple
3061
- * transactions and the last transaction is not recovered after a crash.
3062
- *
3063
- * At filesystem recovery time, we walk this list deleting unlinked
3064
- * inodes and truncating linked inodes in ext4_orphan_cleanup().
3065
- *
3066
- * Orphan list manipulation functions must be called under i_mutex unless
3067
- * we are just creating the inode or deleting it.
3068
- */
3069
- int ext4_orphan_add (handle_t * handle , struct inode * inode )
3070
- {
3071
- struct super_block * sb = inode -> i_sb ;
3072
- struct ext4_sb_info * sbi = EXT4_SB (sb );
3073
- struct ext4_iloc iloc ;
3074
- int err = 0 , rc ;
3075
- bool dirty = false;
3076
-
3077
- if (!sbi -> s_journal || is_bad_inode (inode ))
3078
- return 0 ;
3079
-
3080
- WARN_ON_ONCE (!(inode -> i_state & (I_NEW | I_FREEING )) &&
3081
- !inode_is_locked (inode ));
3082
- /*
3083
- * Exit early if inode already is on orphan list. This is a big speedup
3084
- * since we don't have to contend on the global s_orphan_lock.
3085
- */
3086
- if (!list_empty (& EXT4_I (inode )-> i_orphan ))
3087
- return 0 ;
3088
-
3089
- /*
3090
- * Orphan handling is only valid for files with data blocks
3091
- * being truncated, or files being unlinked. Note that we either
3092
- * hold i_mutex, or the inode can not be referenced from outside,
3093
- * so i_nlink should not be bumped due to race
3094
- */
3095
- ASSERT ((S_ISREG (inode -> i_mode ) || S_ISDIR (inode -> i_mode ) ||
3096
- S_ISLNK (inode -> i_mode )) || inode -> i_nlink == 0 );
3097
-
3098
- BUFFER_TRACE (sbi -> s_sbh , "get_write_access" );
3099
- err = ext4_journal_get_write_access (handle , sb , sbi -> s_sbh ,
3100
- EXT4_JTR_NONE );
3101
- if (err )
3102
- goto out ;
3103
-
3104
- err = ext4_reserve_inode_write (handle , inode , & iloc );
3105
- if (err )
3106
- goto out ;
3107
-
3108
- mutex_lock (& sbi -> s_orphan_lock );
3109
- /*
3110
- * Due to previous errors inode may be already a part of on-disk
3111
- * orphan list. If so skip on-disk list modification.
3112
- */
3113
- if (!NEXT_ORPHAN (inode ) || NEXT_ORPHAN (inode ) >
3114
- (le32_to_cpu (sbi -> s_es -> s_inodes_count ))) {
3115
- /* Insert this inode at the head of the on-disk orphan list */
3116
- NEXT_ORPHAN (inode ) = le32_to_cpu (sbi -> s_es -> s_last_orphan );
3117
- lock_buffer (sbi -> s_sbh );
3118
- sbi -> s_es -> s_last_orphan = cpu_to_le32 (inode -> i_ino );
3119
- ext4_superblock_csum_set (sb );
3120
- unlock_buffer (sbi -> s_sbh );
3121
- dirty = true;
3122
- }
3123
- list_add (& EXT4_I (inode )-> i_orphan , & sbi -> s_orphan );
3124
- mutex_unlock (& sbi -> s_orphan_lock );
3125
-
3126
- if (dirty ) {
3127
- err = ext4_handle_dirty_metadata (handle , NULL , sbi -> s_sbh );
3128
- rc = ext4_mark_iloc_dirty (handle , inode , & iloc );
3129
- if (!err )
3130
- err = rc ;
3131
- if (err ) {
3132
- /*
3133
- * We have to remove inode from in-memory list if
3134
- * addition to on disk orphan list failed. Stray orphan
3135
- * list entries can cause panics at unmount time.
3136
- */
3137
- mutex_lock (& sbi -> s_orphan_lock );
3138
- list_del_init (& EXT4_I (inode )-> i_orphan );
3139
- mutex_unlock (& sbi -> s_orphan_lock );
3140
- }
3141
- } else
3142
- brelse (iloc .bh );
3143
-
3144
- jbd_debug (4 , "superblock will point to %lu\n" , inode -> i_ino );
3145
- jbd_debug (4 , "orphan inode %lu will point to %d\n" ,
3146
- inode -> i_ino , NEXT_ORPHAN (inode ));
3147
- out :
3148
- ext4_std_error (sb , err );
3149
- return err ;
3150
- }
3151
-
3152
- /*
3153
- * ext4_orphan_del() removes an unlinked or truncated inode from the list
3154
- * of such inodes stored on disk, because it is finally being cleaned up.
3155
- */
3156
- int ext4_orphan_del (handle_t * handle , struct inode * inode )
3157
- {
3158
- struct list_head * prev ;
3159
- struct ext4_inode_info * ei = EXT4_I (inode );
3160
- struct ext4_sb_info * sbi = EXT4_SB (inode -> i_sb );
3161
- __u32 ino_next ;
3162
- struct ext4_iloc iloc ;
3163
- int err = 0 ;
3164
-
3165
- if (!sbi -> s_journal && !(sbi -> s_mount_state & EXT4_ORPHAN_FS ))
3166
- return 0 ;
3167
-
3168
- WARN_ON_ONCE (!(inode -> i_state & (I_NEW | I_FREEING )) &&
3169
- !inode_is_locked (inode ));
3170
- /* Do this quick check before taking global s_orphan_lock. */
3171
- if (list_empty (& ei -> i_orphan ))
3172
- return 0 ;
3173
-
3174
- if (handle ) {
3175
- /* Grab inode buffer early before taking global s_orphan_lock */
3176
- err = ext4_reserve_inode_write (handle , inode , & iloc );
3177
- }
3178
-
3179
- mutex_lock (& sbi -> s_orphan_lock );
3180
- jbd_debug (4 , "remove inode %lu from orphan list\n" , inode -> i_ino );
3181
-
3182
- prev = ei -> i_orphan .prev ;
3183
- list_del_init (& ei -> i_orphan );
3184
-
3185
- /* If we're on an error path, we may not have a valid
3186
- * transaction handle with which to update the orphan list on
3187
- * disk, but we still need to remove the inode from the linked
3188
- * list in memory. */
3189
- if (!handle || err ) {
3190
- mutex_unlock (& sbi -> s_orphan_lock );
3191
- goto out_err ;
3192
- }
3193
-
3194
- ino_next = NEXT_ORPHAN (inode );
3195
- if (prev == & sbi -> s_orphan ) {
3196
- jbd_debug (4 , "superblock will point to %u\n" , ino_next );
3197
- BUFFER_TRACE (sbi -> s_sbh , "get_write_access" );
3198
- err = ext4_journal_get_write_access (handle , inode -> i_sb ,
3199
- sbi -> s_sbh , EXT4_JTR_NONE );
3200
- if (err ) {
3201
- mutex_unlock (& sbi -> s_orphan_lock );
3202
- goto out_brelse ;
3203
- }
3204
- lock_buffer (sbi -> s_sbh );
3205
- sbi -> s_es -> s_last_orphan = cpu_to_le32 (ino_next );
3206
- ext4_superblock_csum_set (inode -> i_sb );
3207
- unlock_buffer (sbi -> s_sbh );
3208
- mutex_unlock (& sbi -> s_orphan_lock );
3209
- err = ext4_handle_dirty_metadata (handle , NULL , sbi -> s_sbh );
3210
- } else {
3211
- struct ext4_iloc iloc2 ;
3212
- struct inode * i_prev =
3213
- & list_entry (prev , struct ext4_inode_info , i_orphan )-> vfs_inode ;
3214
-
3215
- jbd_debug (4 , "orphan inode %lu will point to %u\n" ,
3216
- i_prev -> i_ino , ino_next );
3217
- err = ext4_reserve_inode_write (handle , i_prev , & iloc2 );
3218
- if (err ) {
3219
- mutex_unlock (& sbi -> s_orphan_lock );
3220
- goto out_brelse ;
3221
- }
3222
- NEXT_ORPHAN (i_prev ) = ino_next ;
3223
- err = ext4_mark_iloc_dirty (handle , i_prev , & iloc2 );
3224
- mutex_unlock (& sbi -> s_orphan_lock );
3225
- }
3226
- if (err )
3227
- goto out_brelse ;
3228
- NEXT_ORPHAN (inode ) = 0 ;
3229
- err = ext4_mark_iloc_dirty (handle , inode , & iloc );
3230
- out_err :
3231
- ext4_std_error (inode -> i_sb , err );
3232
- return err ;
3233
-
3234
- out_brelse :
3235
- brelse (iloc .bh );
3236
- goto out_err ;
3237
- }
3238
-
3239
3057
static int ext4_rmdir (struct inode * dir , struct dentry * dentry )
3240
3058
{
3241
3059
int retval ;
0 commit comments