root/plugin/ipc/file/fileconnection.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /****************************************************************************
   2  *   Copyright (C) 2006-2008 by Jason Ansel, Kapil Arya, Gene Cooperman,    *
   3  *                                                           and Rohan Garg *
   4  *   jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu, and         *
   5  *                                                      rohgarg@ccs.neu.edu *
   6  *                                                                          *
   7  *   This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src).  *
   8  *                                                                          *
   9  *  DMTCP:dmtcp/src is free software: you can redistribute it and/or        *
  10  *  modify it under the terms of the GNU Lesser General Public License as   *
  11  *  published by the Free Software Foundation, either version 3 of the      *
  12  *  License, or (at your option) any later version.                         *
  13  *                                                                          *
  14  *  DMTCP:dmtcp/src is distributed in the hope that it will be useful,      *
  15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
  17  *  GNU Lesser General Public License for more details.                     *
  18  *                                                                          *
  19  *  You should have received a copy of the GNU Lesser General Public        *
  20  *  License along with DMTCP:dmtcp/src.  If not, see                        *
  21  *  <http://www.gnu.org/licenses/>.                                         *
  22  ****************************************************************************/
  23 
  24 #pragma once
  25 #ifndef FILECONNECTION_H
  26 #define FILECONNECTION_H
  27 
  28 // THESE INCLUDES ARE IN RANDOM ORDER.  LET'S CLEAN IT UP AFTER RELEASE. - Gene
  29 #include <sys/types.h>
  30 #include <sys/stat.h>
  31 #include <sys/types.h>
  32 #include <sys/socket.h>
  33 #include <unistd.h>
  34 #include <mqueue.h>
  35 #include <stdint.h>
  36 #include <signal.h>
  37 #include "jfilesystem.h"
  38 #include "jbuffer.h"
  39 #include "jconvert.h"
  40 #include "connection.h"
  41 
  42 namespace dmtcp
  43 {
  44   class PtyConnection : public Connection
  45   {
  46     public:
  47       enum PtyType
  48       {
  49         PTY_INVALID = Connection::PTY,
  50         PTY_DEV_TTY,
  51         PTY_CTTY,
  52         PTY_PARENT_CTTY,
  53         PTY_MASTER,
  54         PTY_SLAVE,
  55         PTY_BSD_MASTER,
  56         PTY_BSD_SLAVE
  57       };
  58 
  59       PtyConnection() {}
  60       PtyConnection(int fd, const char *path, int flags, mode_t mode, int type);
  61 
  62       string ptsName() { return _ptsName;; }
  63       string virtPtsName() { return _virtPtsName;; }
  64       void markPreExistingCTTY() { _preExistingCTTY = true; }
  65 
  66       void preRefill(bool isRestart);
  67 
  68       virtual void drain();
  69       virtual void refill(bool isRestart);
  70       virtual void postRestart();
  71       virtual void serializeSubClass(jalib::JBinarySerializer& o);
  72       virtual bool isPreExistingCTTY() const { return _preExistingCTTY; }
  73       virtual string str() { return _masterName + ":" + _ptsName; }
  74     private:
  75       string _masterName;
  76       string _ptsName;
  77       string _virtPtsName;
  78       int64_t       _flags;
  79       int64_t       _mode;
  80       char          _ptmxIsPacketMode;
  81       char          _isControllingTTY;
  82       char          _preExistingCTTY;
  83   };
  84 
  85   class StdioConnection : public Connection
  86   {
  87     public:
  88       enum StdioType
  89       {
  90         STDIO_IN = STDIO,
  91         STDIO_OUT,
  92         STDIO_ERR,
  93         STDIO_INVALID
  94       };
  95 
  96       StdioConnection(int fd): Connection(STDIO + fd) {
  97         JTRACE("creating stdio connection") (fd) (id());
  98         JASSERT(jalib::Between(0, fd, 2)) (fd)
  99           .Text("invalid fd for StdioConnection");
 100       }
 101 
 102       StdioConnection() {}
 103 
 104       virtual void drain() {}
 105       virtual void refill(bool isRestart) {}
 106       virtual void postRestart();
 107       virtual void serializeSubClass(jalib::JBinarySerializer& o) {}
 108 
 109       virtual string str() { return "<STDIO>"; };
 110   };
 111 
 112   class FileConnection : public Connection
 113   {
 114     public:
 115       enum FileType
 116       {
 117         FILE_INVALID = FILE,
 118         FILE_REGULAR,
 119         FILE_SHM,
 120         FILE_PROCFS,
 121         FILE_DELETED,
 122         FILE_BATCH_QUEUE
 123       };
 124 
 125       FileConnection() {}
 126       FileConnection(const string& path, int flags, mode_t mode,
 127                      int type = FILE_REGULAR)
 128         : Connection(FILE)
 129         , _path(path)
 130         , _fileAlreadyExists(false)
 131         , _flags(flags)
 132         /* No method uses _mode yet.  Stop compiler from issuing warning. */
 133         /* , _mode(mode) */
 134       {
 135          _type = type;
 136       }
 137 
 138 
 139       virtual void doLocking();
 140       virtual void drain();
 141       virtual void preCkpt();
 142       virtual void refill(bool isRestart);
 143       virtual void postRestart();
 144       virtual void resume(bool isRestart);
 145 
 146       virtual void serializeSubClass(jalib::JBinarySerializer& o);
 147 
 148       virtual string str() { return _path; }
 149       string filePath() { return _path; }
 150       bool checkpointed() { return _ckpted_file; }
 151       void doNotRestoreCkptCopy() { _ckpted_file = false; }
 152 
 153       dev_t devnum() const { return _st_dev; }
 154       ino_t inode() const { return _st_ino; }
 155 
 156       bool checkDup(int fd);
 157     private:
 158       int  openFile();
 159       void refreshPath();
 160       void calculateRelativePath();
 161       string getSavedFilePath(const string& path);
 162 
 163       string _path;
 164       string _rel_path;
 165       string _ckptFilesDir;
 166       int32_t       _ckpted_file;
 167       int32_t       _fileAlreadyExists;
 168       int32_t       _rmtype;
 169       int64_t       _flags;
 170       /* No method uses _mode yet.  Stop compiler from issuing warning. */
 171       /* int64_t       _mode; */
 172       int64_t       _offset;
 173       uint64_t      _st_dev;
 174       uint64_t      _st_ino;
 175       int64_t       _st_size;
 176   };
 177 
 178   class FifoConnection : public Connection
 179   {
 180     public:
 181 
 182       FifoConnection() {}
 183       FifoConnection(const string& path, int flags, mode_t mode)
 184         : Connection(FIFO)
 185           , _path(path)
 186     {
 187       string curDir = jalib::Filesystem::GetCWD();
 188       int offs = _path.find(curDir);
 189       if (offs < 0) {
 190         _rel_path = "*";
 191       } else {
 192         offs += curDir.size();
 193         offs = _path.find('/',offs);
 194         offs++;
 195         _rel_path = _path.substr(offs);
 196       }
 197       JTRACE("New Fifo connection created") (_path) (_rel_path);
 198       _in_data.clear();
 199     }
 200 
 201       virtual void drain();
 202       virtual void refill(bool isRestart);
 203       virtual void postRestart();
 204 
 205       virtual string str() { return _path; };
 206       virtual void serializeSubClass(jalib::JBinarySerializer& o);
 207 
 208     private:
 209       int  openFile();
 210       void refreshPath();
 211       string getSavedFilePath(const string& path);
 212       string _path;
 213       string _rel_path;
 214       string _savedRelativePath;
 215       int64_t       _flags;
 216       int64_t       _mode;
 217       vector<char> _in_data;
 218       int32_t       ckptfd;
 219   };
 220 
 221   class PosixMQConnection: public Connection
 222   {
 223     public:
 224       inline PosixMQConnection(const char *name, int oflag, mode_t mode,
 225                                struct mq_attr *attr)
 226         : Connection(POSIXMQ)
 227           , _name(name)
 228           , _oflag(oflag)
 229           , _mode(mode)
 230           , _qnum(0)
 231           , _notifyReg(false)
 232     {
 233       if (attr != NULL) {
 234         _attr = *attr;
 235       }
 236     }
 237 
 238       virtual void drain();
 239       virtual void refill(bool isRestart);
 240       virtual void postRestart();
 241 
 242       virtual void serializeSubClass(jalib::JBinarySerializer& o);
 243 
 244       virtual string str() { return _name; }
 245 
 246       void on_mq_close();
 247       void on_mq_notify(const struct sigevent *sevp);
 248 
 249     private:
 250       string  _name;
 251       int64_t        _oflag;
 252       int64_t        _mode;
 253       struct mq_attr _attr;
 254       int64_t        _qnum;
 255       char           _notifyReg;
 256       struct sigevent _sevp;
 257       vector<jalib::JBuffer> _msgInQueue;
 258       vector<uint32_t> _msgInQueuePrio;
 259   };
 260 
 261 }
 262 
 263 #endif

/* [<][>][^][v][top][bottom][index][help] */