diff -r 535004faa1a5 -r 0cb4eda146c4 src/server/plugins/postgresql/vfs.c --- a/src/server/plugins/postgresql/vfs.c Thu Jan 27 21:24:27 2022 +0100 +++ b/src/server/plugins/postgresql/vfs.c Fri Jan 28 15:44:30 2022 +0100 @@ -55,6 +55,46 @@ pg_vfs_dirio_close }; + + +VFS* pg_vfs_create(Session *sn, Request *rq, pblock *pb) { + // resourcepool is required + char *resource_pool = pblock_find("resourcepool", pb); + if(!resource_pool) { + log_ereport(LOG_MISCONFIG, "pg_vfs_create: missing resourcepool parameter"); + return NULL; + } + + // get the resource first (most likely to fail due to misconfig) + ResourceData *resdata = resourcepool_lookup(sn, rq, resource_pool, 0); + if(!resdata) { + log_ereport(LOG_MISCONFIG, "postgresql vfs: resource pool %s not found", resource_pool); + return NULL; + } + // resdata will be freed automatically when the request is finished + + // Create a new VFS object and a separate instance object + // VFS contains fptrs that can be copied from pg_vfs_class + // instance contains request specific data (PGconn) + VFS *vfs = pool_malloc(sn->pool, sizeof(VFS)); + if(!vfs) { + return NULL; + } + + PgVFS *vfs_priv = pool_malloc(sn->pool, sizeof(PgVFS)); + if(!vfs_priv) { + pool_free(sn->pool, vfs); + return NULL; + } + + memcpy(vfs, &pg_vfs_class, sizeof(VFS)); + vfs->flags = 0; + vfs->instance = vfs_priv; + + return vfs; +} + + /* -------------------------- VFS functions -------------------------- */ SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags) {