From owner-svn-src-head@freebsd.org Tue Aug 21 18:39:04 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2A796107BDB2; Tue, 21 Aug 2018 18:39:04 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CC9E091592; Tue, 21 Aug 2018 18:39:03 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AB76627C40; Tue, 21 Aug 2018 18:39:03 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7LId32v093216; Tue, 21 Aug 2018 18:39:03 GMT (envelope-from fsu@FreeBSD.org) Received: (from fsu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7LId2cx093212; Tue, 21 Aug 2018 18:39:02 GMT (envelope-from fsu@FreeBSD.org) Message-Id: <201808211839.w7LId2cx093212@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: fsu set sender to fsu@FreeBSD.org using -f From: Fedor Uporov Date: Tue, 21 Aug 2018 18:39:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338150 - head/sys/fs/ext2fs X-SVN-Group: head X-SVN-Commit-Author: fsu X-SVN-Commit-Paths: head/sys/fs/ext2fs X-SVN-Commit-Revision: 338150 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Aug 2018 18:39:04 -0000 Author: fsu Date: Tue Aug 21 18:39:02 2018 New Revision: 338150 URL: https://svnweb.freebsd.org/changeset/base/338150 Log: Fix directory blocks checksum updating logic. Count dirent tail in the searchslot logic in case of directory block search. Add htree root csum update function call in case of rename. Modified: head/sys/fs/ext2fs/ext2_csum.c head/sys/fs/ext2fs/ext2_extern.h head/sys/fs/ext2fs/ext2_lookup.c head/sys/fs/ext2fs/ext2_vnops.c Modified: head/sys/fs/ext2fs/ext2_csum.c ============================================================================== --- head/sys/fs/ext2fs/ext2_csum.c Tue Aug 21 18:22:12 2018 (r338149) +++ head/sys/fs/ext2fs/ext2_csum.c Tue Aug 21 18:39:02 2018 (r338150) @@ -162,12 +162,32 @@ ext2_init_dirent_tail(struct ext2fs_direct_tail *tp) tp->e2dt_reserved_ft = EXT2_FT_DIR_CSUM; } +int +ext2_is_dirent_tail(struct inode *ip, struct ext2fs_direct_2 *ep) +{ + struct m_ext2fs *fs; + struct ext2fs_direct_tail *tp; + + fs = ip->i_e2fs; + + if (!EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) + return (0); + + tp = (struct ext2fs_direct_tail *)ep; + if (tp->e2dt_reserved_zero1 == 0 && + tp->e2dt_rec_len == sizeof(struct ext2fs_direct_tail) && + tp->e2dt_reserved_zero2 == 0 && + tp->e2dt_reserved_ft == EXT2_FT_DIR_CSUM) + return (1); + + return (0); +} + struct ext2fs_direct_tail * ext2_dirent_get_tail(struct inode *ip, struct ext2fs_direct_2 *ep) { struct ext2fs_direct_2 *dep; void *top; - struct ext2fs_direct_tail *tp; unsigned int rec_len; dep = ep; @@ -184,14 +204,10 @@ ext2_dirent_get_tail(struct inode *ip, struct ext2fs_d if (dep != top) return (NULL); - tp = (struct ext2fs_direct_tail *)dep; - if (tp->e2dt_reserved_zero1 || - tp->e2dt_rec_len != sizeof(struct ext2fs_direct_tail) || - tp->e2dt_reserved_zero2 || - tp->e2dt_reserved_ft != EXT2_FT_DIR_CSUM) - return (NULL); + if (ext2_is_dirent_tail(ip, dep)) + return ((struct ext2fs_direct_tail *)dep); - return (tp); + return (NULL); } static uint32_t Modified: head/sys/fs/ext2fs/ext2_extern.h ============================================================================== --- head/sys/fs/ext2fs/ext2_extern.h Tue Aug 21 18:22:12 2018 (r338149) +++ head/sys/fs/ext2fs/ext2_extern.h Tue Aug 21 18:39:02 2018 (r338150) @@ -120,6 +120,7 @@ int ext2_dx_csum_verify(struct inode *ip, struct ext2f int ext2_extent_blk_csum_verify(struct inode *, void *); void ext2_extent_blk_csum_set(struct inode *, void *); void ext2_init_dirent_tail(struct ext2fs_direct_tail *); +int ext2_is_dirent_tail(struct inode *, struct ext2fs_direct_2 *); int ext2_gd_i_bitmap_csum_verify(struct m_ext2fs *, int, struct buf *); void ext2_gd_i_bitmap_csum_set(struct m_ext2fs *, int, struct buf *); int ext2_gd_b_bitmap_csum_verify(struct m_ext2fs *, int, struct buf *); Modified: head/sys/fs/ext2fs/ext2_lookup.c ============================================================================== --- head/sys/fs/ext2fs/ext2_lookup.c Tue Aug 21 18:22:12 2018 (r338149) +++ head/sys/fs/ext2fs/ext2_lookup.c Tue Aug 21 18:39:02 2018 (r338150) @@ -429,16 +429,13 @@ searchloop: error = ext2_blkatoff(vdp, (off_t)i_offset, NULL, &bp); if (error != 0) return (error); + entryoffsetinblock = 0; - /* - * If still looking for a slot, and at a DIRBLKSIZE - * boundary, have to start looking for free space again. - */ - if (ss.slotstatus == NONE && - (entryoffsetinblock & (DIRBLKSIZ - 1)) == 0) { + if (ss.slotstatus == NONE) { ss.slotoffset = -1; ss.slotfreespace = 0; } + error = ext2_search_dirblock(dp, bp->b_data, &entry_found, cnp->cn_nameptr, cnp->cn_namelen, &entryoffsetinblock, &i_offset, &prevoff, @@ -719,9 +716,7 @@ ext2_search_dirblock(struct inode *ip, void *data, int vdp = ITOV(ip); ep = (struct ext2fs_direct_2 *)((char *)data + offset); - top = (struct ext2fs_direct_2 *)((char *)data + - bsize - EXT2_DIR_REC_LEN(0)); - + top = (struct ext2fs_direct_2 *)((char *)data + bsize); while (ep < top) { /* * Full validation checks are slow, so we only check @@ -751,6 +746,8 @@ ext2_search_dirblock(struct inode *ip, void *data, int if (ep->e2d_ino != 0) size -= EXT2_DIR_REC_LEN(ep->e2d_namlen); + else if (ext2_is_dirent_tail(ip, ep)) + size -= sizeof(struct ext2fs_direct_tail); if (size > 0) { if (size >= ssp->slotneeded) { ssp->slotstatus = FOUND; Modified: head/sys/fs/ext2fs/ext2_vnops.c ============================================================================== --- head/sys/fs/ext2fs/ext2_vnops.c Tue Aug 21 18:22:12 2018 (r338149) +++ head/sys/fs/ext2fs/ext2_vnops.c Tue Aug 21 18:39:02 2018 (r338150) @@ -1081,7 +1081,13 @@ abortit: "rename: mangled dir"); } else { dirbuf->dotdot_ino = newparent; + /* + * dirblock 0 could be htree root, + * try both csum update functions. + */ ext2_dirent_csum_set(ip, + (struct ext2fs_direct_2 *)dirbuf); + ext2_dx_csum_set(ip, (struct ext2fs_direct_2 *)dirbuf); (void)vn_rdwr(UIO_WRITE, fvp, (caddr_t)dirbuf,