提交 1f75cdd5 编写于 作者: T Tom Lane

Ensure that kernel error code is included in smgr-level error reports.

Tweak mdcreate a little bit so that it returns the right errno.
上级 81b30f2c
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.70 2000/06/02 15:57:26 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.71 2000/06/19 23:37:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -130,34 +130,41 @@ mdcreate(Relation reln) ...@@ -130,34 +130,41 @@ mdcreate(Relation reln)
char *path; char *path;
Assert(reln->rd_unlinked && reln->rd_fd < 0); Assert(reln->rd_unlinked && reln->rd_fd < 0);
path = relpath(RelationGetPhysicalRelationName(reln)); path = relpath(RelationGetPhysicalRelationName(reln));
fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600); fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
/* /*
* During bootstrap processing, we skip that check, because pg_time, * For cataloged relations, pg_class is guaranteed to have a unique
* pg_variable, and pg_log get created before their .bki file entries
* are processed.
*
* For cataloged relations,pg_class is guaranteed to have an unique
* record with the same relname by the unique index. So we are able to * record with the same relname by the unique index. So we are able to
* reuse existent files for new catloged relations. Currently we reuse * reuse existent files for new cataloged relations. Currently we reuse
* them in the following cases. 1. they are empty. 2. they are used * them in the following cases. 1. they are empty. 2. they are used
* for Index relations and their size == BLCKSZ * 2. * for Index relations and their size == BLCKSZ * 2.
*
* During bootstrap processing, we skip that check, because pg_time,
* pg_variable, and pg_log get created before their .bki file entries
* are processed.
*/ */
if (fd < 0) if (fd < 0)
{ {
int save_errno = errno;
if (!IsBootstrapProcessingMode() && if (!IsBootstrapProcessingMode() &&
reln->rd_rel->relkind == RELKIND_UNCATALOGED) reln->rd_rel->relkind == RELKIND_UNCATALOGED)
return -1; return -1;
fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600); fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
if (fd < 0) if (fd < 0)
{
/* be sure to return the error reported by create, not open */
errno = save_errno;
return -1; return -1;
}
if (!IsBootstrapProcessingMode()) if (!IsBootstrapProcessingMode())
{ {
bool reuse = false; bool reuse = false;
int len = FileSeek(fd, 0L, SEEK_END); long len = FileSeek(fd, 0L, SEEK_END);
if (len == 0) if (len == 0)
reuse = true; reuse = true;
...@@ -167,9 +174,12 @@ mdcreate(Relation reln) ...@@ -167,9 +174,12 @@ mdcreate(Relation reln)
if (!reuse) if (!reuse)
{ {
FileClose(fd); FileClose(fd);
/* be sure to return the error reported by create */
errno = save_errno;
return -1; return -1;
} }
} }
errno = 0;
} }
reln->rd_unlinked = false; reln->rd_unlinked = false;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.36 2000/06/05 07:28:47 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.37 2000/06/19 23:37:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -105,7 +105,7 @@ smgrinit() ...@@ -105,7 +105,7 @@ smgrinit()
if (smgrsw[i].smgr_init) if (smgrsw[i].smgr_init)
{ {
if ((*(smgrsw[i].smgr_init)) () == SM_FAIL) if ((*(smgrsw[i].smgr_init)) () == SM_FAIL)
elog(FATAL, "initialization failed on %s", elog(FATAL, "initialization failed on %s: %m",
DatumGetCString(DirectFunctionCall1(smgrout, DatumGetCString(DirectFunctionCall1(smgrout,
Int16GetDatum(i)))); Int16GetDatum(i))));
} }
...@@ -127,7 +127,7 @@ smgrshutdown(int dummy) ...@@ -127,7 +127,7 @@ smgrshutdown(int dummy)
if (smgrsw[i].smgr_shutdown) if (smgrsw[i].smgr_shutdown)
{ {
if ((*(smgrsw[i].smgr_shutdown)) () == SM_FAIL) if ((*(smgrsw[i].smgr_shutdown)) () == SM_FAIL)
elog(FATAL, "shutdown failed on %s", elog(FATAL, "shutdown failed on %s: %m",
DatumGetCString(DirectFunctionCall1(smgrout, DatumGetCString(DirectFunctionCall1(smgrout,
Int16GetDatum(i)))); Int16GetDatum(i))));
} }
...@@ -146,7 +146,7 @@ smgrcreate(int16 which, Relation reln) ...@@ -146,7 +146,7 @@ smgrcreate(int16 which, Relation reln)
int fd; int fd;
if ((fd = (*(smgrsw[which].smgr_create)) (reln)) < 0) if ((fd = (*(smgrsw[which].smgr_create)) (reln)) < 0)
elog(ERROR, "cannot create %s", RelationGetRelationName(reln)); elog(ERROR, "cannot create %s: %m", RelationGetRelationName(reln));
return fd; return fd;
} }
...@@ -162,7 +162,7 @@ smgrunlink(int16 which, Relation reln) ...@@ -162,7 +162,7 @@ smgrunlink(int16 which, Relation reln)
int status; int status;
if ((status = (*(smgrsw[which].smgr_unlink)) (reln)) == SM_FAIL) if ((status = (*(smgrsw[which].smgr_unlink)) (reln)) == SM_FAIL)
elog(ERROR, "cannot unlink %s", RelationGetRelationName(reln)); elog(ERROR, "cannot unlink %s: %m", RelationGetRelationName(reln));
return status; return status;
} }
...@@ -181,7 +181,7 @@ smgrextend(int16 which, Relation reln, char *buffer) ...@@ -181,7 +181,7 @@ smgrextend(int16 which, Relation reln, char *buffer)
status = (*(smgrsw[which].smgr_extend)) (reln, buffer); status = (*(smgrsw[which].smgr_extend)) (reln, buffer);
if (status == SM_FAIL) if (status == SM_FAIL)
elog(ERROR, "%s: cannot extend. Check free disk space.", elog(ERROR, "cannot extend %s: %m.\n\tCheck free disk space.",
RelationGetRelationName(reln)); RelationGetRelationName(reln));
return status; return status;
...@@ -200,7 +200,7 @@ smgropen(int16 which, Relation reln) ...@@ -200,7 +200,7 @@ smgropen(int16 which, Relation reln)
if ((fd = (*(smgrsw[which].smgr_open)) (reln)) < 0 && if ((fd = (*(smgrsw[which].smgr_open)) (reln)) < 0 &&
!reln->rd_unlinked) !reln->rd_unlinked)
elog(ERROR, "cannot open %s", RelationGetRelationName(reln)); elog(ERROR, "cannot open %s: %m", RelationGetRelationName(reln));
return fd; return fd;
} }
...@@ -220,7 +220,7 @@ int ...@@ -220,7 +220,7 @@ int
smgrclose(int16 which, Relation reln) smgrclose(int16 which, Relation reln)
{ {
if ((*(smgrsw[which].smgr_close)) (reln) == SM_FAIL) if ((*(smgrsw[which].smgr_close)) (reln) == SM_FAIL)
elog(ERROR, "cannot close %s", RelationGetRelationName(reln)); elog(ERROR, "cannot close %s: %m", RelationGetRelationName(reln));
return SM_SUCCESS; return SM_SUCCESS;
} }
...@@ -243,7 +243,7 @@ smgrread(int16 which, Relation reln, BlockNumber blocknum, char *buffer) ...@@ -243,7 +243,7 @@ smgrread(int16 which, Relation reln, BlockNumber blocknum, char *buffer)
status = (*(smgrsw[which].smgr_read)) (reln, blocknum, buffer); status = (*(smgrsw[which].smgr_read)) (reln, blocknum, buffer);
if (status == SM_FAIL) if (status == SM_FAIL)
elog(ERROR, "cannot read block %d of %s", elog(ERROR, "cannot read block %d of %s: %m",
blocknum, RelationGetRelationName(reln)); blocknum, RelationGetRelationName(reln));
return status; return status;
...@@ -265,7 +265,7 @@ smgrwrite(int16 which, Relation reln, BlockNumber blocknum, char *buffer) ...@@ -265,7 +265,7 @@ smgrwrite(int16 which, Relation reln, BlockNumber blocknum, char *buffer)
status = (*(smgrsw[which].smgr_write)) (reln, blocknum, buffer); status = (*(smgrsw[which].smgr_write)) (reln, blocknum, buffer);
if (status == SM_FAIL) if (status == SM_FAIL)
elog(ERROR, "cannot write block %d of %s", elog(ERROR, "cannot write block %d of %s: %m",
blocknum, RelationGetRelationName(reln)); blocknum, RelationGetRelationName(reln));
return status; return status;
...@@ -282,7 +282,7 @@ smgrflush(int16 which, Relation reln, BlockNumber blocknum, char *buffer) ...@@ -282,7 +282,7 @@ smgrflush(int16 which, Relation reln, BlockNumber blocknum, char *buffer)
status = (*(smgrsw[which].smgr_flush)) (reln, blocknum, buffer); status = (*(smgrsw[which].smgr_flush)) (reln, blocknum, buffer);
if (status == SM_FAIL) if (status == SM_FAIL)
elog(ERROR, "cannot flush block %d of %s to stable store", elog(ERROR, "cannot flush block %d of %s to stable store: %m",
blocknum, RelationGetRelationName(reln)); blocknum, RelationGetRelationName(reln));
return status; return status;
...@@ -323,7 +323,7 @@ smgrblindwrt(int16 which, ...@@ -323,7 +323,7 @@ smgrblindwrt(int16 which,
blkno, buffer, dofsync); blkno, buffer, dofsync);
if (status == SM_FAIL) if (status == SM_FAIL)
elog(ERROR, "cannot write block %d of %s [%s] blind", elog(ERROR, "cannot write block %d of %s [%s] blind: %m",
blkno, relstr, dbstr); blkno, relstr, dbstr);
pfree(dbstr); pfree(dbstr);
...@@ -352,7 +352,7 @@ smgrmarkdirty(int16 which, ...@@ -352,7 +352,7 @@ smgrmarkdirty(int16 which,
status = (*(smgrsw[which].smgr_markdirty)) (reln, blkno); status = (*(smgrsw[which].smgr_markdirty)) (reln, blkno);
if (status == SM_FAIL) if (status == SM_FAIL)
elog(ERROR, "cannot mark block %d of %s", elog(ERROR, "cannot mark block %d of %s: %m",
blkno, RelationGetRelationName(reln)); blkno, RelationGetRelationName(reln));
return status; return status;
...@@ -384,7 +384,7 @@ smgrblindmarkdirty(int16 which, ...@@ -384,7 +384,7 @@ smgrblindmarkdirty(int16 which,
blkno); blkno);
if (status == SM_FAIL) if (status == SM_FAIL)
elog(ERROR, "cannot mark block %d of %s [%s] blind", elog(ERROR, "cannot mark block %d of %s [%s] blind: %m",
blkno, relstr, dbstr); blkno, relstr, dbstr);
pfree(dbstr); pfree(dbstr);
...@@ -406,7 +406,7 @@ smgrnblocks(int16 which, Relation reln) ...@@ -406,7 +406,7 @@ smgrnblocks(int16 which, Relation reln)
int nblocks; int nblocks;
if ((nblocks = (*(smgrsw[which].smgr_nblocks)) (reln)) < 0) if ((nblocks = (*(smgrsw[which].smgr_nblocks)) (reln)) < 0)
elog(ERROR, "cannot count blocks for %s", elog(ERROR, "cannot count blocks for %s: %m",
RelationGetRelationName(reln)); RelationGetRelationName(reln));
return nblocks; return nblocks;
...@@ -428,7 +428,7 @@ smgrtruncate(int16 which, Relation reln, int nblocks) ...@@ -428,7 +428,7 @@ smgrtruncate(int16 which, Relation reln, int nblocks)
if (smgrsw[which].smgr_truncate) if (smgrsw[which].smgr_truncate)
{ {
if ((newblks = (*(smgrsw[which].smgr_truncate)) (reln, nblocks)) < 0) if ((newblks = (*(smgrsw[which].smgr_truncate)) (reln, nblocks)) < 0)
elog(ERROR, "cannot truncate %s to %d blocks", elog(ERROR, "cannot truncate %s to %d blocks: %m",
RelationGetRelationName(reln), nblocks); RelationGetRelationName(reln), nblocks);
} }
...@@ -449,7 +449,7 @@ smgrcommit() ...@@ -449,7 +449,7 @@ smgrcommit()
if (smgrsw[i].smgr_commit) if (smgrsw[i].smgr_commit)
{ {
if ((*(smgrsw[i].smgr_commit)) () == SM_FAIL) if ((*(smgrsw[i].smgr_commit)) () == SM_FAIL)
elog(FATAL, "transaction commit failed on %s", elog(FATAL, "transaction commit failed on %s: %m",
DatumGetCString(DirectFunctionCall1(smgrout, DatumGetCString(DirectFunctionCall1(smgrout,
Int16GetDatum(i)))); Int16GetDatum(i))));
} }
...@@ -468,7 +468,7 @@ smgrabort() ...@@ -468,7 +468,7 @@ smgrabort()
if (smgrsw[i].smgr_abort) if (smgrsw[i].smgr_abort)
{ {
if ((*(smgrsw[i].smgr_abort)) () == SM_FAIL) if ((*(smgrsw[i].smgr_abort)) () == SM_FAIL)
elog(FATAL, "transaction abort failed on %s", elog(FATAL, "transaction abort failed on %s: %m",
DatumGetCString(DirectFunctionCall1(smgrout, DatumGetCString(DirectFunctionCall1(smgrout,
Int16GetDatum(i)))); Int16GetDatum(i))));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册