From: Christoph Hellwig <hch@infradead.org>
To: xfs@oss.sgi.com
Subject: Re: [PATCH 1/5] xfs: cleanup uuid handling
Date: Sun, 29 Mar 2009 03:45:07 -0400 [thread overview]
Message-ID: <20090329074507.GF16402@infradead.org> (raw)
In-Reply-To: <20090318094131.771403000@bombadil.infradead.org>
ping?
On Wed, Mar 18, 2009 at 05:41:20AM -0400, Christoph Hellwig wrote:
> The uuid table handling should not be part of a semi-generic uuid library
> but in the XFS code using it, so move those bits to xfs_mount.c and
> refactor the whole glob to give a proper abstraction.
>
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
>
> Index: xfs/fs/xfs/support/uuid.c
> ===================================================================
> --- xfs.orig/fs/xfs/support/uuid.c 2009-02-15 19:40:08.564944522 +0100
> +++ xfs/fs/xfs/support/uuid.c 2009-02-24 21:50:49.051029140 +0100
> @@ -17,10 +17,6 @@
> */
> #include <xfs.h>
>
> -static DEFINE_MUTEX(uuid_monitor);
> -static int uuid_table_size;
> -static uuid_t *uuid_table;
> -
> /* IRIX interpretation of an uuid_t */
> typedef struct {
> __be32 uu_timelow;
> @@ -46,12 +42,6 @@ uuid_getnodeuniq(uuid_t *uuid, int fsid
> fsid[1] = be32_to_cpu(uup->uu_timelow);
> }
>
> -void
> -uuid_create_nil(uuid_t *uuid)
> -{
> - memset(uuid, 0, sizeof(*uuid));
> -}
> -
> int
> uuid_is_nil(uuid_t *uuid)
> {
> @@ -71,64 +61,3 @@ uuid_equal(uuid_t *uuid1, uuid_t *uuid2)
> {
> return memcmp(uuid1, uuid2, sizeof(uuid_t)) ? 0 : 1;
> }
> -
> -/*
> - * Given a 128-bit uuid, return a 64-bit value by adding the top and bottom
> - * 64-bit words. NOTE: This function can not be changed EVER. Although
> - * brain-dead, some applications depend on this 64-bit value remaining
> - * persistent. Specifically, DMI vendors store the value as a persistent
> - * filehandle.
> - */
> -__uint64_t
> -uuid_hash64(uuid_t *uuid)
> -{
> - __uint64_t *sp = (__uint64_t *)uuid;
> -
> - return sp[0] + sp[1];
> -}
> -
> -int
> -uuid_table_insert(uuid_t *uuid)
> -{
> - int i, hole;
> -
> - mutex_lock(&uuid_monitor);
> - for (i = 0, hole = -1; i < uuid_table_size; i++) {
> - if (uuid_is_nil(&uuid_table[i])) {
> - hole = i;
> - continue;
> - }
> - if (uuid_equal(uuid, &uuid_table[i])) {
> - mutex_unlock(&uuid_monitor);
> - return 0;
> - }
> - }
> - if (hole < 0) {
> - uuid_table = kmem_realloc(uuid_table,
> - (uuid_table_size + 1) * sizeof(*uuid_table),
> - uuid_table_size * sizeof(*uuid_table),
> - KM_SLEEP);
> - hole = uuid_table_size++;
> - }
> - uuid_table[hole] = *uuid;
> - mutex_unlock(&uuid_monitor);
> - return 1;
> -}
> -
> -void
> -uuid_table_remove(uuid_t *uuid)
> -{
> - int i;
> -
> - mutex_lock(&uuid_monitor);
> - for (i = 0; i < uuid_table_size; i++) {
> - if (uuid_is_nil(&uuid_table[i]))
> - continue;
> - if (!uuid_equal(uuid, &uuid_table[i]))
> - continue;
> - uuid_create_nil(&uuid_table[i]);
> - break;
> - }
> - ASSERT(i < uuid_table_size);
> - mutex_unlock(&uuid_monitor);
> -}
> Index: xfs/fs/xfs/support/uuid.h
> ===================================================================
> --- xfs.orig/fs/xfs/support/uuid.h 2009-02-15 19:40:08.569944670 +0100
> +++ xfs/fs/xfs/support/uuid.h 2009-02-24 21:50:37.206029255 +0100
> @@ -22,12 +22,8 @@ typedef struct {
> unsigned char __u_bits[16];
> } uuid_t;
>
> -extern void uuid_create_nil(uuid_t *uuid);
> extern int uuid_is_nil(uuid_t *uuid);
> extern int uuid_equal(uuid_t *uuid1, uuid_t *uuid2);
> extern void uuid_getnodeuniq(uuid_t *uuid, int fsid [2]);
> -extern __uint64_t uuid_hash64(uuid_t *uuid);
> -extern int uuid_table_insert(uuid_t *uuid);
> -extern void uuid_table_remove(uuid_t *uuid);
>
> #endif /* __XFS_SUPPORT_UUID_H__ */
> Index: xfs/fs/xfs/xfs_mount.c
> ===================================================================
> --- xfs.orig/fs/xfs/xfs_mount.c 2009-02-24 15:32:35.871518446 +0100
> +++ xfs/fs/xfs/xfs_mount.c 2009-02-24 21:51:03.558027729 +0100
> @@ -45,7 +45,6 @@
> #include "xfs_fsops.h"
> #include "xfs_utils.h"
>
> -STATIC int xfs_uuid_mount(xfs_mount_t *);
> STATIC void xfs_unmountfs_wait(xfs_mount_t *);
>
>
> @@ -121,6 +120,84 @@ static const struct {
> { sizeof(xfs_sb_t), 0 }
> };
>
> +static DEFINE_MUTEX(xfs_uuid_table_mutex);
> +static int xfs_uuid_table_size;
> +static uuid_t *xfs_uuid_table;
> +
> +/*
> + * See if the UUID is unique among mounted XFS filesystems.
> + * Mount fails if UUID is nil or a FS with the same UUID is already mounted.
> + */
> +STATIC int
> +xfs_uuid_mount(
> + struct xfs_mount *mp)
> +{
> + uuid_t *uuid = &mp->m_sb.sb_uuid;
> + int hole, i;
> +
> + if (mp->m_flags & XFS_MOUNT_NOUUID)
> + return 0;
> +
> + if (uuid_is_nil(uuid)) {
> + cmn_err(CE_WARN,
> + "XFS: Filesystem %s has nil UUID - can't mount",
> + mp->m_fsname);
> + return XFS_ERROR(EINVAL);
> + }
> +
> + mutex_lock(&xfs_uuid_table_mutex);
> + for (i = 0, hole = -1; i < xfs_uuid_table_size; i++) {
> + if (uuid_is_nil(&xfs_uuid_table[i])) {
> + hole = i;
> + continue;
> + }
> + if (uuid_equal(uuid, &xfs_uuid_table[i]))
> + goto out_duplicate;
> + }
> +
> + if (hole < 0) {
> + xfs_uuid_table = kmem_realloc(xfs_uuid_table,
> + (xfs_uuid_table_size + 1) * sizeof(*xfs_uuid_table),
> + xfs_uuid_table_size * sizeof(*xfs_uuid_table),
> + KM_SLEEP);
> + hole = xfs_uuid_table_size++;
> + }
> + xfs_uuid_table[hole] = *uuid;
> + mutex_unlock(&xfs_uuid_table_mutex);
> +
> + return 0;
> +
> + out_duplicate:
> + mutex_unlock(&xfs_uuid_table_mutex);
> + cmn_err(CE_WARN, "XFS: Filesystem %s has duplicate UUID - can't mount",
> + mp->m_fsname);
> + return XFS_ERROR(EINVAL);
> +}
> +
> +STATIC void
> +xfs_uuid_unmount(
> + struct xfs_mount *mp)
> +{
> + uuid_t *uuid = &mp->m_sb.sb_uuid;
> + int i;
> +
> + if (mp->m_flags & XFS_MOUNT_NOUUID)
> + return;
> +
> + mutex_lock(&xfs_uuid_table_mutex);
> + for (i = 0; i < xfs_uuid_table_size; i++) {
> + if (uuid_is_nil(&xfs_uuid_table[i]))
> + continue;
> + if (!uuid_equal(uuid, &xfs_uuid_table[i]))
> + continue;
> + memset(&xfs_uuid_table[i], 0, sizeof(uuid_t));
> + break;
> + }
> + ASSERT(i < xfs_uuid_table_size);
> + mutex_unlock(&xfs_uuid_table_mutex);
> +}
> +
> +
> /*
> * Free up the resources associated with a mount structure. Assume that
> * the structure was initially zeroed, so we can tell which fields got
> @@ -1016,18 +1093,9 @@ xfs_mountfs(
>
> mp->m_maxioffset = xfs_max_file_offset(sbp->sb_blocklog);
>
> - /*
> - * XFS uses the uuid from the superblock as the unique
> - * identifier for fsid. We can not use the uuid from the volume
> - * since a single partition filesystem is identical to a single
> - * partition volume/filesystem.
> - */
> - if (!(mp->m_flags & XFS_MOUNT_NOUUID)) {
> - if (xfs_uuid_mount(mp)) {
> - error = XFS_ERROR(EINVAL);
> - goto out;
> - }
> - }
> + error = xfs_uuid_mount(mp);
> + if (error)
> + goto out;
>
> /*
> * Set the minimum read and write sizes
> @@ -1275,8 +1343,7 @@ xfs_mountfs(
> out_free_perag:
> xfs_free_perag(mp);
> out_remove_uuid:
> - if (!(mp->m_flags & XFS_MOUNT_NOUUID))
> - uuid_table_remove(&mp->m_sb.sb_uuid);
> + xfs_uuid_unmount(mp);
> out:
> return error;
> }
> @@ -1351,9 +1418,7 @@ xfs_unmountfs(
> xfs_unmountfs_wait(mp); /* wait for async bufs */
> xfs_log_unmount_write(mp);
> xfs_log_unmount(mp);
> -
> - if ((mp->m_flags & XFS_MOUNT_NOUUID) == 0)
> - uuid_table_remove(&mp->m_sb.sb_uuid);
> + xfs_uuid_unmount(mp);
>
> #if defined(DEBUG)
> xfs_errortag_clearall(mp, 0);
> @@ -1855,29 +1920,6 @@ xfs_freesb(
> }
>
> /*
> - * See if the UUID is unique among mounted XFS filesystems.
> - * Mount fails if UUID is nil or a FS with the same UUID is already mounted.
> - */
> -STATIC int
> -xfs_uuid_mount(
> - xfs_mount_t *mp)
> -{
> - if (uuid_is_nil(&mp->m_sb.sb_uuid)) {
> - cmn_err(CE_WARN,
> - "XFS: Filesystem %s has nil UUID - can't mount",
> - mp->m_fsname);
> - return -1;
> - }
> - if (!uuid_table_insert(&mp->m_sb.sb_uuid)) {
> - cmn_err(CE_WARN,
> - "XFS: Filesystem %s has duplicate UUID - can't mount",
> - mp->m_fsname);
> - return -1;
> - }
> - return 0;
> -}
> -
> -/*
> * Used to log changes to the superblock unit and width fields which could
> * be altered by the mount options, as well as any potential sb_features2
> * fixup. Only the first superblock is updated.
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
---end quoted text---
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2009-03-29 7:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-18 9:41 [PATCH 0/5] A couple more patches for 2.6.30 Christoph Hellwig
2009-03-18 9:41 ` [PATCH 1/5] xfs: cleanup uuid handling Christoph Hellwig
2009-03-29 7:45 ` Christoph Hellwig [this message]
2009-03-30 6:06 ` Felix Blyakher
2009-03-18 9:41 ` [PATCH 2/5] xfs: kill mutex_t typedef Christoph Hellwig
2009-03-21 3:51 ` Eric Sandeen
2009-03-26 22:31 ` Felix Blyakher
2009-03-18 9:41 ` [PATCH 3/5] xfs: kill ino64 mount option Christoph Hellwig
2009-03-21 3:54 ` Eric Sandeen
2009-03-21 20:08 ` Christoph Hellwig
2009-03-21 22:12 ` Eric Sandeen
2009-03-24 8:30 ` Dave Chinner
2009-03-24 13:11 ` Eric Sandeen
2009-03-26 22:37 ` Felix Blyakher
2009-03-18 9:41 ` [PATCH 4/5] xfs: remove m_litino Christoph Hellwig
2009-03-21 3:57 ` Eric Sandeen
2009-03-21 20:09 ` Christoph Hellwig
2009-03-26 22:41 ` Felix Blyakher
2009-03-29 7:48 ` Christoph Hellwig
2009-03-18 9:41 ` [PATCH 5/5] xfs: remove m_attroffset Christoph Hellwig
2009-03-26 19:42 ` Josef 'Jeff' Sipek
2009-03-29 7:50 ` Christoph Hellwig
2009-04-06 22:11 ` Felix Blyakher
2009-04-07 16:01 ` Christoph Hellwig
2009-03-29 9:28 ` [PATCH 0/5] A couple more patches for 2.6.30 Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090329074507.GF16402@infradead.org \
--to=hch@infradead.org \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox