X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Flog.c;h=94550584df9d3f826ce96e41373b392b9aac6a03;hb=1ff95dce46dcb5b0358db1fd4fa9698daeb326d7;hp=d9ad11b64a2084dbcf0ea7467a15cc3aeadb2d09;hpb=7355d6bac79109cd893b7b0f4ffac77b0b8f438c;p=bluesky.git diff --git a/bluesky/log.c b/bluesky/log.c index d9ad11b..9455058 100644 --- a/bluesky/log.c +++ b/bluesky/log.c @@ -62,6 +62,16 @@ static void log_commit(BlueSkyLog *log) return; fdatasync(log->fd); + + /* Update disk-space usage statistics for the journal file. */ + g_atomic_int_add(&log->disk_used, -log->current_log->disk_used); + struct stat statbuf; + if (fstat(log->fd, &statbuf) >= 0) { + /* Convert from 512-byte blocks to 1-kB units */ + log->current_log->disk_used = (statbuf.st_blocks + 1) / 2; + } + g_atomic_int_add(&log->disk_used, log->current_log->disk_used); + while (log->committed != NULL) { BlueSkyCloudLog *item = (BlueSkyCloudLog *)log->committed->data; g_mutex_lock(item->lock); @@ -514,6 +524,16 @@ static void cloudlog_partial_fetch_complete(BlueSkyStoreAsync *async, cloudlog_partial_fetch_start(cachefile, async->start, async->len); } + /* Update disk-space usage statistics, since the writes above may have + * consumed more space. */ + g_atomic_int_add(&cachefile->log->disk_used, -cachefile->disk_used); + struct stat statbuf; + if (fstatat(cachefile->log->dirfd, cachefile->filename, &statbuf, 0) >= 0) { + /* Convert from 512-byte blocks to 1-kB units */ + cachefile->disk_used = (statbuf.st_blocks + 1) / 2; + } + g_atomic_int_add(&cachefile->log->disk_used, cachefile->disk_used); + bluesky_cachefile_unref(cachefile); g_cond_broadcast(cachefile->cond); g_mutex_unlock(cachefile->lock); @@ -618,9 +638,7 @@ BlueSkyRCStr *bluesky_log_map_object(BlueSkyCloudLog *item, gboolean map_data) off_t length = lseek(fd, 0, SEEK_END); map->addr = (const char *)mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0); - g_atomic_int_add(&log->disk_used, -(map->len / 1024)); map->len = length; - g_atomic_int_add(&log->disk_used, map->len / 1024); g_atomic_int_inc(&map->refcount);