From owner-svn-src-head@freebsd.org Mon Jul 18 05:00:02 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6F3BEB9CED3; Mon, 18 Jul 2016 05:00:02 +0000 (UTC) (envelope-from sobomax@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 mx1.freebsd.org (Postfix) with ESMTPS id 343B4105A; Mon, 18 Jul 2016 05:00:02 +0000 (UTC) (envelope-from sobomax@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u6I5017t063744; Mon, 18 Jul 2016 05:00:01 GMT (envelope-from sobomax@FreeBSD.org) Received: (from sobomax@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6I501CX063743; Mon, 18 Jul 2016 05:00:01 GMT (envelope-from sobomax@FreeBSD.org) Message-Id: <201607180500.u6I501CX063743@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sobomax set sender to sobomax@FreeBSD.org using -f From: Maxim Sobolev Date: Mon, 18 Jul 2016 05:00:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r302985 - head/sys/geom/label X-SVN-Group: head 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.22 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: Mon, 18 Jul 2016 05:00:02 -0000 Author: sobomax Date: Mon Jul 18 05:00:01 2016 New Revision: 302985 URL: https://svnweb.freebsd.org/changeset/base/302985 Log: Relax checking if the privider size matches size recorded in the superblock, allowing provider to be bit bigger, i.e. have some extra padding after the FS image. That in some cases might be a side-effect of using CLOOP format which enforces certain block size and trying to compress image that is not exactly the number of those blocks in size. The UFS itself does not have any issues mounting such padded file systems, so it's what GEOM_LABEL should do. Submitted by: @mizhka_gmail.com Differential Revision: https://reviews.freebsd.org/D6208 Modified: head/sys/geom/label/g_label_ufs.c Modified: head/sys/geom/label/g_label_ufs.c ============================================================================== --- head/sys/geom/label/g_label_ufs.c Mon Jul 18 04:36:18 2016 (r302984) +++ head/sys/geom/label/g_label_ufs.c Mon Jul 18 05:00:01 2016 (r302985) @@ -45,6 +45,15 @@ __FBSDID("$FreeBSD$"); #define G_LABEL_UFS_VOLUME 0 #define G_LABEL_UFS_ID 1 +/* + * G_LABEL_UFS_CMP returns true if difference between provider mediasize + * and filesystem size is less than G_LABEL_UFS_MAXDIFF sectors + */ +#define G_LABEL_UFS_CMP(prov, fsys, size) \ + ( abs( ((fsys)->size) - ( (prov)->mediasize / (fsys)->fs_fsize )) \ + < G_LABEL_UFS_MAXDIFF ) +#define G_LABEL_UFS_MAXDIFF 0x100 + static const int superblocks[] = SBLOCKSEARCH; static void @@ -82,18 +91,35 @@ g_label_ufs_taste_common(struct g_consum if (fs == NULL) continue; /* - * Check for magic. We also need to check if file system size is equal - * to providers size, because sysinstall(8) used to bogusly put first - * partition at offset 0 instead of 16, and glabel/ufs would find file - * system on slice instead of partition. + * Check for magic. We also need to check if file system size + * is almost equal to providers size, because sysinstall(8) + * used to bogusly put first partition at offset 0 + * instead of 16, and glabel/ufs would find file system on slice + * instead of partition. + * + * In addition, media size can be a bit bigger than file system + * size. For instance, mkuzip can append bytes to align data + * to large sector size (it improves compression rates). */ + switch (fs->fs_magic){ + case FS_UFS1_MAGIC: + case FS_UFS2_MAGIC: + G_LABEL_DEBUG(1, "%s %s params: %jd, %d, %d, %jd\n", + fs->fs_magic == FS_UFS1_MAGIC ? "UFS1" : "UFS2", + pp->name, pp->mediasize, fs->fs_fsize, + fs->fs_old_size, fs->fs_providersize); + break; + default: + break; + } + if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0 && - ((pp->mediasize / fs->fs_fsize == fs->fs_old_size) || - (pp->mediasize / fs->fs_fsize == fs->fs_providersize))) { + ( G_LABEL_UFS_CMP(pp, fs, fs_old_size) + || G_LABEL_UFS_CMP(pp, fs, fs_providersize))) { /* Valid UFS1. */ } else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0 && - ((pp->mediasize / fs->fs_fsize == fs->fs_size) || - (pp->mediasize / fs->fs_fsize == fs->fs_providersize))) { + ( G_LABEL_UFS_CMP(pp, fs, fs_size) + || G_LABEL_UFS_CMP(pp, fs, fs_providersize))) { /* Valid UFS2. */ } else { g_free(fs);