Lines Matching defs:res

47 metadata_read(struct hast_resource *res, bool openrw)
63 if (res->hr_localfd == -1) {
64 if (provinfo(res, openrw) == -1) {
69 pjdlog_debug(1, "Obtained info about %s.", res->hr_localpath);
71 if (flock(res->hr_localfd, LOCK_EX | LOCK_NB) == -1) {
75 res->hr_localpath);
79 res->hr_localpath);
83 pjdlog_debug(1, "Locked %s.", res->hr_localpath);
103 done = pread(res->hr_localfd, buf, METADATA_SIZE, 0);
114 res->hr_localpath);
120 if (str != NULL && strcmp(str, res->hr_name) != 0) {
122 res->hr_localpath, res->hr_name);
127 res->hr_datasize = nv_get_uint64(nv, "datasize");
128 res->hr_extentsize = (int)nv_get_uint32(nv, "extentsize");
129 res->hr_keepdirty = (int)nv_get_uint32(nv, "keepdirty");
130 res->hr_localoff = nv_get_uint64(nv, "offset");
131 res->hr_resuid = nv_get_uint64(nv, "resuid");
132 if (res->hr_role != HAST_ROLE_PRIMARY) {
134 res->hr_secondary_localcnt = nv_get_uint64(nv, "localcnt");
135 res->hr_secondary_remotecnt = nv_get_uint64(nv, "remotecnt");
137 if (res->hr_role != HAST_ROLE_SECONDARY) {
139 res->hr_primary_localcnt = nv_get_uint64(nv, "localcnt");
140 res->hr_primary_remotecnt = nv_get_uint64(nv, "remotecnt");
145 res->hr_previous_role = HAST_ROLE_PRIMARY;
147 res->hr_previous_role = HAST_ROLE_SECONDARY;
153 res->hr_localpath);
161 close(res->hr_localfd);
162 res->hr_localfd = -1;
169 metadata_write(struct hast_resource *res)
188 nv_add_string(nv, res->hr_name, "resource");
189 nv_add_uint64(nv, (uint64_t)res->hr_datasize, "datasize");
190 nv_add_uint32(nv, (uint32_t)res->hr_extentsize, "extentsize");
191 nv_add_uint32(nv, (uint32_t)res->hr_keepdirty, "keepdirty");
192 nv_add_uint64(nv, (uint64_t)res->hr_localoff, "offset");
193 nv_add_uint64(nv, res->hr_resuid, "resuid");
194 if (res->hr_role == HAST_ROLE_PRIMARY ||
195 res->hr_role == HAST_ROLE_INIT) {
196 nv_add_uint64(nv, res->hr_primary_localcnt, "localcnt");
197 nv_add_uint64(nv, res->hr_primary_remotecnt, "remotecnt");
198 } else /* if (res->hr_role == HAST_ROLE_SECONDARY) */ {
199 PJDLOG_ASSERT(res->hr_role == HAST_ROLE_SECONDARY);
200 nv_add_uint64(nv, res->hr_secondary_localcnt, "localcnt");
201 nv_add_uint64(nv, res->hr_secondary_remotecnt, "remotecnt");
203 nv_add_string(nv, role2str(res->hr_role), "prevrole");
208 res->hr_previous_role = res->hr_role;
215 done = pwrite(res->hr_localfd, buf, METADATA_SIZE, 0);