Tweak prev commit again

Make sure errors are propagated from init_meta
vmware
Howard Chu 11 years ago
parent bc03467040
commit 2cc2574d84
  1. 56
      libraries/liblmdb/mdb.c

@ -2949,6 +2949,19 @@ mdb_env_init_meta(MDB_env *env, MDB_meta *meta)
MDB_page *p, *q; MDB_page *p, *q;
int rc; int rc;
unsigned int psize; unsigned int psize;
#ifdef _WIN32
DWORD len;
OVERLAPPED ov;
memset(&ov, 0, sizeof(ov));
#define DO_PWRITE(rc, fd, ptr, size, len, pos) do { \
ov.Offset = pos; \
rc = WriteFile(fd, ptr, size, &len, &ov); } while(0)
#else
int len;
#define DO_PWRITE(rc, fd, ptr, size, len, pos) do { \
len = pwrite(fd, ptr, size, pos); \
rc = (len >= 0); } while(0)
#endif
DPUTS("writing new meta page"); DPUTS("writing new meta page");
@ -2974,18 +2987,13 @@ mdb_env_init_meta(MDB_env *env, MDB_meta *meta)
q->mp_flags = P_META; q->mp_flags = P_META;
*(MDB_meta *)METADATA(q) = *meta; *(MDB_meta *)METADATA(q) = *meta;
#ifdef _WIN32 DO_PWRITE(rc, env->me_fd, p, psize * 2, len, 0);
{ if (!rc)
DWORD len; rc = ErrCode();
OVERLAPPED ov; else if (len == psize * 2)
memset(&ov, 0, sizeof(ov)); rc = MDB_SUCCESS;
rc = WriteFile(env->me_fd, p, psize * 2, &len, &ov); else
rc = (len == psize * 2) ? MDB_SUCCESS : ErrCode(); rc = ENOSPC;
}
#else
rc = pwrite(env->me_fd, p, psize * 2, 0);
rc = (rc == (int)psize * 2) ? MDB_SUCCESS : ErrCode();
#endif
free(p); free(p);
return rc; return rc;
} }
@ -4009,11 +4017,11 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd)
char *ptr; char *ptr;
#ifdef _WIN32 #ifdef _WIN32
DWORD len, w2; DWORD len, w2;
#define DOWRITE(fd, ptr, w2, len) WriteFile(fd, ptr, w2, &len) #define DO_WRITE(rc, fd, ptr, w2, len) rc = WriteFile(fd, ptr, w2, &len, NULL)
#else #else
ssize_t len; ssize_t len;
size_t w2; size_t w2;
#define DOWRITE(fd, ptr, w2, len) len = write(fd, ptr, w2) #define DO_WRITE(rc, fd, ptr, w2, len) len = write(fd, ptr, w2); rc = (len >= 0)
#endif #endif
/* Do the lock/unlock of the reader mutex before starting the /* Do the lock/unlock of the reader mutex before starting the
@ -4039,24 +4047,23 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd)
wsize = env->me_psize * 2; wsize = env->me_psize * 2;
ptr = env->me_map; ptr = env->me_map;
{
w2 = wsize; w2 = wsize;
while (w2 > 0) { while (w2 > 0) {
DOWRITE(fd, ptr, w2, len); DO_WRITE(rc, fd, ptr, w2, len);
if (len > 0) { if (!rc) {
rc = ErrCode();
break;
} else if (len > 0) {
rc = MDB_SUCCESS; rc = MDB_SUCCESS;
ptr += len; ptr += len;
w2 -= len; w2 -= len;
continue; continue;
} else { } else {
/* Non-blocking or async handles are not supported */ /* Non-blocking or async handles are not supported */
rc = ErrCode();
if (!rc)
rc = EIO; rc = EIO;
break; break;
} }
} }
}
if (env->me_txns) if (env->me_txns)
UNLOCK_MUTEX_W(env); UNLOCK_MUTEX_W(env);
@ -4069,15 +4076,16 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd)
w2 = MAX_WRITE; w2 = MAX_WRITE;
else else
w2 = wsize; w2 = wsize;
DOWRITE(fd, ptr, w2, len); DO_WRITE(rc, fd, ptr, w2, len);
if (len > 0) { if (!rc) {
rc = ErrCode();
break;
} else if (len > 0) {
rc = MDB_SUCCESS; rc = MDB_SUCCESS;
ptr += len; ptr += len;
wsize -= len; wsize -= len;
continue; continue;
} else { } else {
rc = ErrCode();
if (!rc)
rc = EIO; rc = EIO;
break; break;
} }

Loading…
Cancel
Save