Skip to content
Snippets Groups Projects
Commit a6c397e8 authored by Giuseppe Lo Presti's avatar Giuseppe Lo Presti
Browse files

Added a small library for the movers to handle the metadata operations when...

Added a small library for the movers to handle the metadata operations when opening and closing files. The location is temporary, the code of all movers will be grouped together later on.
For the time being, only the close procedure is implemented.
parent d6cccdc3
Branches
Tags
No related merge requests found
......@@ -172,6 +172,7 @@ ELSE(DEFINED PackageOnly)
if (${COMPILE_SERVER} STREQUAL "1")
add_subdirectory (gridftp2)
add_subdirectory (ceph)
add_subdirectory (movers)
endif (${COMPILE_SERVER} STREQUAL "1")
add_subdirectory (h)
if (${COMPILE_SERVER} STREQUAL "1")
......
#
# This file is part of the Castor project.
# See http://castor.web.cern.ch/castor
#
# Copyright (C) 2003 CERN
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
cmake_minimum_required (VERSION 2.6)
add_library (castormovers moverclose.cpp)
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sstream>
#include <exception>
#include <stdexcept>
#include "serrno.h"
extern "C" {
int mover_close_file(const int port, const char* transferUuid, const u_signed64 filesize, const char* cksumtype, const char* cksumvalue,
int* errorcode, char** errormsg) {
try {
int sockfd = 0, n = 0;
/* Prepare close message. Protocol:
CLOSE <transferUuid> <fileSize> <cksumType> <cksumValue> <errorCode>[ <error message>]
*/
std::ostringstream writeBuf;
writeBuf << "CLOSE " << transferUuid << ' ' << filesize << ' ' << cksumtype
<< ' ' << cksumvalue << ' ' << *errorcode;
if(*errorcode) {
writeBuf << ' ' << *errormsg;
}
try {
// connect and send data
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
throw std::runtime_error("Failed to create socket");
}
struct sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port);
inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr.s_addr);
if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
throw std::runtime_error("Failed to connect");
}
n = write(sockfd, writeBuf.str().c_str(), writeBuf.str().length());
// process result
if (n != (int)writeBuf.str().length()) {
throw std::runtime_error("Failed to send CLOSE message");
}
// synchronously read answer back until \n
// Format is <returnCode> [<error message>]\n
n = 0;
char readBuf[1024];
while(n < 1024 && 1 == read(sockfd, &readBuf[n], 1)) {
if(n > 0 && readBuf[n] == ' ' && *errorcode == 0) {
/* so far we have the return code */
*errorcode = (int)strtol(readBuf, NULL, 10);
n = 0;
}
else if(readBuf[n] == '\n') {
/* this is the end of the data */
readBuf[n] = '\0';
break;
}
else {
n++;
}
}
// ok, we got the reply, return it to the caller
if(*errorcode != 0) {
*errormsg = strdup(readBuf);
}
}
catch (std::exception& e) {
// report any exception to the caller
*errorcode = SEINTERNAL;
*errormsg = strdup(e.what());
}
}
catch (...) {
// this is to avoid core dumps on standard exceptions
*errorcode = SEINTERNAL;
*errormsg = strdup("mover_close_file: caught general exception");
}
return *errorcode;
}
} /* extern C */
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* a single function definition for closing a file by any CASTOR mover
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define MOVERHANDLERPORT 15511
/**
* move_open_file asks for opening a CASTOR file from non-forked movers like xrootd.
* In this case, allocated transfer slots may expire before the client is ready to
* transfer the data, regardless from the fact that the mover daemon runs forever.
* It connects to the diskmanagerd daemon and synchronously wait for the response.
*
* port the port to which to connect
* transferUuid the UUID of the transfer to be served, aka the subRequest id
*
* The return value is 0 for success and SETIMEDOUT if the slot had timed out meanwhile.
*
int mover_open_file(const int port, const char* transferUuid);
*/
/**
* mover_close_file allows a mover to close a CASTOR file after a transfer.
* It connects to the diskmanagerd daemon and synchronously wait for the response.
*
* port the port to which to connect
* transferUuid the UUID of the current transfer, aka the subRequest id
* filesize the size of the file (relevant only on Put requests)
* cksumtype the type of checksum (relevant only on Put requests)
* cksumvalue the hexadecimal value of the checksum (relevant only on Put requests)
* errorcode an error code to be passed in case of failure
* errormsg an error message
*
* errorcode and errormsg are then populated with the result of the operation:
* if errorcode == 0 the operation was successful, otherwise errormsg contains
* a useful string to be sent to the client or logged by the mover.
* The return value is equal to errorcode.
*/
int mover_close_file(const int port, const char* transferUuid, const long long filesize,
const char* cksumtype, const char* cksumvalue,
int* errorcode, char** errormsg);
#ifdef __cplusplus
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment