nfs4: Use IPPROTO_* instead of enum Transport
This commit is contained in:
@@ -54,7 +54,7 @@ status_t
|
|||||||
ServerAddress::ResolveName(const char* name, ServerAddress* addr)
|
ServerAddress::ResolveName(const char* name, ServerAddress* addr)
|
||||||
{
|
{
|
||||||
addr->fPort = 2049;
|
addr->fPort = 2049;
|
||||||
addr->fProtocol = ProtocolUDP;
|
addr->fProtocol = IPPROTO_UDP;
|
||||||
|
|
||||||
struct in_addr iaddr;
|
struct in_addr iaddr;
|
||||||
if (inet_aton(name, &iaddr) != 0) {
|
if (inet_aton(name, &iaddr) != 0) {
|
||||||
@@ -86,7 +86,7 @@ ServerAddress::ResolveName(const char* name, ServerAddress* addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Connection::Connection(const sockaddr_in& addr, Transport proto)
|
Connection::Connection(const sockaddr_in& addr, int proto)
|
||||||
:
|
:
|
||||||
fWaitCancel(create_sem(0, NULL)),
|
fWaitCancel(create_sem(0, NULL)),
|
||||||
fSock(-1),
|
fSock(-1),
|
||||||
@@ -97,14 +97,14 @@ Connection::Connection(const sockaddr_in& addr, Transport proto)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConnectionStream::ConnectionStream(const sockaddr_in& addr, Transport proto)
|
ConnectionStream::ConnectionStream(const sockaddr_in& addr, int proto)
|
||||||
:
|
:
|
||||||
Connection(addr, proto)
|
Connection(addr, proto)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConnectionPacket::ConnectionPacket(const sockaddr_in& addr, Transport proto)
|
ConnectionPacket::ConnectionPacket(const sockaddr_in& addr, int proto)
|
||||||
:
|
:
|
||||||
Connection(addr, proto)
|
Connection(addr, proto)
|
||||||
{
|
{
|
||||||
@@ -323,10 +323,16 @@ Connection::Connect(Connection **pconn, const ServerAddress& id)
|
|||||||
addr.sin_port = htons(id.fPort);
|
addr.sin_port = htons(id.fPort);
|
||||||
|
|
||||||
Connection* conn;
|
Connection* conn;
|
||||||
if (id.fProtocol == ProtocolTCP)
|
switch (id.fProtocol) {
|
||||||
conn = new(std::nothrow) ConnectionStream(addr, id.fProtocol);
|
case IPPROTO_TCP:
|
||||||
else
|
conn = new(std::nothrow) ConnectionStream(addr, id.fProtocol);
|
||||||
conn = new(std::nothrow) ConnectionPacket(addr, id.fProtocol);
|
break;
|
||||||
|
case IPPROTO_UDP:
|
||||||
|
conn = new(std::nothrow) ConnectionPacket(addr, id.fProtocol);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -346,10 +352,10 @@ status_t
|
|||||||
Connection::_Connect()
|
Connection::_Connect()
|
||||||
{
|
{
|
||||||
switch (fProtocol) {
|
switch (fProtocol) {
|
||||||
case ProtocolTCP:
|
case IPPROTO_TCP:
|
||||||
fSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
fSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
break;
|
break;
|
||||||
case ProtocolUDP:
|
case IPPROTO_UDP:
|
||||||
fSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
fSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -15,15 +15,10 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
enum Transport {
|
|
||||||
ProtocolTCP = 6,
|
|
||||||
ProtocolUDP = 11
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ServerAddress {
|
struct ServerAddress {
|
||||||
uint32 fAddress;
|
uint32 fAddress;
|
||||||
uint16 fPort;
|
uint16 fPort;
|
||||||
Transport fProtocol;
|
int fProtocol;
|
||||||
|
|
||||||
bool operator==(const ServerAddress& x);
|
bool operator==(const ServerAddress& x);
|
||||||
bool operator<(const ServerAddress& x);
|
bool operator<(const ServerAddress& x);
|
||||||
@@ -49,22 +44,21 @@ public:
|
|||||||
void Disconnect();
|
void Disconnect();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Connection(const sockaddr_in& addr,
|
Connection(const sockaddr_in& addr, int proto);
|
||||||
Transport proto);
|
|
||||||
status_t _Connect();
|
status_t _Connect();
|
||||||
|
|
||||||
sem_id fWaitCancel;
|
sem_id fWaitCancel;
|
||||||
int fSock;
|
int fSock;
|
||||||
mutex fSockLock;
|
mutex fSockLock;
|
||||||
|
|
||||||
const Transport fProtocol;
|
const int fProtocol;
|
||||||
const sockaddr_in fServerAddress;
|
const sockaddr_in fServerAddress;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConnectionStream : public Connection {
|
class ConnectionStream : public Connection {
|
||||||
public:
|
public:
|
||||||
ConnectionStream(const sockaddr_in& addr,
|
ConnectionStream(const sockaddr_in& addr,
|
||||||
Transport proto);
|
int proto);
|
||||||
|
|
||||||
virtual status_t Send(const void* buffer, uint32 size);
|
virtual status_t Send(const void* buffer, uint32 size);
|
||||||
virtual status_t Receive(void** buffer, uint32* size);
|
virtual status_t Receive(void** buffer, uint32* size);
|
||||||
@@ -73,7 +67,7 @@ public:
|
|||||||
class ConnectionPacket : public Connection {
|
class ConnectionPacket : public Connection {
|
||||||
public:
|
public:
|
||||||
ConnectionPacket(const sockaddr_in& addr,
|
ConnectionPacket(const sockaddr_in& addr,
|
||||||
Transport proto);
|
int proto);
|
||||||
|
|
||||||
virtual status_t Send(const void* buffer, uint32 size);
|
virtual status_t Send(const void* buffer, uint32 size);
|
||||||
virtual status_t Receive(void** buffer, uint32* size);
|
virtual status_t Receive(void** buffer, uint32* size);
|
||||||
|
|||||||
@@ -215,16 +215,15 @@ FileSystem::Migrate(const RPC::Server* serv)
|
|||||||
reinterpret_cast<FSLocations*>(values[0].fData.fLocations);
|
reinterpret_cast<FSLocations*>(values[0].fData.fLocations);
|
||||||
|
|
||||||
RPC::Server* server = fServer;
|
RPC::Server* server = fServer;
|
||||||
|
ServerAddress addr = fServer->ID();
|
||||||
for (uint32 i = 0; i < locs->fCount; i++) {
|
for (uint32 i = 0; i < locs->fCount; i++) {
|
||||||
for (uint32 j = 0; j < locs->fLocations[i].fCount; j++) {
|
for (uint32 j = 0; j < locs->fLocations[i].fCount; j++) {
|
||||||
ServerAddress addr;
|
|
||||||
|
|
||||||
if (ServerAddress::ResolveName(locs->fLocations[i].fLocations[j],
|
if (ServerAddress::ResolveName(locs->fLocations[i].fLocations[j],
|
||||||
&addr) != B_OK)
|
&addr) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (gRPCServerManager->Acquire(&fServer, addr.fAddress, addr.fPort,
|
if (gRPCServerManager->Acquire(&fServer, addr,
|
||||||
addr.fProtocol, CreateNFS4Server) == B_OK) {
|
CreateNFS4Server) == B_OK) {
|
||||||
|
|
||||||
free(const_cast<char*>(fPath));
|
free(const_cast<char*>(fPath));
|
||||||
fPath = strdup(locs->fLocations[i].fRootPath);
|
fPath = strdup(locs->fLocations[i].fRootPath);
|
||||||
|
|||||||
@@ -279,16 +279,11 @@ ServerManager::~ServerManager()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ServerManager::Acquire(Server** pserv, uint32 ip, uint16 port, Transport proto,
|
ServerManager::Acquire(Server** pserv, const ServerAddress& id,
|
||||||
ProgramData* (*createPriv)(Server*))
|
ProgramData* (*createPriv)(Server*))
|
||||||
{
|
{
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
ServerAddress id;
|
|
||||||
id.fAddress = ip;
|
|
||||||
id.fPort = port;
|
|
||||||
id.fProtocol = proto;
|
|
||||||
|
|
||||||
MutexLocker locker(fLock);
|
MutexLocker locker(fLock);
|
||||||
ServerNode* node = _Find(id);
|
ServerNode* node = _Find(id);
|
||||||
if (node != NULL) {
|
if (node != NULL) {
|
||||||
|
|||||||
@@ -160,8 +160,7 @@ public:
|
|||||||
ServerManager();
|
ServerManager();
|
||||||
~ServerManager();
|
~ServerManager();
|
||||||
|
|
||||||
status_t Acquire(Server** pserv, uint32 ip, uint16 port,
|
status_t Acquire(Server** pserv, const ServerAddress& id,
|
||||||
Transport proto,
|
|
||||||
ProgramData* (*createPriv)(Server*));
|
ProgramData* (*createPriv)(Server*));
|
||||||
void Release(Server* serv);
|
void Release(Server* serv);
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ status_t
|
|||||||
Request::Send(Cookie* cookie)
|
Request::Send(Cookie* cookie)
|
||||||
{
|
{
|
||||||
switch (fServer->ID().fProtocol) {
|
switch (fServer->ID().fProtocol) {
|
||||||
case ProtocolUDP: return _SendUDP(cookie);
|
case IPPROTO_UDP: return _SendUDP(cookie);
|
||||||
case ProtocolTCP: return _SendTCP(cookie);
|
case IPPROTO_TCP: return _SendTCP(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|||||||
@@ -80,9 +80,13 @@ nfs4_mount(fs_volume* volume, const char* device, uint32 flags,
|
|||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
ServerAddress id;
|
||||||
|
id.fAddress = ip;
|
||||||
|
id.fPort = 2049;
|
||||||
|
id.fProtocol = IPPROTO_UDP;
|
||||||
|
|
||||||
RPC::Server *server;
|
RPC::Server *server;
|
||||||
result = gRPCServerManager->Acquire(&server, ip, 2049, ProtocolUDP,
|
result = gRPCServerManager->Acquire(&server, id, CreateNFS4Server);
|
||||||
CreateNFS4Server);
|
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user