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

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

Referenced by AbortSubTransaction(), and CommitSubTransaction().

634 {
635  int i;
636 
637  if (fscxt == NULL) /* no LO operations in this xact */
638  return;
639 
640  for (i = 0; i < cookies_size; i++)
641  {
642  LargeObjectDesc *lo = cookies[i];
643 
644  if (lo != NULL && lo->subid == mySubid)
645  {
646  if (isCommit)
647  lo->subid = parentSubid;
648  else
649  {
650  /*
651  * Make sure we do not call inv_close twice if it errors out
652  * for some reason. Better a leak than a crash.
653  */
654  deleteLOfd(i);
655  inv_close(lo);
656  }
657  }
658  }
659 }
static void deleteLOfd(int fd)
Definition: be-fsstubs.c:709
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 591 of file be-fsstubs.c.

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

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

592 {
593  int i;
594 
595  if (fscxt == NULL)
596  return; /* no LO operations in this xact */
597 
598  /*
599  * Close LO fds and clear cookies array so that LO fds are no longer good.
600  * On abort we skip the close step.
601  */
602  for (i = 0; i < cookies_size; i++)
603  {
604  if (cookies[i] != NULL)
605  {
606  if (isCommit)
607  inv_close(cookies[i]);
608  deleteLOfd(i);
609  }
610  }
611 
612  /* Needn't actually pfree since we're about to zap context */
613  cookies = NULL;
614  cookies_size = 0;
615 
616  /* Release the LO memory context to prevent permanent memory leaks. */
618  fscxt = NULL;
619 
620  /* Give inv_api.c a chance to clean up, too */
621  close_lo_relation(isCommit);
622 }
static void deleteLOfd(int fd)
Definition: be-fsstubs.c:709
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
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:608
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:141
static int cookies_size
Definition: be-fsstubs.c:68
int errmsg(const char *fmt,...)
Definition: elog.c:822
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:67
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:226
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:608
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:141
static int cookies_size
Definition: be-fsstubs.c:68
int errmsg(const char *fmt,...)
Definition: elog.c:822
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:67
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:226
int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
Definition: inv_api.c:587