PostgreSQL Source Code git master
be-fsstubs.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int lo_read (int fd, char *buf, int len)
 
int lo_write (int fd, const char *buf, int len)
 
void AtEOXact_LargeObject (bool isCommit)
 
void AtEOSubXact_LargeObject (bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
 

Function Documentation

◆ AtEOSubXact_LargeObject()

void AtEOSubXact_LargeObject ( bool  isCommit,
SubTransactionId  mySubid,
SubTransactionId  parentSubid 
)

Definition at line 653 of file be-fsstubs.c.

655{
656 int i;
657
658 if (fscxt == NULL) /* no LO operations in this xact */
659 return;
660
661 for (i = 0; i < cookies_size; i++)
662 {
664
665 if (lo != NULL && lo->subid == mySubid)
666 {
667 if (isCommit)
668 lo->subid = parentSubid;
669 else
670 closeLOfd(i);
671 }
672 }
673}
static MemoryContext fscxt
Definition: be-fsstubs.c:75
static void closeLOfd(int fd)
Definition: be-fsstubs.c:721
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:71
static int cookies_size
Definition: be-fsstubs.c:72
int i
Definition: isn.c:72
SubTransactionId subid
Definition: large_object.h:43

References closeLOfd(), cookies, cookies_size, fscxt, i, and LargeObjectDesc::subid.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

◆ AtEOXact_LargeObject()

void AtEOXact_LargeObject ( bool  isCommit)

Definition at line 607 of file be-fsstubs.c.

608{
609 int i;
610
612 return; /* no LO operations in this xact */
613
614 /*
615 * Close LO fds and clear cookies array so that LO fds are no longer good.
616 * The memory context and resource owner holding them are going away at
617 * the end-of-transaction anyway, but on commit, we need to close them to
618 * avoid warnings about leaked resources at commit. On abort we can skip
619 * this step.
620 */
621 if (isCommit)
622 {
623 for (i = 0; i < cookies_size; i++)
624 {
625 if (cookies[i] != NULL)
626 closeLOfd(i);
627 }
628 }
629
630 /* Needn't actually pfree since we're about to zap context */
631 cookies = NULL;
632 cookies_size = 0;
633
634 /* Release the LO memory context to prevent permanent memory leaks. */
635 if (fscxt)
637 fscxt = NULL;
638
639 /* Give inv_api.c a chance to clean up, too */
640 close_lo_relation(isCommit);
641
642 lo_cleanup_needed = false;
643}
static bool lo_cleanup_needed
Definition: be-fsstubs.c:74
void close_lo_relation(bool isCommit)
Definition: inv_api.c:97
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454

References close_lo_relation(), closeLOfd(), cookies, cookies_size, fscxt, i, lo_cleanup_needed, and MemoryContextDelete().

Referenced by AbortTransaction(), CommitTransaction(), and PrepareTransaction().

◆ lo_read()

int lo_read ( int  fd,
char *  buf,
int  len 
)

Definition at line 154 of file be-fsstubs.c.

155{
156 int status;
157 LargeObjectDesc *lobj;
158
159 if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
161 (errcode(ERRCODE_UNDEFINED_OBJECT),
162 errmsg("invalid large-object descriptor: %d", fd)));
163 lobj = cookies[fd];
164
165 /*
166 * Check state. inv_read() would throw an error anyway, but we want the
167 * error to be about the FD's state not the underlying privilege; it might
168 * be that the privilege exists but user forgot to ask for read mode.
169 */
170 if ((lobj->flags & IFS_RDLOCK) == 0)
172 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
173 errmsg("large object descriptor %d was not opened for reading",
174 fd)));
175
176 status = inv_read(lobj, buf, len);
177
178 return status;
179}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
Definition: inv_api.c:450
#define IFS_RDLOCK
Definition: large_object.h:48
const void size_t len
static char * buf
Definition: pg_test_fsync.c:72
static int fd(const char *x, int i)
Definition: preproc-init.c:105

References buf, cookies, cookies_size, ereport, errcode(), errmsg(), ERROR, fd(), LargeObjectDesc::flags, IFS_RDLOCK, inv_read(), and len.

Referenced by be_loread(), dumpLOs(), exportFile(), and pickout().

◆ lo_write()

int lo_write ( int  fd,
const char *  buf,
int  len 
)

Definition at line 182 of file be-fsstubs.c.

183{
184 int status;
185 LargeObjectDesc *lobj;
186
187 if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
189 (errcode(ERRCODE_UNDEFINED_OBJECT),
190 errmsg("invalid large-object descriptor: %d", fd)));
191 lobj = cookies[fd];
192
193 /* see comment in lo_read() */
194 if ((lobj->flags & IFS_WRLOCK) == 0)
196 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
197 errmsg("large object descriptor %d was not opened for writing",
198 fd)));
199
200 status = inv_write(lobj, buf, len);
201
202 return status;
203}
int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
Definition: inv_api.c:543
#define IFS_WRLOCK
Definition: large_object.h:49

References buf, cookies, cookies_size, ereport, errcode(), errmsg(), ERROR, fd(), LargeObjectDesc::flags, IFS_WRLOCK, inv_write(), and len.

Referenced by be_lowrite(), dump_lo_buf(), importFile(), and overwrite().