mirror of
https://github.com/versity/scoutfs.git
synced 2026-02-08 03:30:46 +00:00
scoutfs: add per-mount random id
Calculate a random id which identifies the life of a particular mount. This will be visible in messages and tracing and will replace the server-assigned node_id in persistent structures and protocols. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
@@ -343,6 +343,24 @@ static int scoutfs_debugfs_setup(struct super_block *sb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate a random id for the mount very early, it's used in tracing
|
||||
* and message output. The system assumes that a rid of 0 can't exist. We're
|
||||
* also paranoid and avoid rids that are likely the result of bad rng.
|
||||
*/
|
||||
static int assign_random_id(struct scoutfs_sb_info *sbi)
|
||||
{
|
||||
unsigned int attempts = 0;
|
||||
|
||||
do {
|
||||
if (++attempts == 100)
|
||||
return -EIO;
|
||||
get_random_bytes(&sbi->rid, sizeof(sbi->rid));
|
||||
} while (sbi->rid == 0 || sbi->rid == ~0ULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int scoutfs_fill_super(struct super_block *sb, void *data, int silent)
|
||||
{
|
||||
struct scoutfs_sb_info *sbi;
|
||||
@@ -366,6 +384,10 @@ static int scoutfs_fill_super(struct super_block *sb, void *data, int silent)
|
||||
if (!sbi)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = assign_random_id(sbi);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
spin_lock_init(&sbi->next_ino_lock);
|
||||
init_waitqueue_head(&sbi->trans_hold_wq);
|
||||
spin_lock_init(&sbi->data_wait_root.lock);
|
||||
|
||||
@@ -31,6 +31,7 @@ struct scoutfs_sb_info {
|
||||
struct super_block *sb;
|
||||
|
||||
/* assigned once at the start of each mount, read-only */
|
||||
u64 rid;
|
||||
u64 node_id;
|
||||
struct scoutfs_lock *node_id_lock;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user