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 629 of file be-fsstubs.c.

631 {
632  int i;
633 
634  if (fscxt == NULL) /* no LO operations in this xact */
635  return;
636 
637  for (i = 0; i < cookies_size; i++)
638  {
639  LargeObjectDesc *lo = cookies[i];
640 
641  if (lo != NULL && lo->subid == mySubid)
642  {
643  if (isCommit)
644  lo->subid = parentSubid;
645  else
646  closeLOfd(i);
647  }
648  }
649 }
static MemoryContext fscxt
Definition: be-fsstubs.c:73
static void closeLOfd(int fd)
Definition: be-fsstubs.c:700
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:69
static int cookies_size
Definition: be-fsstubs.c:70
int i
Definition: isn.c:73
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 583 of file be-fsstubs.c.

584 {
585  int i;
586 
587  if (!lo_cleanup_needed)
588  return; /* no LO operations in this xact */
589 
590  /*
591  * Close LO fds and clear cookies array so that LO fds are no longer good.
592  * The memory context and resource owner holding them are going away at
593  * the end-of-transaction anyway, but on commit, we need to close them to
594  * avoid warnings about leaked resources at commit. On abort we can skip
595  * this step.
596  */
597  if (isCommit)
598  {
599  for (i = 0; i < cookies_size; i++)
600  {
601  if (cookies[i] != NULL)
602  closeLOfd(i);
603  }
604  }
605 
606  /* Needn't actually pfree since we're about to zap context */
607  cookies = NULL;
608  cookies_size = 0;
609 
610  /* Release the LO memory context to prevent permanent memory leaks. */
611  if (fscxt)
613  fscxt = NULL;
614 
615  /* Give inv_api.c a chance to clean up, too */
616  close_lo_relation(isCommit);
617 
618  lo_cleanup_needed = false;
619 }
static bool lo_cleanup_needed
Definition: be-fsstubs.c:72
void close_lo_relation(bool isCommit)
Definition: inv_api.c:99
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218

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 149 of file be-fsstubs.c.

150 {
151  int status;
152  LargeObjectDesc *lobj;
153 
154  if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
155  ereport(ERROR,
156  (errcode(ERRCODE_UNDEFINED_OBJECT),
157  errmsg("invalid large-object descriptor: %d", fd)));
158  lobj = cookies[fd];
159 
160  /*
161  * Check state. inv_read() would throw an error anyway, but we want the
162  * error to be about the FD's state not the underlying privilege; it might
163  * be that the privilege exists but user forgot to ask for read mode.
164  */
165  if ((lobj->flags & IFS_RDLOCK) == 0)
166  ereport(ERROR,
167  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
168  errmsg("large object descriptor %d was not opened for reading",
169  fd)));
170 
171  status = inv_read(lobj, buf, len);
172 
173  return status;
174 }
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
Definition: inv_api.c:490
#define IFS_RDLOCK
Definition: large_object.h:48
const void size_t len
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229
static char * buf
Definition: pg_test_fsync.c:67
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(), len, and status().

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

◆ lo_write()

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

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

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

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

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