XRootD
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 
35 #include "XrdOfs/XrdOfsHandle.hh"
36 #include "XrdOuc/XrdOucEnv.hh"
37 #include "XrdOuc/XrdOucErrInfo.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 
57 bool 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 
72 int 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 
87 int 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  [[fallthrough]];
117  case -ENOENT: rc = SFS_OK;
118  break;
119  case -EBUSY: ec = ENOTTY;
120  rc = SFS_ERROR;
121  msg = "file is in use";
122  break;
123  case -EAGAIN: rc = 5;
124  break;
125  default: rc = SFS_ERROR;
126  msg = "unlink failed";
127  break;
128  }
129  TRACE(Info,"Cache "<<xeq<<' '<<path<<" rc="<<ec<<" ec="<<ec<<" msg="<<msg);
130  } else {
131  ec = EINVAL;
132  rc = SFS_ERROR;
133  }
134 
135  if (!strcmp(xeq, "cached"))
136  {
137  const char* path = args.ArgP[0];
138  int rval = myCache.ConsiderCached(path);
139  if (rval == 0)
140  {
141  rc = SFS_OK;
142  ec = 0;
143  }
144  else
145  {
146  ec = ETIME;
147  rc = SFS_ERROR;
148  TRACE(Info,"Cache "<<xeq<<' '<<path<<" rc="<<ec<<" ec="<<ec<<" msg=file not in cache");
149  }
150  }
151 
152 // Return result
153 //
154  eInfo.setErrInfo(ec, msg);
155  return rc;
156 }
@ Info
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.
static void Hide(const char *thePath)
void * GetPtr(const char *varname)
Definition: XrdOucEnv.cc:281
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
Definition: XrdPfcFSctl.cc:72
XrdPfcFSctl(XrdPfc::Cache &cInst, XrdSysLogger *logP)
Constructor.
Definition: XrdPfcFSctl.cc:49
virtual bool Configure(const char *CfgFN, const char *Parms, XrdOucEnv *envP, const Plugins &plugs) override
Definition: XrdPfcFSctl.cc:57
Attaches/creates and detaches/deletes cache-io objects for disk based cache.
Definition: XrdPfc.hh:152
virtual int ConsiderCached(const char *url)
Definition: XrdPfc.cc:999
int UnlinkFile(const std::string &f_name, bool fail_if_open)
Remove cinfo and data files from cache.
Definition: XrdPfc.cc:1188
XrdSysError Log
Definition: XrdConfig.cc:112
XrdOucEnv * envP
Definition: XrdPss.cc:109