162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * linux/fs/ufs/ialloc.c 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (c) 1998 662306a36Sopenharmony_ci * Daniel Pirkl <daniel.pirkl@email.cz> 762306a36Sopenharmony_ci * Charles University, Faculty of Mathematics and Physics 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * from 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * linux/fs/ext2/ialloc.c 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * Copyright (C) 1992, 1993, 1994, 1995 1462306a36Sopenharmony_ci * Remy Card (card@masi.ibp.fr) 1562306a36Sopenharmony_ci * Laboratoire MASI - Institut Blaise Pascal 1662306a36Sopenharmony_ci * Universite Pierre et Marie Curie (Paris VI) 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * BSD ufs-inspired inode and directory allocation by 1962306a36Sopenharmony_ci * Stephen Tweedie (sct@dcs.ed.ac.uk), 1993 2062306a36Sopenharmony_ci * Big-endian to little-endian byte-swapping/bitmaps by 2162306a36Sopenharmony_ci * David S. Miller (davem@caip.rutgers.edu), 1995 2262306a36Sopenharmony_ci * 2362306a36Sopenharmony_ci * UFS2 write support added by 2462306a36Sopenharmony_ci * Evgeniy Dushistov <dushistov@mail.ru>, 2007 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#include <linux/fs.h> 2862306a36Sopenharmony_ci#include <linux/time.h> 2962306a36Sopenharmony_ci#include <linux/stat.h> 3062306a36Sopenharmony_ci#include <linux/string.h> 3162306a36Sopenharmony_ci#include <linux/buffer_head.h> 3262306a36Sopenharmony_ci#include <linux/sched.h> 3362306a36Sopenharmony_ci#include <linux/bitops.h> 3462306a36Sopenharmony_ci#include <asm/byteorder.h> 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#include "ufs_fs.h" 3762306a36Sopenharmony_ci#include "ufs.h" 3862306a36Sopenharmony_ci#include "swab.h" 3962306a36Sopenharmony_ci#include "util.h" 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* 4262306a36Sopenharmony_ci * NOTE! When we get the inode, we're the only people 4362306a36Sopenharmony_ci * that have access to it, and as such there are no 4462306a36Sopenharmony_ci * race conditions we have to worry about. The inode 4562306a36Sopenharmony_ci * is not on the hash-lists, and it cannot be reached 4662306a36Sopenharmony_ci * through the filesystem because the directory entry 4762306a36Sopenharmony_ci * has been deleted earlier. 4862306a36Sopenharmony_ci * 4962306a36Sopenharmony_ci * HOWEVER: we must make sure that we get no aliases, 5062306a36Sopenharmony_ci * which means that we have to call "clear_inode()" 5162306a36Sopenharmony_ci * _before_ we mark the inode not in use in the inode 5262306a36Sopenharmony_ci * bitmaps. Otherwise a newly created file might use 5362306a36Sopenharmony_ci * the same inode number (not actually the same pointer 5462306a36Sopenharmony_ci * though), and then we'd have two inodes sharing the 5562306a36Sopenharmony_ci * same inode number and space on the harddisk. 5662306a36Sopenharmony_ci */ 5762306a36Sopenharmony_civoid ufs_free_inode (struct inode * inode) 5862306a36Sopenharmony_ci{ 5962306a36Sopenharmony_ci struct super_block * sb; 6062306a36Sopenharmony_ci struct ufs_sb_private_info * uspi; 6162306a36Sopenharmony_ci struct ufs_cg_private_info * ucpi; 6262306a36Sopenharmony_ci struct ufs_cylinder_group * ucg; 6362306a36Sopenharmony_ci int is_directory; 6462306a36Sopenharmony_ci unsigned ino, cg, bit; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci UFSD("ENTER, ino %lu\n", inode->i_ino); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci sb = inode->i_sb; 6962306a36Sopenharmony_ci uspi = UFS_SB(sb)->s_uspi; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci ino = inode->i_ino; 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci mutex_lock(&UFS_SB(sb)->s_lock); 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci if (!((ino > 1) && (ino < (uspi->s_ncg * uspi->s_ipg )))) { 7662306a36Sopenharmony_ci ufs_warning(sb, "ufs_free_inode", "reserved inode or nonexistent inode %u\n", ino); 7762306a36Sopenharmony_ci mutex_unlock(&UFS_SB(sb)->s_lock); 7862306a36Sopenharmony_ci return; 7962306a36Sopenharmony_ci } 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci cg = ufs_inotocg (ino); 8262306a36Sopenharmony_ci bit = ufs_inotocgoff (ino); 8362306a36Sopenharmony_ci ucpi = ufs_load_cylinder (sb, cg); 8462306a36Sopenharmony_ci if (!ucpi) { 8562306a36Sopenharmony_ci mutex_unlock(&UFS_SB(sb)->s_lock); 8662306a36Sopenharmony_ci return; 8762306a36Sopenharmony_ci } 8862306a36Sopenharmony_ci ucg = ubh_get_ucg(UCPI_UBH(ucpi)); 8962306a36Sopenharmony_ci if (!ufs_cg_chkmagic(sb, ucg)) 9062306a36Sopenharmony_ci ufs_panic (sb, "ufs_free_fragments", "internal error, bad cg magic number"); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci ucg->cg_time = ufs_get_seconds(sb); 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci is_directory = S_ISDIR(inode->i_mode); 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit)) 9762306a36Sopenharmony_ci ufs_error(sb, "ufs_free_inode", "bit already cleared for inode %u", ino); 9862306a36Sopenharmony_ci else { 9962306a36Sopenharmony_ci ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit); 10062306a36Sopenharmony_ci if (ino < ucpi->c_irotor) 10162306a36Sopenharmony_ci ucpi->c_irotor = ino; 10262306a36Sopenharmony_ci fs32_add(sb, &ucg->cg_cs.cs_nifree, 1); 10362306a36Sopenharmony_ci uspi->cs_total.cs_nifree++; 10462306a36Sopenharmony_ci fs32_add(sb, &UFS_SB(sb)->fs_cs(cg).cs_nifree, 1); 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci if (is_directory) { 10762306a36Sopenharmony_ci fs32_sub(sb, &ucg->cg_cs.cs_ndir, 1); 10862306a36Sopenharmony_ci uspi->cs_total.cs_ndir--; 10962306a36Sopenharmony_ci fs32_sub(sb, &UFS_SB(sb)->fs_cs(cg).cs_ndir, 1); 11062306a36Sopenharmony_ci } 11162306a36Sopenharmony_ci } 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci ubh_mark_buffer_dirty (USPI_UBH(uspi)); 11462306a36Sopenharmony_ci ubh_mark_buffer_dirty (UCPI_UBH(ucpi)); 11562306a36Sopenharmony_ci if (sb->s_flags & SB_SYNCHRONOUS) 11662306a36Sopenharmony_ci ubh_sync_block(UCPI_UBH(ucpi)); 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci ufs_mark_sb_dirty(sb); 11962306a36Sopenharmony_ci mutex_unlock(&UFS_SB(sb)->s_lock); 12062306a36Sopenharmony_ci UFSD("EXIT\n"); 12162306a36Sopenharmony_ci} 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci/* 12462306a36Sopenharmony_ci * Nullify new chunk of inodes, 12562306a36Sopenharmony_ci * BSD people also set ui_gen field of inode 12662306a36Sopenharmony_ci * during nullification, but we not care about 12762306a36Sopenharmony_ci * that because of linux ufs do not support NFS 12862306a36Sopenharmony_ci */ 12962306a36Sopenharmony_cistatic void ufs2_init_inodes_chunk(struct super_block *sb, 13062306a36Sopenharmony_ci struct ufs_cg_private_info *ucpi, 13162306a36Sopenharmony_ci struct ufs_cylinder_group *ucg) 13262306a36Sopenharmony_ci{ 13362306a36Sopenharmony_ci struct buffer_head *bh; 13462306a36Sopenharmony_ci struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi; 13562306a36Sopenharmony_ci sector_t beg = uspi->s_sbbase + 13662306a36Sopenharmony_ci ufs_inotofsba(ucpi->c_cgx * uspi->s_ipg + 13762306a36Sopenharmony_ci fs32_to_cpu(sb, ucg->cg_u.cg_u2.cg_initediblk)); 13862306a36Sopenharmony_ci sector_t end = beg + uspi->s_fpb; 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci UFSD("ENTER cgno %d\n", ucpi->c_cgx); 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci for (; beg < end; ++beg) { 14362306a36Sopenharmony_ci bh = sb_getblk(sb, beg); 14462306a36Sopenharmony_ci lock_buffer(bh); 14562306a36Sopenharmony_ci memset(bh->b_data, 0, sb->s_blocksize); 14662306a36Sopenharmony_ci set_buffer_uptodate(bh); 14762306a36Sopenharmony_ci mark_buffer_dirty(bh); 14862306a36Sopenharmony_ci unlock_buffer(bh); 14962306a36Sopenharmony_ci if (sb->s_flags & SB_SYNCHRONOUS) 15062306a36Sopenharmony_ci sync_dirty_buffer(bh); 15162306a36Sopenharmony_ci brelse(bh); 15262306a36Sopenharmony_ci } 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci fs32_add(sb, &ucg->cg_u.cg_u2.cg_initediblk, uspi->s_inopb); 15562306a36Sopenharmony_ci ubh_mark_buffer_dirty(UCPI_UBH(ucpi)); 15662306a36Sopenharmony_ci if (sb->s_flags & SB_SYNCHRONOUS) 15762306a36Sopenharmony_ci ubh_sync_block(UCPI_UBH(ucpi)); 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci UFSD("EXIT\n"); 16062306a36Sopenharmony_ci} 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci/* 16362306a36Sopenharmony_ci * There are two policies for allocating an inode. If the new inode is 16462306a36Sopenharmony_ci * a directory, then a forward search is made for a block group with both 16562306a36Sopenharmony_ci * free space and a low directory-to-inode ratio; if that fails, then of 16662306a36Sopenharmony_ci * the groups with above-average free space, that group with the fewest 16762306a36Sopenharmony_ci * directories already is chosen. 16862306a36Sopenharmony_ci * 16962306a36Sopenharmony_ci * For other inodes, search forward from the parent directory's block 17062306a36Sopenharmony_ci * group to find a free inode. 17162306a36Sopenharmony_ci */ 17262306a36Sopenharmony_cistruct inode *ufs_new_inode(struct inode *dir, umode_t mode) 17362306a36Sopenharmony_ci{ 17462306a36Sopenharmony_ci struct super_block * sb; 17562306a36Sopenharmony_ci struct ufs_sb_info * sbi; 17662306a36Sopenharmony_ci struct ufs_sb_private_info * uspi; 17762306a36Sopenharmony_ci struct ufs_cg_private_info * ucpi; 17862306a36Sopenharmony_ci struct ufs_cylinder_group * ucg; 17962306a36Sopenharmony_ci struct inode * inode; 18062306a36Sopenharmony_ci struct timespec64 ts; 18162306a36Sopenharmony_ci unsigned cg, bit, i, j, start; 18262306a36Sopenharmony_ci struct ufs_inode_info *ufsi; 18362306a36Sopenharmony_ci int err = -ENOSPC; 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci UFSD("ENTER\n"); 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci /* Cannot create files in a deleted directory */ 18862306a36Sopenharmony_ci if (!dir || !dir->i_nlink) 18962306a36Sopenharmony_ci return ERR_PTR(-EPERM); 19062306a36Sopenharmony_ci sb = dir->i_sb; 19162306a36Sopenharmony_ci inode = new_inode(sb); 19262306a36Sopenharmony_ci if (!inode) 19362306a36Sopenharmony_ci return ERR_PTR(-ENOMEM); 19462306a36Sopenharmony_ci ufsi = UFS_I(inode); 19562306a36Sopenharmony_ci sbi = UFS_SB(sb); 19662306a36Sopenharmony_ci uspi = sbi->s_uspi; 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci mutex_lock(&sbi->s_lock); 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci /* 20162306a36Sopenharmony_ci * Try to place the inode in its parent directory 20262306a36Sopenharmony_ci */ 20362306a36Sopenharmony_ci i = ufs_inotocg(dir->i_ino); 20462306a36Sopenharmony_ci if (sbi->fs_cs(i).cs_nifree) { 20562306a36Sopenharmony_ci cg = i; 20662306a36Sopenharmony_ci goto cg_found; 20762306a36Sopenharmony_ci } 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci /* 21062306a36Sopenharmony_ci * Use a quadratic hash to find a group with a free inode 21162306a36Sopenharmony_ci */ 21262306a36Sopenharmony_ci for ( j = 1; j < uspi->s_ncg; j <<= 1 ) { 21362306a36Sopenharmony_ci i += j; 21462306a36Sopenharmony_ci if (i >= uspi->s_ncg) 21562306a36Sopenharmony_ci i -= uspi->s_ncg; 21662306a36Sopenharmony_ci if (sbi->fs_cs(i).cs_nifree) { 21762306a36Sopenharmony_ci cg = i; 21862306a36Sopenharmony_ci goto cg_found; 21962306a36Sopenharmony_ci } 22062306a36Sopenharmony_ci } 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci /* 22362306a36Sopenharmony_ci * That failed: try linear search for a free inode 22462306a36Sopenharmony_ci */ 22562306a36Sopenharmony_ci i = ufs_inotocg(dir->i_ino) + 1; 22662306a36Sopenharmony_ci for (j = 2; j < uspi->s_ncg; j++) { 22762306a36Sopenharmony_ci i++; 22862306a36Sopenharmony_ci if (i >= uspi->s_ncg) 22962306a36Sopenharmony_ci i = 0; 23062306a36Sopenharmony_ci if (sbi->fs_cs(i).cs_nifree) { 23162306a36Sopenharmony_ci cg = i; 23262306a36Sopenharmony_ci goto cg_found; 23362306a36Sopenharmony_ci } 23462306a36Sopenharmony_ci } 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci goto failed; 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_cicg_found: 23962306a36Sopenharmony_ci ucpi = ufs_load_cylinder (sb, cg); 24062306a36Sopenharmony_ci if (!ucpi) { 24162306a36Sopenharmony_ci err = -EIO; 24262306a36Sopenharmony_ci goto failed; 24362306a36Sopenharmony_ci } 24462306a36Sopenharmony_ci ucg = ubh_get_ucg(UCPI_UBH(ucpi)); 24562306a36Sopenharmony_ci if (!ufs_cg_chkmagic(sb, ucg)) 24662306a36Sopenharmony_ci ufs_panic (sb, "ufs_new_inode", "internal error, bad cg magic number"); 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci start = ucpi->c_irotor; 24962306a36Sopenharmony_ci bit = ubh_find_next_zero_bit (UCPI_UBH(ucpi), ucpi->c_iusedoff, uspi->s_ipg, start); 25062306a36Sopenharmony_ci if (!(bit < uspi->s_ipg)) { 25162306a36Sopenharmony_ci bit = ubh_find_first_zero_bit (UCPI_UBH(ucpi), ucpi->c_iusedoff, start); 25262306a36Sopenharmony_ci if (!(bit < start)) { 25362306a36Sopenharmony_ci ufs_error (sb, "ufs_new_inode", 25462306a36Sopenharmony_ci "cylinder group %u corrupted - error in inode bitmap\n", cg); 25562306a36Sopenharmony_ci err = -EIO; 25662306a36Sopenharmony_ci goto failed; 25762306a36Sopenharmony_ci } 25862306a36Sopenharmony_ci } 25962306a36Sopenharmony_ci UFSD("start = %u, bit = %u, ipg = %u\n", start, bit, uspi->s_ipg); 26062306a36Sopenharmony_ci if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit)) 26162306a36Sopenharmony_ci ubh_setbit (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit); 26262306a36Sopenharmony_ci else { 26362306a36Sopenharmony_ci ufs_panic (sb, "ufs_new_inode", "internal error"); 26462306a36Sopenharmony_ci err = -EIO; 26562306a36Sopenharmony_ci goto failed; 26662306a36Sopenharmony_ci } 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci if (uspi->fs_magic == UFS2_MAGIC) { 26962306a36Sopenharmony_ci u32 initediblk = fs32_to_cpu(sb, ucg->cg_u.cg_u2.cg_initediblk); 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci if (bit + uspi->s_inopb > initediblk && 27262306a36Sopenharmony_ci initediblk < fs32_to_cpu(sb, ucg->cg_u.cg_u2.cg_niblk)) 27362306a36Sopenharmony_ci ufs2_init_inodes_chunk(sb, ucpi, ucg); 27462306a36Sopenharmony_ci } 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci fs32_sub(sb, &ucg->cg_cs.cs_nifree, 1); 27762306a36Sopenharmony_ci uspi->cs_total.cs_nifree--; 27862306a36Sopenharmony_ci fs32_sub(sb, &sbi->fs_cs(cg).cs_nifree, 1); 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ci if (S_ISDIR(mode)) { 28162306a36Sopenharmony_ci fs32_add(sb, &ucg->cg_cs.cs_ndir, 1); 28262306a36Sopenharmony_ci uspi->cs_total.cs_ndir++; 28362306a36Sopenharmony_ci fs32_add(sb, &sbi->fs_cs(cg).cs_ndir, 1); 28462306a36Sopenharmony_ci } 28562306a36Sopenharmony_ci ubh_mark_buffer_dirty (USPI_UBH(uspi)); 28662306a36Sopenharmony_ci ubh_mark_buffer_dirty (UCPI_UBH(ucpi)); 28762306a36Sopenharmony_ci if (sb->s_flags & SB_SYNCHRONOUS) 28862306a36Sopenharmony_ci ubh_sync_block(UCPI_UBH(ucpi)); 28962306a36Sopenharmony_ci ufs_mark_sb_dirty(sb); 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci inode->i_ino = cg * uspi->s_ipg + bit; 29262306a36Sopenharmony_ci inode_init_owner(&nop_mnt_idmap, inode, dir, mode); 29362306a36Sopenharmony_ci inode->i_blocks = 0; 29462306a36Sopenharmony_ci inode->i_generation = 0; 29562306a36Sopenharmony_ci inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode); 29662306a36Sopenharmony_ci ufsi->i_flags = UFS_I(dir)->i_flags; 29762306a36Sopenharmony_ci ufsi->i_lastfrag = 0; 29862306a36Sopenharmony_ci ufsi->i_shadow = 0; 29962306a36Sopenharmony_ci ufsi->i_osync = 0; 30062306a36Sopenharmony_ci ufsi->i_oeftflag = 0; 30162306a36Sopenharmony_ci ufsi->i_dir_start_lookup = 0; 30262306a36Sopenharmony_ci memset(&ufsi->i_u1, 0, sizeof(ufsi->i_u1)); 30362306a36Sopenharmony_ci if (insert_inode_locked(inode) < 0) { 30462306a36Sopenharmony_ci err = -EIO; 30562306a36Sopenharmony_ci goto failed; 30662306a36Sopenharmony_ci } 30762306a36Sopenharmony_ci mark_inode_dirty(inode); 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci if (uspi->fs_magic == UFS2_MAGIC) { 31062306a36Sopenharmony_ci struct buffer_head *bh; 31162306a36Sopenharmony_ci struct ufs2_inode *ufs2_inode; 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci /* 31462306a36Sopenharmony_ci * setup birth date, we do it here because of there is no sense 31562306a36Sopenharmony_ci * to hold it in struct ufs_inode_info, and lose 64 bit 31662306a36Sopenharmony_ci */ 31762306a36Sopenharmony_ci bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino)); 31862306a36Sopenharmony_ci if (!bh) { 31962306a36Sopenharmony_ci ufs_warning(sb, "ufs_read_inode", 32062306a36Sopenharmony_ci "unable to read inode %lu\n", 32162306a36Sopenharmony_ci inode->i_ino); 32262306a36Sopenharmony_ci err = -EIO; 32362306a36Sopenharmony_ci goto fail_remove_inode; 32462306a36Sopenharmony_ci } 32562306a36Sopenharmony_ci lock_buffer(bh); 32662306a36Sopenharmony_ci ufs2_inode = (struct ufs2_inode *)bh->b_data; 32762306a36Sopenharmony_ci ufs2_inode += ufs_inotofsbo(inode->i_ino); 32862306a36Sopenharmony_ci ktime_get_real_ts64(&ts); 32962306a36Sopenharmony_ci ufs2_inode->ui_birthtime = cpu_to_fs64(sb, ts.tv_sec); 33062306a36Sopenharmony_ci ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, ts.tv_nsec); 33162306a36Sopenharmony_ci mark_buffer_dirty(bh); 33262306a36Sopenharmony_ci unlock_buffer(bh); 33362306a36Sopenharmony_ci if (sb->s_flags & SB_SYNCHRONOUS) 33462306a36Sopenharmony_ci sync_dirty_buffer(bh); 33562306a36Sopenharmony_ci brelse(bh); 33662306a36Sopenharmony_ci } 33762306a36Sopenharmony_ci mutex_unlock(&sbi->s_lock); 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci UFSD("allocating inode %lu\n", inode->i_ino); 34062306a36Sopenharmony_ci UFSD("EXIT\n"); 34162306a36Sopenharmony_ci return inode; 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_cifail_remove_inode: 34462306a36Sopenharmony_ci mutex_unlock(&sbi->s_lock); 34562306a36Sopenharmony_ci clear_nlink(inode); 34662306a36Sopenharmony_ci discard_new_inode(inode); 34762306a36Sopenharmony_ci UFSD("EXIT (FAILED): err %d\n", err); 34862306a36Sopenharmony_ci return ERR_PTR(err); 34962306a36Sopenharmony_cifailed: 35062306a36Sopenharmony_ci mutex_unlock(&sbi->s_lock); 35162306a36Sopenharmony_ci make_bad_inode(inode); 35262306a36Sopenharmony_ci iput (inode); 35362306a36Sopenharmony_ci UFSD("EXIT (FAILED): err %d\n", err); 35462306a36Sopenharmony_ci return ERR_PTR(err); 35562306a36Sopenharmony_ci} 356