/** * _exp_file_insert -- Insert the exports directory into the file structure * using the directory as a dict. Also hashes the dirname, * stores it in a uuid type, converts the uuid type to a * string and uses that as the key to the exports map. * The exports map maps an export "uuid" to an export * directory struct. * * @file : Exports file struct to insert into * @dir : Export directory to insert * * Not for external use. */ static void _exp_file_insert(struct exports_file *file, struct export_dir *dir) { data_t *dirdata = NULL; uint32_t hashedval = 0; uuid_t export_uuid = { 0, }; char export_uuid_str[512] = { 0, }; char *dirdup = NULL; GF_VALIDATE_OR_GOTO(GF_EXP, file, out); GF_VALIDATE_OR_GOTO(GF_EXP, dir, out); dirdata = bin_to_data(dir, sizeof(*dir)); dict_set(file->exports_dict, dir->dir_name, dirdata); dirdup = strdupa(dir->dir_name); while (strlen(dirdup) > 0 && dirdup[0] == '/') dirdup++; hashedval = SuperFastHash(dirdup, strlen(dirdup)); memset(export_uuid, 0, sizeof(export_uuid)); memcpy(export_uuid, &hashedval, sizeof(hashedval)); gf_uuid_unparse(export_uuid, export_uuid_str); dict_set(file->exports_map, export_uuid_str, dirdata); out: return; }
/* Given a filehandle and an ip, creates a colon delimited hashkey that is * allocated on the stack. */ static inline void make_hashkey(char *hashkey, struct nfs3_fh *fh, const char *host) { char exportid[256] = {0, }; char gfid[256] = {0, }; char mountid[256] = {0, }; size_t nbytes = 0; gf_uuid_unparse (fh->exportid, exportid); gf_uuid_unparse (fh->gfid, gfid); gf_uuid_unparse (fh->mountid, mountid); nbytes = strlen (exportid) + strlen (gfid) + strlen (host) + strlen (mountid) + 5; hashkey = alloca (nbytes); snprintf (hashkey, nbytes, "%s:%s:%s:%s", exportid, gfid, mountid, host); }
/* Given a filehandle and an ip, creates a colon delimited hashkey. */ static char* make_hashkey(struct nfs3_fh *fh, const char *host) { char *hashkey = NULL; char exportid[256] = {0, }; char gfid[256] = {0, }; char mountid[256] = {0, }; size_t nbytes = 0; gf_uuid_unparse (fh->exportid, exportid); gf_uuid_unparse (fh->gfid, gfid); gf_uuid_unparse (fh->mountid, mountid); nbytes = strlen (exportid) + strlen (host) + strlen (mountid) + 3; hashkey = GF_MALLOC (nbytes, gf_common_mt_char); if (!hashkey) return NULL; snprintf (hashkey, nbytes, "%s:%s:%s", exportid, mountid, host); return hashkey; }
/** * exp_file_dir_from_uuid -- Using a uuid as the key, retrieve an exports * directory from the file. * * @file: File to retrieve data from * @export_uuid: UUID of the export (mountid in the NFS xlator) * * @return : success: Pointer to an export dir struct * failure: NULL */ struct export_dir * exp_file_dir_from_uuid (const struct exports_file *file, const uuid_t export_uuid) { char export_uuid_str[512] = {0, }; data_t *dirdata = NULL; struct export_dir *dir = NULL; gf_uuid_unparse (export_uuid, export_uuid_str); dirdata = dict_get (file->exports_map, export_uuid_str); if (dirdata) dir = (struct export_dir *)dirdata->data; return dir; }