Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
fc8e6c77
Commit
fc8e6c77
authored
Feb 21, 2000
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oops, commited a test version of this file by accident. Revert.
parent
393f3132
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
59 deletions
+73
-59
src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/bufmgr.c
+3
-14
src/backend/utils/adt/network.c
src/backend/utils/adt/network.c
+70
-45
No files found.
src/backend/storage/buffer/bufmgr.c
View file @
fc8e6c77
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.7
4 2000/02/21 18:47:03
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.7
5 2000/02/21 18:49:00
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -453,7 +453,6 @@ BufferAlloc(Relation reln,
*/
Assert
(
buf
->
refcount
==
0
);
buf
->
refcount
=
1
;
Assert
(
PrivateRefCount
[
BufferDescriptorGetBuffer
(
buf
)
-
1
]
==
0
);
PrivateRefCount
[
BufferDescriptorGetBuffer
(
buf
)
-
1
]
=
1
;
if
(
buf
->
flags
&
BM_DIRTY
)
...
...
@@ -543,7 +542,6 @@ BufferAlloc(Relation reln,
inProgress
=
FALSE
;
buf
->
flags
&=
~
BM_IO_IN_PROGRESS
;
TerminateBufferIO
(
buf
);
Assert
(
PrivateRefCount
[
BufferDescriptorGetBuffer
(
buf
)
-
1
]
==
1
);
PrivateRefCount
[
BufferDescriptorGetBuffer
(
buf
)
-
1
]
=
0
;
buf
->
refcount
--
;
buf
=
(
BufferDesc
*
)
NULL
;
...
...
@@ -570,7 +568,6 @@ BufferAlloc(Relation reln,
{
TerminateBufferIO
(
buf
);
/* give up the buffer since we don't need it any more */
Assert
(
PrivateRefCount
[
BufferDescriptorGetBuffer
(
buf
)
-
1
]
==
1
);
PrivateRefCount
[
BufferDescriptorGetBuffer
(
buf
)
-
1
]
=
0
;
Assert
(
buf
->
refcount
>
0
);
buf
->
refcount
--
;
...
...
@@ -1472,16 +1469,8 @@ ReleaseRelationBuffers(Relation rel)
if
(
!
(
buf
->
flags
&
BM_FREE
))
{
/* Assert checks that buffer will actually get freed! */
Assert
(
buf
->
refcount
==
1
);
if
(
PrivateRefCount
[
i
-
1
]
<=
0
)
{
fprintf
(
stderr
,
"Nonpositive PrivateRefCount on buffer for %s
\n
"
,
RelationGetRelationName
(
rel
));
fflush
(
stderr
);
*
((
char
*
)
0
)
=
0
;
abort
();
}
Assert
(
PrivateRefCount
[
i
-
1
]
==
1
);
Assert
(
PrivateRefCount
[
i
-
1
]
==
1
&&
buf
->
refcount
==
1
);
/* ReleaseBuffer expects we do not hold the lock at entry */
SpinRelease
(
BufMgrLock
);
holding
=
false
;
...
...
src/backend/utils/adt/network.c
View file @
fc8e6c77
...
...
@@ -3,23 +3,22 @@
* is for IP V4 CIDR notation, but prepared for V6: just
* add the necessary bits where the comments indicate.
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.17 2000/02/21 18:47:07 tgl Exp $
*
* $Id: network.c,v 1.18 2000/02/21 18:49:54 tgl Exp $
* Jon Postel RIP 16 Oct 1998
*/
#include "postgres.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "postgres.h"
#include "utils/builtins.h"
static
int
v4bitncmp
(
unsigned
long
a1
,
unsigned
long
a2
,
int
bits
);
static
int
v4bitncmp
(
unsigned
int
a1
,
unsigned
int
a2
,
int
bits
);
/*
* Access macros. Add IPV6 support.
...
...
@@ -40,7 +39,6 @@ static int v4bitncmp(unsigned long a1, unsigned long a2, int bits);
#define ip_v4addr(inetptr) \
(((inet_struct *)VARDATA(inetptr))->addr.ipv4_addr)
/* Common input routine */
static
inet
*
network_in
(
char
*
src
,
int
type
)
...
...
@@ -129,8 +127,7 @@ cidr_out(inet *src)
}
/*
* Boolean tests for ordering operators --- must agree with sorting
* operator network_cmp().
* Boolean tests for magnitude. Add V4/V6 testing!
*/
bool
...
...
@@ -138,7 +135,19 @@ network_lt(inet *a1, inet *a2)
{
if
(
!
PointerIsValid
(
a1
)
||
!
PointerIsValid
(
a2
))
return
FALSE
;
return
(
bool
)
(
network_cmp
(
a1
,
a2
)
<
0
);
if
((
ip_family
(
a1
)
==
AF_INET
)
&&
(
ip_family
(
a2
)
==
AF_INET
))
{
int
order
=
v4bitncmp
(
ip_v4addr
(
a1
),
ip_v4addr
(
a2
),
ip_bits
(
a2
));
return
((
order
<
0
)
||
((
order
==
0
)
&&
(
ip_bits
(
a1
)
<
ip_bits
(
a2
))));
}
else
{
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"cannot compare address families %d and %d"
,
ip_family
(
a1
),
ip_family
(
a2
));
return
FALSE
;
}
}
bool
...
...
@@ -146,7 +155,7 @@ network_le(inet *a1, inet *a2)
{
if
(
!
PointerIsValid
(
a1
)
||
!
PointerIsValid
(
a2
))
return
FALSE
;
return
(
bool
)
(
network_cmp
(
a1
,
a2
)
<=
0
);
return
(
network_lt
(
a1
,
a2
)
||
network_eq
(
a1
,
a2
)
);
}
bool
...
...
@@ -154,7 +163,18 @@ network_eq(inet *a1, inet *a2)
{
if
(
!
PointerIsValid
(
a1
)
||
!
PointerIsValid
(
a2
))
return
FALSE
;
return
(
bool
)
(
network_cmp
(
a1
,
a2
)
==
0
);
if
((
ip_family
(
a1
)
==
AF_INET
)
&&
(
ip_family
(
a2
)
==
AF_INET
))
{
return
((
ip_bits
(
a1
)
==
ip_bits
(
a2
))
&&
(
v4bitncmp
(
ip_v4addr
(
a1
),
ip_v4addr
(
a2
),
ip_bits
(
a1
))
==
0
));
}
else
{
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"cannot compare address families %d and %d"
,
ip_family
(
a1
),
ip_family
(
a2
));
return
FALSE
;
}
}
bool
...
...
@@ -162,7 +182,7 @@ network_ge(inet *a1, inet *a2)
{
if
(
!
PointerIsValid
(
a1
)
||
!
PointerIsValid
(
a2
))
return
FALSE
;
return
(
bool
)
(
network_cmp
(
a1
,
a2
)
>=
0
);
return
(
network_gt
(
a1
,
a2
)
||
network_eq
(
a1
,
a2
)
);
}
bool
...
...
@@ -170,44 +190,29 @@ network_gt(inet *a1, inet *a2)
{
if
(
!
PointerIsValid
(
a1
)
||
!
PointerIsValid
(
a2
))
return
FALSE
;
return
(
bool
)
(
network_cmp
(
a1
,
a2
)
>
0
);
}
bool
network_ne
(
inet
*
a1
,
inet
*
a2
)
{
if
(
!
PointerIsValid
(
a1
)
||
!
PointerIsValid
(
a2
))
return
FALSE
;
return
(
bool
)
(
network_cmp
(
a1
,
a2
)
!=
0
);
}
/*
* Comparison function for sorting. Add V4/V6 testing!
*/
int4
network_cmp
(
inet
*
a1
,
inet
*
a2
)
{
if
((
ip_family
(
a1
)
==
AF_INET
)
&&
(
ip_family
(
a2
)
==
AF_INET
))
{
int
order
=
v4bitncmp
(
ip_v4addr
(
a1
),
ip_v4addr
(
a2
),
(
ip_bits
(
a1
)
<
ip_bits
(
a2
))
?
ip_bits
(
a1
)
:
ip_bits
(
a2
));
if
(
order
)
return
order
;
/* They agree in the first N bits, so shorter one comes first */
return
(
int
)
ip_bits
(
a1
)
-
(
int
)
ip_bits
(
a2
);
int
order
=
v4bitncmp
(
ip_v4addr
(
a1
),
ip_v4addr
(
a2
),
ip_bits
(
a2
));
return
((
order
>
0
)
||
((
order
==
0
)
&&
(
ip_bits
(
a1
)
>
ip_bits
(
a2
))));
}
else
{
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"cannot compare address families %d and %d"
,
ip_family
(
a1
),
ip_family
(
a2
));
return
0
;
return
FALSE
;
}
}
bool
network_ne
(
inet
*
a1
,
inet
*
a2
)
{
if
(
!
PointerIsValid
(
a1
)
||
!
PointerIsValid
(
a2
))
return
FALSE
;
return
(
!
network_eq
(
a1
,
a2
));
}
bool
network_sub
(
inet
*
a1
,
inet
*
a2
)
{
...
...
@@ -288,6 +293,28 @@ network_supeq(inet *a1, inet *a2)
}
}
/*
* Comparison function for sorting. Add V4/V6 testing!
*/
int4
network_cmp
(
inet
*
a1
,
inet
*
a2
)
{
if
(
ntohl
(
ip_v4addr
(
a1
))
<
ntohl
(
ip_v4addr
(
a2
)))
return
(
-
1
);
if
(
ntohl
(
ip_v4addr
(
a1
))
>
ntohl
(
ip_v4addr
(
a2
)))
return
(
1
);
if
(
ip_bits
(
a1
)
<
ip_bits
(
a2
))
return
(
-
1
);
if
(
ip_bits
(
a1
)
>
ip_bits
(
a2
))
return
(
1
);
return
0
;
}
text
*
network_host
(
inet
*
ip
)
{
...
...
@@ -449,7 +476,7 @@ network_netmask(inet *ip)
*/
static
int
v4bitncmp
(
unsigned
long
a1
,
unsigned
long
a2
,
int
bits
)
v4bitncmp
(
unsigned
int
a1
,
unsigned
int
a2
,
int
bits
)
{
unsigned
long
mask
=
0
;
int
i
;
...
...
@@ -458,11 +485,9 @@ v4bitncmp(unsigned long a1, unsigned long a2, int bits)
mask
=
(
mask
>>
1
)
|
0x80000000
;
a1
=
ntohl
(
a1
);
a2
=
ntohl
(
a2
);
a1
&=
mask
;
a2
&=
mask
;
if
(
a1
<
a2
)
if
((
a1
&
mask
)
<
(
a2
&
mask
))
return
(
-
1
);
else
if
(
a1
>
a2
)
else
if
(
(
a1
&
mask
)
>
(
a2
&
mask
)
)
return
(
1
);
return
(
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment