XRootD
Loading...
Searching...
No Matches
XrdPfcFSctl.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d P f c F S c t l . c c */
4/* */
5/* (c) 2023 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include <string>
32#include <errno.h>
33#include <string.h>
34
36#include "XrdOuc/XrdOucEnv.hh"
38#include "XrdOuc/XrdOucCache.hh"
39#include "XrdPfc/XrdPfc.hh"
40#include "XrdPfc/XrdPfcFSctl.hh"
41#include "XrdPfc/XrdPfcTrace.hh"
43#include "XrdSys/XrdSysTrace.hh"
44
45/******************************************************************************/
46/* C o n s t r u c t o r */
47/******************************************************************************/
48
50 : myCache(cInst), hProc(0), Log(logP, "PfcFsctl"),
51 sysTrace(cInst.GetTrace()), m_traceID("PfcFSctl") {}
52
53/******************************************************************************/
54/* C o n f i g u r e */
55/******************************************************************************/
56
57bool XrdPfcFSctl::Configure(const char *CfgFN,
58 const char *Parms,
59 XrdOucEnv *envP,
60 const Plugins &plugs)
61{
62// All we are interested in is getting the file handle handler pointer
63//
64 hProc = (XrdOfsHandle*)envP->GetPtr("XrdOfsHandle*");
65 return hProc != 0;
66}
67
68/******************************************************************************/
69/* F S c t l [ F i l e ] */
70/******************************************************************************/
71
72int XrdPfcFSctl::FSctl(const int cmd,
73 int alen,
74 const char *args,
75 XrdSfsFile &file,
76 XrdOucErrInfo &eInfo,
77 const XrdSecEntity *client)
78{
79 eInfo.setErrInfo(ENOTSUP, "File based fstcl not supported for a cache.");
80 return SFS_ERROR;
81}
82
83/******************************************************************************/
84/* F S c t l [ B a s e ] */
85/******************************************************************************/
86
87int XrdPfcFSctl::FSctl(const int cmd,
88 XrdSfsFSctl &args,
89 XrdOucErrInfo &eInfo,
90 const XrdSecEntity *client)
91{
92 const char *msg = "", *xeq = args.Arg1;
93 int ec, rc;
94
95// Verify command
96//
97 if (cmd != SFS_FSCTL_PLUGXC)
98 {eInfo.setErrInfo(EIDRM, "None-cache command issued to a cache.");
99 return SFS_ERROR;
100 }
101
102// Very that we have a command
103//
104 if (!xeq || args.Arg1Len < 1)
105 {eInfo.setErrInfo(EINVAL, "Missing cache command or argument.");
106 return SFS_ERROR;
107 }
108
109// Process command
110//
111 if ((!strcmp(xeq, "evict") || !strcmp(xeq, "fevict")) && args.Arg2Len == -2)
112 {std::string path = args.ArgP[0];
113 ec = myCache.UnlinkFile(path, *xeq != 'f');
114 switch(ec)
115 {case 0: if (hProc) hProc->Hide(path.c_str());
116 rc = SFS_OK;
117 break;
118 case -ENOENT: ec = ENOENT;
119 rc = SFS_ERROR;
120 msg = "file does not exist";
121 break;
122 case -EBUSY: ec = ENOTTY;
123 rc = SFS_ERROR;
124 msg = "file is in use";
125 break;
126 case -EAGAIN: rc = 5;
127 break;
128 default: rc = SFS_ERROR;
129 msg = "unlink failed";
130 break;
131 }
132 TRACE(Info,"Cache "<<xeq<<' '<<path<<" rc="<<ec<<" ec="<<ec<<" msg="<<msg);
133 } else {
134 ec = EINVAL;
135 rc = SFS_ERROR;
136 }
137
138 if (!strcmp(xeq, "cached"))
139 {
140 const char* path = args.ArgP[0];
141 int rval = myCache.ConsiderCached(path);
142 if (rval == 0)
143 {
144 rc = SFS_OK;
145 ec = 0;
146 }
147 else
148 {
149 ec = ETIME;
150 rc = SFS_ERROR;
151 TRACE(Info,"Cache "<<xeq<<' '<<path<<" rc="<<ec<<" ec="<<ec<<" msg=file not in cache");
152 }
153 }
154
155// Return result
156//
157 eInfo.setErrInfo(ec, msg);
158 return rc;
159}
const char * Arg1
PLUGINO, PLUGION, PLUGXC.
int Arg2Len
Length or -count of args in extension.
#define SFS_ERROR
int Arg1Len
Length.
#define SFS_OK
#define SFS_FSCTL_PLUGXC
< SFS_FSCTL_PLUGIN/PLUGIO/PLUGXC parms
#define TRACE(act, x)
Definition XrdTrace.hh:63
The Plugins struct is used to pass plugin pointers to configure.
void * GetPtr(const char *varname)
Definition XrdOucEnv.cc:263
int setErrInfo(int code, const char *emsg)
virtual int FSctl(const int cmd, int alen, const char *args, XrdSfsFile &file, XrdOucErrInfo &eInfo, const XrdSecEntity *client=0) override
XrdPfcFSctl(XrdPfc::Cache &cInst, XrdSysLogger *logP)
Constructor.
virtual bool Configure(const char *CfgFN, const char *Parms, XrdOucEnv *envP, const Plugins &plugs) override
Attaches/creates and detaches/deletes cache-io objects for disk based cache.
Definition XrdPfc.hh:163