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