Optimization for FreeBSD distro.

This commit is contained in:
longpanda 2021-11-15 16:00:30 +08:00
parent 37e7a539f9
commit 164c8d6505
9 changed files with 301 additions and 19 deletions

View file

@ -65,12 +65,22 @@ static g_taste_t g_ventoy_taste;
static g_ctl_req_t g_ventoy_config;
static g_dumpconf_t g_ventoy_dumpconf;
static const char *g_ventoy_disk_uuid = NULL;
static char g_ventoy_disk_uuid[64];
static bool g_ventoy_tasted = false;
static off_t g_ventoy_disk_size = 0;
static off_t g_disk_map_start = 0;
static off_t g_disk_map_end = 0;
struct g_ventoy_map g_ventoy_map_data __attribute__((aligned (65536))) =
{
{ VENTOY_UNIX_SEG_MAGIC0, VENTOY_UNIX_SEG_MAGIC1, VENTOY_UNIX_SEG_MAGIC2, VENTOY_UNIX_SEG_MAGIC3 },
{ 0, 0, 0, 0 },
0, 0,
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ { 0, 0 } },
{ VENTOY_UNIX_SEG_MAGIC0, VENTOY_UNIX_SEG_MAGIC1, VENTOY_UNIX_SEG_MAGIC2, VENTOY_UNIX_SEG_MAGIC3 }
};
struct g_class g_ventoy_class = {
.name = G_VENTOY_CLASS_NAME,
.version = G_VERSION,
@ -719,16 +729,36 @@ static bool g_vtoy_check_disk(struct g_class *mp, struct g_provider *pp)
if (g_ventoy_disk_size == 0)
{
if (resource_string_value("ventoy", 0, "disksize", &value) == 0)
if (VENTOY_MAP_VALID(g_ventoy_map_data.magic2))
{
G_DEBUG("ventoy.disksize: %s\n", value);
g_ventoy_disk_size = strtouq(value, NULL, 0);
}
G_DEBUG("ventoy map data is valid. [OK]\n");
if (resource_string_value("ventoy", 0, "diskuuid", &g_ventoy_disk_uuid) == 0)
{
for (i = 0; i < 16; i++)
{
sprintf(uuid + i * 2, "%02x", g_ventoy_map_data.diskuuid[i]);
}
snprintf(g_ventoy_disk_uuid, sizeof(g_ventoy_disk_uuid), "%s", uuid);
g_ventoy_disk_size = g_ventoy_map_data.disksize;
G_DEBUG("ventoy.disksize: %llu\n", (unsigned long long)g_ventoy_disk_size);
G_DEBUG("ventoy.diskuuid: <%s>\n", g_ventoy_disk_uuid);
}
else
{
G_DEBUG("ventoy map data is invalid, get from resource\n");
if (resource_string_value("ventoy", 0, "disksize", &value) == 0)
{
G_DEBUG("ventoy.disksize: %s\n", value);
g_ventoy_disk_size = strtouq(value, NULL, 0);
}
if (resource_string_value("ventoy", 0, "diskuuid", &value) == 0)
{
snprintf(g_ventoy_disk_uuid, sizeof(g_ventoy_disk_uuid), "%s", value);
G_DEBUG("ventoy.diskuuid: <%s>\n", value);
}
}
}
if (g_ventoy_disk_size != pp->mediasize)
@ -812,7 +842,16 @@ g_ventoy_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
G_DEBUG("######### ventoy disk <%s> #############\n", pp->name);
resource_int_value("ventoy", 0, "segnum", &disknum);
if (VENTOY_MAP_VALID(g_ventoy_map_data.magic2))
{
disknum = (int)g_ventoy_map_data.segnum;
G_DEBUG("segnum from map data is:<%d>\n", disknum);
}
else
{
resource_int_value("ventoy", 0, "segnum", &disknum);
G_DEBUG("segnum from resource is:<%d>\n", disknum);
}
strlcpy(md.md_magic, G_VENTOY_MAGIC, sizeof(md.md_magic));
md.md_version = G_VENTOY_VERSION;
@ -834,18 +873,29 @@ g_ventoy_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
for (i = 0; i < disknum; i ++)
{
if (resource_string_value("ventoy", i, "seg", &value) == 0)
if (VENTOY_MAP_VALID(g_ventoy_map_data.magic2))
{
g_disk_map_start = strtouq(value, &endpos, 0);
g_disk_map_end = strtouq(endpos + 1, NULL, 0);
G_DEBUG("[map] ventoy segment%d: 0x%llx@0x%llx\n", i,
(long long)g_ventoy_map_data.seglist[i].seg_start_bytes,
(long long)g_ventoy_map_data.seglist[i].seg_end_bytes);
g_disk_map_start = (off_t)g_ventoy_map_data.seglist[i].seg_start_bytes;
g_disk_map_end = (off_t)g_ventoy_map_data.seglist[i].seg_end_bytes;
}
else
{
printf("Failed to parse ventoy seg %d\n", i);
continue;
if (resource_string_value("ventoy", i, "seg", &value) == 0)
{
g_disk_map_start = strtouq(value, &endpos, 0);
g_disk_map_end = strtouq(endpos + 1, NULL, 0);
}
else
{
printf("Failed to parse ventoy seg %d\n", i);
continue;
}
G_DEBUG("[resource] ventoy segment%d: %s\n", i, value);
}
G_DEBUG("ventoy segment%d: %s\n", i, value);
G_VENTOY_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
error = g_ventoy_add_disk(sc, pp, i);

View file

@ -76,6 +76,33 @@ struct g_ventoy_softc {
struct mtx sc_lock;
};
#define sc_name sc_geom->name
#pragma pack(1)
#define VENTOY_UNIX_SEG_MAGIC0 0x11223344
#define VENTOY_UNIX_SEG_MAGIC1 0x55667788
#define VENTOY_UNIX_SEG_MAGIC2 0x99aabbcc
#define VENTOY_UNIX_SEG_MAGIC3 0xddeeff00
#define VENTOY_UNIX_MAX_SEGNUM 40960
struct g_ventoy_seg {
uint64_t seg_start_bytes;
uint64_t seg_end_bytes;
};
struct g_ventoy_map{
uint32_t magic1[4];
uint32_t magic2[4];
uint64_t segnum;
uint64_t disksize;
uint8_t diskuuid[16];
struct g_ventoy_seg seglist[VENTOY_UNIX_MAX_SEGNUM];
uint32_t magic3[4];
};
#pragma pack()
#define VENTOY_MAP_VALID(magic2) \
(magic2[0] == VENTOY_UNIX_SEG_MAGIC0 && magic2[1] == VENTOY_UNIX_SEG_MAGIC1 && magic2[2] == VENTOY_UNIX_SEG_MAGIC2 && magic2[3] == VENTOY_UNIX_SEG_MAGIC3)
#endif /* _KERNEL */
struct g_ventoy_metadata {