Lines Matching defs:res

49 metadata_read(struct hast_resource *res, bool openrw)
65 if (res->hr_localfd == -1) {
66 if (provinfo(res, openrw) == -1) {
71 pjdlog_debug(1, "Obtained info about %s.", res->hr_localpath);
73 if (flock(res->hr_localfd, LOCK_EX | LOCK_NB) == -1) {
77 res->hr_localpath);
81 res->hr_localpath);
85 pjdlog_debug(1, "Locked %s.", res->hr_localpath);
105 done = pread(res->hr_localfd, buf, METADATA_SIZE, 0);
116 res->hr_localpath);
122 if (str != NULL && strcmp(str, res->hr_name) != 0) {
124 res->hr_localpath, res->hr_name);
129 res->hr_datasize = nv_get_uint64(nv, "datasize");
130 res->hr_extentsize = (int)nv_get_uint32(nv, "extentsize");
131 res->hr_keepdirty = (int)nv_get_uint32(nv, "keepdirty");
132 res->hr_localoff = nv_get_uint64(nv, "offset");
133 res->hr_resuid = nv_get_uint64(nv, "resuid");
134 if (res->hr_role != HAST_ROLE_PRIMARY) {
136 res->hr_secondary_localcnt = nv_get_uint64(nv, "localcnt");
137 res->hr_secondary_remotecnt = nv_get_uint64(nv, "remotecnt");
139 if (res->hr_role != HAST_ROLE_SECONDARY) {
141 res->hr_primary_localcnt = nv_get_uint64(nv, "localcnt");
142 res->hr_primary_remotecnt = nv_get_uint64(nv, "remotecnt");
147 res->hr_previous_role = HAST_ROLE_PRIMARY;
149 res->hr_previous_role = HAST_ROLE_SECONDARY;
155 res->hr_localpath);
163 close(res->hr_localfd);
164 res->hr_localfd = -1;
171 metadata_write(struct hast_resource *res)
190 nv_add_string(nv, res->hr_name, "resource");
191 nv_add_uint64(nv, (uint64_t)res->hr_datasize, "datasize");
192 nv_add_uint32(nv, (uint32_t)res->hr_extentsize, "extentsize");
193 nv_add_uint32(nv, (uint32_t)res->hr_keepdirty, "keepdirty");
194 nv_add_uint64(nv, (uint64_t)res->hr_localoff, "offset");
195 nv_add_uint64(nv, res->hr_resuid, "resuid");
196 if (res->hr_role == HAST_ROLE_PRIMARY ||
197 res->hr_role == HAST_ROLE_INIT) {
198 nv_add_uint64(nv, res->hr_primary_localcnt, "localcnt");
199 nv_add_uint64(nv, res->hr_primary_remotecnt, "remotecnt");
200 } else /* if (res->hr_role == HAST_ROLE_SECONDARY) */ {
201 PJDLOG_ASSERT(res->hr_role == HAST_ROLE_SECONDARY);
202 nv_add_uint64(nv, res->hr_secondary_localcnt, "localcnt");
203 nv_add_uint64(nv, res->hr_secondary_remotecnt, "remotecnt");
205 nv_add_string(nv, role2str(res->hr_role), "prevrole");
210 res->hr_previous_role = res->hr_role;
217 done = pwrite(res->hr_localfd, buf, METADATA_SIZE, 0);