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

References cookies_size, deleteLOfd(), i, inv_close(), and LargeObjectDesc::subid.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

626 {
627  int i;
628 
629  if (fscxt == NULL) /* no LO operations in this xact */
630  return;
631 
632  for (i = 0; i < cookies_size; i++)
633  {
634  LargeObjectDesc *lo = cookies[i];
635 
636  if (lo != NULL && lo->subid == mySubid)
637  {
638  if (isCommit)
639  lo->subid = parentSubid;
640  else
641  {
642  /*
643  * Make sure we do not call inv_close twice if it errors out
644  * for some reason. Better a leak than a crash.
645  */
646  deleteLOfd(i);
647  inv_close(lo);
648  }
649  }
650  }
651 }
static void deleteLOfd(int fd)
Definition: be-fsstubs.c:701
void inv_close(LargeObjectDesc *obj_desc)
Definition: inv_api.c:339
SubTransactionId subid
Definition: large_object.h:43
static int cookies_size
Definition: be-fsstubs.c:68
static MemoryContext fscxt
Definition: be-fsstubs.c:70
int i
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:67

◆ AtEOXact_LargeObject()

void AtEOXact_LargeObject ( bool  isCommit)

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

References close_lo_relation(), cookies_size, deleteLOfd(), i, inv_close(), and MemoryContextDelete().

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

584 {
585  int i;
586 
587  if (fscxt == NULL)
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  * On abort we skip the close step.
593  */
594  for (i = 0; i < cookies_size; i++)
595  {
596  if (cookies[i] != NULL)
597  {
598  if (isCommit)
599  inv_close(cookies[i]);
600  deleteLOfd(i);
601  }
602  }
603 
604  /* Needn't actually pfree since we're about to zap context */
605  cookies = NULL;
606  cookies_size = 0;
607 
608  /* Release the LO memory context to prevent permanent memory leaks. */
610  fscxt = NULL;
611 
612  /* Give inv_api.c a chance to clean up, too */
613  close_lo_relation(isCommit);
614 }
static void deleteLOfd(int fd)
Definition: be-fsstubs.c:701
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
void inv_close(LargeObjectDesc *obj_desc)
Definition: inv_api.c:339
void close_lo_relation(bool isCommit)
Definition: inv_api.c:98
static int cookies_size
Definition: be-fsstubs.c:68
static MemoryContext fscxt
Definition: be-fsstubs.c:70
int i
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:67

◆ lo_read()

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

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

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

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

143 {
144  int status;
145  LargeObjectDesc *lobj;
146 
147  if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
148  ereport(ERROR,
149  (errcode(ERRCODE_UNDEFINED_OBJECT),
150  errmsg("invalid large-object descriptor: %d", fd)));
151  lobj = cookies[fd];
152 
153  /*
154  * Check state. inv_read() would throw an error anyway, but we want the
155  * error to be about the FD's state not the underlying privilege; it might
156  * be that the privilege exists but user forgot to ask for read mode.
157  */
158  if ((lobj->flags & IFS_RDLOCK) == 0)
159  ereport(ERROR,
160  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
161  errmsg("large object descriptor %d was not opened for reading",
162  fd)));
163 
164  status = inv_read(lobj, buf, len);
165 
166  return status;
167 }
#define IFS_RDLOCK
Definition: large_object.h:48
int errcode(int sqlerrcode)
Definition: elog.c:575
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:67
#define ereport(elevel, rest)
Definition: elog.h:122
static int cookies_size
Definition: be-fsstubs.c:68
int errmsg(const char *fmt,...)
Definition: elog.c:797
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:67
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
Definition: inv_api.c:494

◆ lo_write()

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

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

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

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

171 {
172  int status;
173  LargeObjectDesc *lobj;
174 
175  if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
176  ereport(ERROR,
177  (errcode(ERRCODE_UNDEFINED_OBJECT),
178  errmsg("invalid large-object descriptor: %d", fd)));
179  lobj = cookies[fd];
180 
181  /* see comment in lo_read() */
182  if ((lobj->flags & IFS_WRLOCK) == 0)
183  ereport(ERROR,
184  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
185  errmsg("large object descriptor %d was not opened for writing",
186  fd)));
187 
188  status = inv_write(lobj, buf, len);
189 
190  return status;
191 }
int errcode(int sqlerrcode)
Definition: elog.c:575
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define IFS_WRLOCK
Definition: large_object.h:49
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:67
#define ereport(elevel, rest)
Definition: elog.h:122
static int cookies_size
Definition: be-fsstubs.c:68
int errmsg(const char *fmt,...)
Definition: elog.c:797
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:67
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
Definition: inv_api.c:587