Revision ca2a1a42 include/HostPool.h

View differences:

include/HostPool.h
39 39
        const string& hook_location, const string& remotes_location,
40 40
        time_t expire_time);
41 41

  
42
    ~HostPool(){};
42
    ~HostPool();
43 43

  
44 44
    /**
45 45
     *  Function to allocate a new Host object
......
66 66
        int     oid,
67 67
        bool    lock)
68 68
    {
69
        return static_cast<Host *>(PoolSQL::get(oid,lock));
69
        Host * h = static_cast<Host *>(PoolSQL::get(oid,lock));
70

  
71
        if ( h != 0 )
72
        {
73
            HostVM * hv = get_host_vm(oid);
74

  
75
            h->tmp_lost_vms   = &(hv->tmp_lost_vms);
76
            h->tmp_zombie_vms = &(hv->tmp_zombie_vms);
77

  
78
            h->prev_rediscovered_vms = &(hv->prev_rediscovered_vms);
79
        }
80

  
81
        return h;
70 82
    };
71 83

  
72 84
    /**
......
79 91
    Host * get(string name, bool lock)
80 92
    {
81 93
        // The owner is set to -1, because it is not used in the key() method
82
        return static_cast<Host *>(PoolSQL::get(name,-1,lock));
94
        Host * h = static_cast<Host *>(PoolSQL::get(name,-1,lock));
95

  
96
        if ( h != 0 )
97
        {
98
            HostVM * hv = get_host_vm(h->oid);
99

  
100
            h->tmp_lost_vms   = &(hv->tmp_lost_vms);
101
            h->tmp_zombie_vms = &(hv->tmp_zombie_vms);
102

  
103
            h->prev_rediscovered_vms = &(hv->prev_rediscovered_vms);
104
        }
105

  
106
        return h;
83 107
    };
84 108

  
85 109
    /**
......
180 204
            return -1;
181 205
        }
182 206

  
183
        return PoolSQL::drop(objsql, error_msg);
207
        int rc = PoolSQL::drop(objsql, error_msg);
208

  
209
        if ( rc == 0 )
210
        {
211
            delete_host_vm(host->oid);
212
        }
213

  
214
        return rc;
184 215
    };
185 216

  
186 217
    /**
......
265 296
    int clean_expired_monitoring();
266 297

  
267 298
private:
299
    /**
300
     * Stores several Host counters to give VMs one monitor grace cycle before
301
     * moving them to another state
302
     */
303
    struct HostVM
304
    {
305
        /**
306
         * Tmp set of lost VM IDs. 
307
         */
308
        set<int> tmp_lost_vms;
309

  
310
        /**
311
         * Tmp set of zombie VM IDs. 
312
         */
313
        set<int> tmp_zombie_vms;
314

  
315
        /**
316
         * VMs reported as found from the poweroff state.
317
         */
318
        set<int> prev_rediscovered_vms;
319
    };
320

  
321
    map<int, HostVM *> host_vms;
322

  
323
    HostVM * get_host_vm(int oid);
324

  
325
    void delete_host_vm(int oid);
268 326

  
269 327
    /**
270 328
     *  Factory method to produce Host objects

Also available in: Unified diff